[PATCH] D35447: [Bash-autocompletion] Add support for -W and -Wno

2017-07-14 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticIDs.h:266
 
+  static std::vector getDiagnosticFlags();
+

Please write a function comment just like other member functions in this class.



Comment at: clang/lib/Basic/DiagnosticIDs.cpp:514
+std::vector DiagnosticIDs::getDiagnosticFlags() {
+  std::vector res;
+  for (int i = 1; DiagGroupNames[i] != '\0';) {

res -> Res
i -> I




Comment at: clang/lib/Basic/DiagnosticIDs.cpp:515
+  std::vector res;
+  for (int i = 1; DiagGroupNames[i] != '\0';) {
+std::string Diag =

`size_t` is more precise than `int`, even though sizeof(DiagGroupNames) in 
reality fits in an int.



Comment at: clang/lib/Basic/DiagnosticIDs.cpp:516-517
+  for (int i = 1; DiagGroupNames[i] != '\0';) {
+std::string Diag =
+std::string(StringRef(DiagGroupNames + i + 1, DiagGroupNames[i]));
+i += DiagGroupNames[i] + 1;

If you want to construct a string, you can do this

  std::string Diag(DiagGroupNames + i + 1, DiagGroupNames[i]);



Comment at: clang/lib/Basic/DiagnosticIDs.cpp:519-522
+std::string W = "-W" + Diag;
+std::string Wno = "-Wno" + Diag;
+res.push_back(W);
+res.push_back(Wno);

I think you can remove these temporary variables:

  res.push_back("-W" + Diag);
  res.push_back("-Wno" + Diag);



Comment at: clang/lib/Driver/Driver.cpp:1279
+
+  for (std::string S : DiagnosticIDs::getDiagnosticFlags())
+if (StringRef(S).startswith(PassedFlags))

Let's avoid copy: std::string -> StringRef



https://reviews.llvm.org/D35447



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35448: [Bash-autocompletion] Fixed a bug on bash

2017-07-14 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu accepted this revision.
ruiu added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D35448



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35449: [X86] Implement __builtin_cpu_is

2017-07-14 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.

This patch adds support for __builtin_cpu_is. I've tried to match the strings 
supported to the latest version of gcc.

I've only tested this on my Macbook so far so I'd appreciate if others would 
test it. An AMD system would be great.


https://reviews.llvm.org/D35449

Files:
  include/clang/Basic/BuiltinsX86.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  lib/Basic/Targets.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/Sema/SemaChecking.cpp
  test/CodeGen/builtin-cpu-is.c
  test/CodeGen/target-builtin-noerror.c
  test/Sema/builtin-cpu-supports.c

Index: test/Sema/builtin-cpu-supports.c
===
--- test/Sema/builtin-cpu-supports.c
+++ test/Sema/builtin-cpu-supports.c
@@ -12,9 +12,15 @@
 
   if (__builtin_cpu_supports(str)) // expected-error {{expression is not a string literal}}
 a(str);
+
+  if (__builtin_cpu_is("int")) // expected-error {{invalid cpu name for builtin}}
+a("intel");
 #else
   if (__builtin_cpu_supports("vsx")) // expected-error {{use of unknown builtin}}
 a("vsx");
+
+  if (__builtin_cpu_is("pwr9")) // expected-error {{use of unknown builtin}}
+a("pwr9");
 #endif
 
   return 0;
Index: test/CodeGen/target-builtin-noerror.c
===
--- test/CodeGen/target-builtin-noerror.c
+++ test/CodeGen/target-builtin-noerror.c
@@ -73,3 +73,35 @@
   (void)__builtin_cpu_supports("avx512vbmi");
   (void)__builtin_cpu_supports("avx512ifma");
 }
+
+void verifycpustrings() {
+  (void)__builtin_cpu_is("amd");
+  (void)__builtin_cpu_is("amdfam10h");
+  (void)__builtin_cpu_is("amdfam15h");
+  (void)__builtin_cpu_is("atom");
+  (void)__builtin_cpu_is("barcelona");
+  (void)__builtin_cpu_is("bdver1");
+  (void)__builtin_cpu_is("bdver2");
+  (void)__builtin_cpu_is("bdver3");
+  (void)__builtin_cpu_is("bdver4");
+  (void)__builtin_cpu_is("bonnell");
+  (void)__builtin_cpu_is("broadwell");
+  (void)__builtin_cpu_is("btver1");
+  (void)__builtin_cpu_is("btver2");
+  (void)__builtin_cpu_is("core2");
+  (void)__builtin_cpu_is("corei7");
+  (void)__builtin_cpu_is("haswell");
+  (void)__builtin_cpu_is("intel");
+  (void)__builtin_cpu_is("istanbul");
+  (void)__builtin_cpu_is("ivybridge");
+  (void)__builtin_cpu_is("knl");
+  (void)__builtin_cpu_is("nehalem");
+  (void)__builtin_cpu_is("sandybridge");
+  (void)__builtin_cpu_is("shanghai");
+  (void)__builtin_cpu_is("silvermont");
+  (void)__builtin_cpu_is("skylake");
+  (void)__builtin_cpu_is("skylake-avx512");
+  (void)__builtin_cpu_is("slm");
+  (void)__builtin_cpu_is("westmere");
+  (void)__builtin_cpu_is("znver1");
+}
Index: test/CodeGen/builtin-cpu-is.c
===
--- /dev/null
+++ test/CodeGen/builtin-cpu-is.c
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm < %s| FileCheck %s
+
+// Test that we have the structure definition, the gep offsets, the name of the
+// global, the bit grab, and the icmp correct.
+extern void a(const char *);
+
+void intel() {
+  if (__builtin_cpu_is("intel"))
+a("intel");
+
+  // CHECK: [[LOAD:%[^ ]+]] = load i32, i32* getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, { i32, i32, i32, [1 x i32] }* @__cpu_model, i32 0, i32 0)
+  // CHECK: = icmp eq i32 [[LOAD]], 1
+}
+
+void amd() {
+  if (__builtin_cpu_is("amd"))
+a("amd");
+
+  // CHECK: [[LOAD:%[^ ]+]] = load i32, i32* getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, { i32, i32, i32, [1 x i32] }* @__cpu_model, i32 0, i32 0)
+  // CHECK: = icmp eq i32 [[LOAD]], 2
+}
+
+void atom() {
+  if (__builtin_cpu_is("atom"))
+a("atom");
+
+  // CHECK: [[LOAD:%[^ ]+]] = load i32, i32* getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, { i32, i32, i32, [1 x i32] }* @__cpu_model, i32 0, i32 1)
+  // CHECK: = icmp eq i32 [[LOAD]], 1
+}
+
+void amdfam10h() {
+  if (__builtin_cpu_is("amdfam10h"))
+a("amdfam10h");
+
+  // CHECK: [[LOAD:%[^ ]+]] = load i32, i32* getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, { i32, i32, i32, [1 x i32] }* @__cpu_model, i32 0, i32 1)
+  // CHECK: = icmp eq i32 [[LOAD]], 4
+}
+
+void barcelona() {
+  if (__builtin_cpu_is("barcelona"))
+a("barcelona");
+
+  // CHECK: [[LOAD:%[^ ]+]] = load i32, i32* getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, { i32, i32, i32, [1 x i32] }* @__cpu_model, i32 0, i32 2)
+  // CHECK: = icmp eq i32 [[LOAD]], 4
+}
+
+void nehalem() {
+  if (__builtin_cpu_is("nehalem"))
+a("nehalem");
+
+  // CHECK: [[LOAD:%[^ ]+]] = load i32, i32* getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, { i32, i32, i32, [1 x i32] }* @__cpu_model, i32 0, i32 2)
+  // CHECK: = icmp eq i32 [[LOAD]], 1
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1782,6 +1782,26 @@
   return false;
 }
 
+/// SemaBuiltinCpuIs - Handle 

[PATCH] D35448: [Bash-autocompletion] Fixed a bug on bash

2017-07-14 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.

Maybe I mismerged when merging previous commits by hand.


https://reviews.llvm.org/D35448

Files:
  clang/utils/bash-autocomplete.sh


Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -20,18 +20,21 @@
 cur="${COMP_WORDS[$cword]}"
   fi
 
-  # bash always separates '=' as a token even if there's no space before/after 
'='.
-  # On the other hand, '=' is just a regular character for clang options that
-  # contain '='. For example, "-stdlib=" is defined as is, instead of 
"-stdlib" and "=".
-  # So, we need to partially undo bash tokenization here for integrity.
   w1="${COMP_WORDS[$cword - 1]}"
   if [[ $cword > 1 ]]; then
 w2="${COMP_WORDS[$cword - 2]}"
+  fi
+
   # Clang want to know if -cc1 or -Xclang option is specified or not, because 
we don't want to show
   # cc1 options otherwise.
   if [[ "${COMP_WORDS[1]}" == "-cc1" || "$w1" == "-Xclang" ]]; then
 arg="#"
   fi
+
+  # bash always separates '=' as a token even if there's no space before/after 
'='.
+  # On the other hand, '=' is just a regular character for clang options that
+  # contain '='. For example, "-stdlib=" is defined as is, instead of 
"-stdlib" and "=".
+  # So, we need to partially undo bash tokenization here for integrity.
   if [[ "$cur" == -* ]]; then
 # -foo
 arg="$arg$cur"


Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -20,18 +20,21 @@
 cur="${COMP_WORDS[$cword]}"
   fi
 
-  # bash always separates '=' as a token even if there's no space before/after '='.
-  # On the other hand, '=' is just a regular character for clang options that
-  # contain '='. For example, "-stdlib=" is defined as is, instead of "-stdlib" and "=".
-  # So, we need to partially undo bash tokenization here for integrity.
   w1="${COMP_WORDS[$cword - 1]}"
   if [[ $cword > 1 ]]; then
 w2="${COMP_WORDS[$cword - 2]}"
+  fi
+
   # Clang want to know if -cc1 or -Xclang option is specified or not, because we don't want to show
   # cc1 options otherwise.
   if [[ "${COMP_WORDS[1]}" == "-cc1" || "$w1" == "-Xclang" ]]; then
 arg="#"
   fi
+
+  # bash always separates '=' as a token even if there's no space before/after '='.
+  # On the other hand, '=' is just a regular character for clang options that
+  # contain '='. For example, "-stdlib=" is defined as is, instead of "-stdlib" and "=".
+  # So, we need to partially undo bash tokenization here for integrity.
   if [[ "$cur" == -* ]]; then
 # -foo
 arg="$arg$cur"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35447: [Bash-autocompletion] Add support for -W and -Wno

2017-07-14 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi created this revision.

`-W[tab]` will autocomplete warnings defined in this link:
https://clang.llvm.org/docs/DiagnosticsReference.html#wweak-vtables


https://reviews.llvm.org/D35447

Files:
  clang/include/clang/Basic/DiagnosticIDs.h
  clang/lib/Basic/DiagnosticIDs.cpp
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/autocomplete.c


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -40,3 +40,7 @@
 // MRELOCMODEL_CLANG-NOT: -mrelocation-model
 // RUN: %clang --autocomplete=#-mrelocation-mode | FileCheck %s 
-check-prefix=MRELOCMODEL_CC1
 // MRELOCMODEL_CC1: -mrelocation-model
+// RUN: %clang --autocomplete=-Wma | FileCheck %s -check-prefix=WARNING
+// WARNING: -Wmacro-redefined -Wmain -Wmain-return-type 
-Wmalformed-warning-check -Wmany-braces-around-scalar-init -Wmax-unsigned-zero
+// RUN: %clang --autocomplete=-Wnoinvalid-pp- | FileCheck %s 
-check-prefix=NOWARNING
+// NOWARNING: -Wnoinvalid-pp-token
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1275,6 +1275,10 @@
   // we were requested to print out all option names that start with 
"-foo".
   // For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
   SuggestedCompletions = Opts->findByPrefix(PassedFlags, DisableFlags);
+
+  for (std::string S : DiagnosticIDs::getDiagnosticFlags())
+if (StringRef(S).startswith(PassedFlags))
+  SuggestedCompletions.push_back(S);
 } else {
   // If the flag is in the form of "--autocomplete=foo,bar", we were
   // requested to print out all option values for "-foo" that start with
Index: clang/lib/Basic/DiagnosticIDs.cpp
===
--- clang/lib/Basic/DiagnosticIDs.cpp
+++ clang/lib/Basic/DiagnosticIDs.cpp
@@ -510,6 +510,21 @@
   return StringRef();
 }
 
+std::vector DiagnosticIDs::getDiagnosticFlags() {
+  std::vector res;
+  for (int i = 1; DiagGroupNames[i] != '\0';) {
+std::string Diag =
+std::string(StringRef(DiagGroupNames + i + 1, DiagGroupNames[i]));
+i += DiagGroupNames[i] + 1;
+std::string W = "-W" + Diag;
+std::string Wno = "-Wno" + Diag;
+res.push_back(W);
+res.push_back(Wno);
+  }
+
+  return res;
+}
+
 /// Return \c true if any diagnostics were found in this group, even if they
 /// were filtered out due to having the wrong flavor.
 static bool getDiagnosticsInGroup(diag::Flavor Flavor,
Index: clang/include/clang/Basic/DiagnosticIDs.h
===
--- clang/include/clang/Basic/DiagnosticIDs.h
+++ clang/include/clang/Basic/DiagnosticIDs.h
@@ -263,6 +263,8 @@
   /// are not SFINAE errors.
   static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID);
 
+  static std::vector getDiagnosticFlags();
+
   /// \brief Get the set of all diagnostic IDs in the group with the given 
name.
   ///
   /// \param[out] Diags - On return, the diagnostics in the group.


Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -40,3 +40,7 @@
 // MRELOCMODEL_CLANG-NOT: -mrelocation-model
 // RUN: %clang --autocomplete=#-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CC1
 // MRELOCMODEL_CC1: -mrelocation-model
+// RUN: %clang --autocomplete=-Wma | FileCheck %s -check-prefix=WARNING
+// WARNING: -Wmacro-redefined -Wmain -Wmain-return-type -Wmalformed-warning-check -Wmany-braces-around-scalar-init -Wmax-unsigned-zero
+// RUN: %clang --autocomplete=-Wnoinvalid-pp- | FileCheck %s -check-prefix=NOWARNING
+// NOWARNING: -Wnoinvalid-pp-token
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1275,6 +1275,10 @@
   // we were requested to print out all option names that start with "-foo".
   // For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
   SuggestedCompletions = Opts->findByPrefix(PassedFlags, DisableFlags);
+
+  for (std::string S : DiagnosticIDs::getDiagnosticFlags())
+if (StringRef(S).startswith(PassedFlags))
+  SuggestedCompletions.push_back(S);
 } else {
   // If the flag is in the form of "--autocomplete=foo,bar", we were
   // requested to print out all option values for "-foo" that start with
Index: clang/lib/Basic/DiagnosticIDs.cpp
===
--- clang/lib/Basic/DiagnosticIDs.cpp
+++ clang/lib/Basic/DiagnosticIDs.cpp
@@ -510,6 +510,21 @@
   return StringRef();
 }
 
+std::vector DiagnosticIDs::getDiagnosticFlags() {
+  std::vector res;
+  for (int i = 1; DiagGroupNames[i] != 

r308077 - [ODRHash] Revert r307743 which reverted r307720

2017-07-14 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Fri Jul 14 19:55:13 2017
New Revision: 308077

URL: http://llvm.org/viewvc/llvm-project?rev=308077=rev
Log:
[ODRHash] Revert r307743 which reverted r307720

Reapply r307720 to allow processing of constructors and destructors.  Reuse
the diagnostics for CXXMethodDecl for them.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
cfe/trunk/lib/AST/ODRHash.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Modules/odr_hash.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=308077=308076=308077=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Fri Jul 14 
19:55:13 2017
@@ -147,18 +147,29 @@ def err_module_odr_violation_mismatch_de
   "%select{non-|}5mutable field %4|"
   "field %4 with %select{no|an}5 initalizer|"
   "field %4 with an initializer|"
-  "method %4|"
-  "method %4 is %select{not deleted|deleted}5|"
-  "method %4 is %select{|pure }5%select{not virtual|virtual}6|"
-  "method %4 is %select{not static|static}5|"
-  "method %4 is %select{not volatile|volatile}5|"
-  "method %4 is %select{not const|const}5|"
-  "method %4 is %select{not inline|inline}5|"
-  "method %4 that has %5 parameter%s5|"
-  "method %4 with %ordinal5 parameter of type %6%select{| decayed from %8}7|"
-  "method %4 with %ordinal5 parameter named %6|"
-  "method %4 with %ordinal5 parameter with%select{out|}6 a default argument|"
-  "method %4 with %ordinal5 parameter with a default argument|"
+  "%select{method %5|constructor|destructor}4|"
+  "%select{method %5|constructor|destructor}4 "
+"is %select{not deleted|deleted}6|"
+  "%select{method %5|constructor|destructor}4 "
+"is %select{|pure }6%select{not virtual|virtual}7|"
+  "%select{method %5|constructor|destructor}4 "
+"is %select{not static|static}6|"
+  "%select{method %5|constructor|destructor}4 "
+"is %select{not volatile|volatile}6|"
+  "%select{method %5|constructor|destructor}4 "
+"is %select{not const|const}6|"
+  "%select{method %5|constructor|destructor}4 "
+"is %select{not inline|inline}6|"
+  "%select{method %5|constructor|destructor}4 "
+"that has %6 parameter%s6|"
+  "%select{method %5|constructor|destructor}4 "
+"with %ordinal6 parameter of type %7%select{| decayed from %9}8|"
+  "%select{method %5|constructor|destructor}4 "
+"with %ordinal6 parameter named %7|"
+  "%select{method %5|constructor|destructor}4 "
+"with %ordinal6 parameter with%select{out|}7 a default argument|"
+  "%select{method %5|constructor|destructor}4 "
+"with %ordinal6 parameter with a default argument|"
   "%select{typedef|type alias}4 name %5|"
   "%select{typedef|type alias}4 %5 with underlying type %6|"
   "data member with name %4|"
@@ -183,18 +194,29 @@ def note_module_odr_violation_mismatch_d
   "%select{non-|}3mutable field %2|"
   "field %2 with %select{no|an}3 initializer|"
   "field %2 with a different initializer|"
-  "method %2|"
-  "method %2 is %select{not deleted|deleted}3|"
-  "method %2 is %select{|pure }3%select{not virtual|virtual}4|"
-  "method %2 is %select{not static|static}3|"
-  "method %2 is %select{not volatile|volatile}3|"
-  "method %2 is %select{not const|const}3|"
-  "method %2 is %select{not inline|inline}3|"
-  "method %2 that has %3 parameter%s3|"
-  "method %2 with %ordinal3 parameter of type %4%select{| decayed from %6}5|"
-  "method %2 with %ordinal3 parameter named %4|"
-  "method %2 with %ordinal3 parameter with%select{out|}4 a default argument|"
-  "method %2 with %ordinal3 parameter with a different default argument|"
+  "%select{method %3|constructor|destructor}2|"
+  "%select{method %3|constructor|destructor}2 "
+"is %select{not deleted|deleted}4|"
+  "%select{method %3|constructor|destructor}2 "
+"is %select{|pure }4%select{not virtual|virtual}5|"
+  "%select{method %3|constructor|destructor}2 "
+"is %select{not static|static}4|"
+  "%select{method %3|constructor|destructor}2 "
+"is %select{not volatile|volatile}4|"
+  "%select{method %3|constructor|destructor}2 "
+"is %select{not const|const}4|"
+  "%select{method %3|constructor|destructor}2 "
+"is %select{not inline|inline}4|"
+  "%select{method %3|constructor|destructor}2 "
+"that has %4 parameter%s4|"
+  "%select{method %3|constructor|destructor}2 "
+"with %ordinal4 parameter of type %5%select{| decayed from %7}6|"
+  "%select{method %3|constructor|destructor}2 "
+"with %ordinal4 parameter named %5|"
+  "%select{method %3|constructor|destructor}2 "
+"with %ordinal4 parameter with%select{out|}5 a default argument|"
+  "%select{method %3|constructor|destructor}2 "
+"with %ordinal4 parameter with a different default argument|"
   

[PATCH] D35438: CodeGen: Ensure there is basic block when performing address space cast

2017-07-14 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Oh, of course.  Sadly, in C/C++ the declaration point of a variable does not 
necessarily dominate all uses of the variable, so you need to emit the cast 
immediately after the alloca.  Just temporarily move CGF.Builder to that point; 
hopefully we can assume that this function will never try to add control flow.

Test case:

  extern void use(int*);
  void foo() {
goto later;
int x;
later:
use();
  }


https://reviews.llvm.org/D35438



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34654: Allow passing a regex for headers to exclude from clang-tidy

2017-07-14 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Please regenerate the patch with full context (e.g. as described in 
llvm.org/docs/Phabricator.html).


Repository:
  rL LLVM

https://reviews.llvm.org/D34654



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35438: CodeGen: Ensure there is basic block when performing address space cast

2017-07-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D35438#810234, @rjmccall wrote:

> Hmm.  It doesn't seem unreasonable for this to require an insertion point as 
> a precondition.  In what situation do we emit addrspace casts after a return?


When the alloca address space is not zero and we declare an automatic variable 
after return.  Since we need to cast the automatic variable to default address 
space, we need to have a new basic block.


https://reviews.llvm.org/D35438



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308073 - [clang] Fix format test

2017-07-14 Thread Alexander Shaposhnikov via cfe-commits
Author: alexshap
Date: Fri Jul 14 18:06:59 2017
New Revision: 308073

URL: http://llvm.org/viewvc/llvm-project?rev=308073=rev
Log:
[clang] Fix format test 

This diff makes the test FixIt/format.m more robust.
The issue was caught by the build bot clang-cmake-thumbv7-a15.

Test plan: make check-all

Modified:
cfe/trunk/test/FixIt/format.m

Modified: cfe/trunk/test/FixIt/format.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/format.m?rev=308073=308072=308073=diff
==
--- cfe/trunk/test/FixIt/format.m (original)
+++ cfe/trunk/test/FixIt/format.m Fri Jul 14 18:06:59 2017
@@ -230,14 +230,14 @@ void testSignedness(long i, unsigned lon
 }
 
 void testSizeTypes() {
-  printf("%zu", 0.f); // expected-warning{{format specifies type 'size_t' (aka 
'unsigned long') but the argument has type 'float'}}
+  printf("%zu", 0.f); // expected-warning-re{{format specifies type 'size_t' 
(aka '{{.+}}') but the argument has type 'float'}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
 
-  printf("%zd", 0.f); // expected-warning{{format specifies type 'ssize_t' 
(aka 'long') but the argument has type 'float'}}
+  printf("%zd", 0.f); // expected-warning-re{{format specifies type 'ssize_t' 
(aka '{{.+}}') but the argument has type 'float'}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
   
   int x;
-  printf("%zn", ); // expected-warning{{format specifies type 'ssize_t *' 
(aka 'long *') but the argument has type 'int *'}}
+  printf("%zn", ); // expected-warning-re{{format specifies type 'ssize_t *' 
(aka '{{.+}}') but the argument has type 'int *'}}
   // PrintfSpecifier::fixType doesn't handle %n, so a fix-it is not emitted, 
   // see the comment in PrintfSpecifier::fixType in PrintfFormatString.cpp.
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308071 - Try to fix modules build

2017-07-14 Thread Matthias Braun via cfe-commits
Author: matze
Date: Fri Jul 14 17:29:25 2017
New Revision: 308071

URL: http://llvm.org/viewvc/llvm-project?rev=308071=rev
Log:
Try to fix modules build

Module builds somehow report an ambiguity between clang::Diagnostic and
clang::Tooling::Diagnostic. It seems as if one of the additional headers
brought in by the module brings the clang namespace to the toplevel. I
could not find out the reason for that, so for now I go with the simple
fix to bring the build back to green.

rdar://33321397

Modified:
cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp

Modified: cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp?rev=308071=308070=308071=diff
==
--- cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp Fri Jul 14 17:29:25 2017
@@ -18,6 +18,7 @@
 
 using namespace llvm;
 using namespace clang::tooling;
+using clang::tooling::Diagnostic;
 
 static Diagnostic makeDiagnostic(StringRef DiagnosticName,
  const std::string , int FileOffset,


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32210: [Sema][ObjC] Add support for attribute "noescape"

2017-07-14 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 106735.
ahatanak marked 3 inline comments as done.
ahatanak added a comment.

Address review comments.

- Allow attaching "noescape" to pointers other than block pointers. Update the 
docs accordingly.
- Attach attribute "nocapture" to parameters that are annotated with "noescape".
- Call Sema::isValidPointerAttrType to determine whether "noescape" can be 
applied to a parameter. Also, use the existing warning 
"warn_attribute_pointers_only" rather than defining a new warning that will be 
used just for noescape.

I also thought about what else we can do in the front-end when a parameter has 
'noescape".  One idea is to do something similar to what r301667 did and omit 
emitting retains and releases of block captures when the block is passed to a 
function taking a noescape parameter. If that is viable, I can look into it 
after committing this patch.


https://reviews.llvm.org/D32210

Files:
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/CodeGen/CGCall.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenObjC/noescape.m
  test/SemaObjCXX/noescape.mm

Index: test/SemaObjCXX/noescape.mm
===
--- /dev/null
+++ test/SemaObjCXX/noescape.mm
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++11 %s
+
+typedef void (^BlockTy)();
+
+struct S {
+  int i;
+  void m();
+};
+
+void noescapeFunc0(id, __attribute__((noescape)) BlockTy);
+void noescapeFunc1(id, [[clang::noescape]] BlockTy);
+void noescapeFunc2(__attribute__((noescape)) int *);
+void noescapeFunc3(__attribute__((noescape)) id);
+void noescapeFunc4(__attribute__((noescape)) int &);
+
+void invalidFunc0(int __attribute__((noescape))); // expected-warning {{'noescape' attribute only applies to pointer arguments}}
+void invalidFunc1(int __attribute__((noescape(0; // expected-error {{'noescape' attribute takes no arguments}}
+void invalidFunc2(int0 *__attribute__((noescape))); // expected-error {{use of undeclared identifier 'int0'; did you mean 'int'?}}
+void invalidFunc3(__attribute__((noescape)) int (S::*Ty)); // expected-warning {{'noescape' attribute only applies to pointer arguments}}
+void invalidFunc4(__attribute__((noescape)) void (S::*Ty)()); // expected-warning {{'noescape' attribute only applies to pointer arguments}}
+int __attribute__((noescape)) g; // expected-warning {{'noescape' attribute only applies to parameters}}
Index: test/CodeGenObjC/noescape.m
===
--- /dev/null
+++ test/CodeGenObjC/noescape.m
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -fblocks -emit-llvm -o - %s | FileCheck %s
+
+typedef void (^BlockTy)(void);
+
+union U {
+  int *i;
+  long long *ll;
+} __attribute__((transparent_union));
+
+void noescapeFunc0(id, __attribute__((noescape)) BlockTy);
+void noescapeFunc1(__attribute__((noescape)) int *);
+void noescapeFunc2(__attribute__((noescape)) id);
+void noescapeFunc3(__attribute__((noescape)) union U);
+
+// CHECK-LABEL: define void @test0(
+// CHECK: call void @noescapeFunc0({{.*}}, [[TY0:.*]] nocapture {{.*}})
+// CHECK: declare void @noescapeFunc0(i8*, [[TY0]] nocapture)
+void test0(BlockTy b) {
+  noescapeFunc0(0, b);
+}
+
+// CHECK-LABEL: define void @test1(
+// CHECK: call void @noescapeFunc1([[TY1:.*]] nocapture {{.*}})
+// CHECK: declare void @noescapeFunc1([[TY1]] nocapture)
+void test1(int *i) {
+  noescapeFunc1(i);
+}
+
+// CHECK-LABEL: define void @test2(
+// CHECK: call void @noescapeFunc2([[TY2:.*]] nocapture {{.*}})
+// CHECK: declare void @noescapeFunc2([[TY2]] nocapture)
+void test2(id i) {
+  noescapeFunc2(i);
+}
+
+// CHECK-LABEL: define void @test3(
+// CHECK: call void @noescapeFunc3([[TY3:.*]] nocapture {{.*}})
+// CHECK: declare void @noescapeFunc3([[TY3]] nocapture)
+void test3(union U u) {
+  noescapeFunc3(u);
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -4478,6 +4478,11 @@
 HasAnyInterestingExtParameterInfos = true;
   }
 
+  if (Param->hasAttr()) {
+ExtParameterInfos[i] = ExtParameterInfos[i].withIsNoEscape();
+HasAnyInterestingExtParameterInfos = true;
+  }
+
   ParamTys.push_back(ParamTy);
 }
 
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -1517,6 +1517,22 @@
Attr.getAttributeSpellingListIndex()));
 }
 
+static void handleNoEscapeAttr(Sema , Decl *D, const AttributeList ) {
+  if (D->isInvalidDecl())
+return;
+
+  // noescape only applies to pointer types.
+  QualType T = cast(D)->getType();
+  if (!S.isValidPointerAttrType(T, /* RefOkay */ true)) {
+S.Diag(Attr.getLoc(), diag::warn_attribute_pointers_only)
+ 

[PATCH] D26350: Keep invalid Switch in the AST

2017-07-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D26350#809577, @ogoffart wrote:

> The problem i'm trying to solve is precisely to keep as much as possible of 
> the valid AST in the main AST, despite errors.
>  I've already done some work with r249982, r272962 and more, and there is 
> still a lot to do. But the goal is to keep as much as possible of it.


Thank you for the explanation -- I like the goal, but am definitely concerned 
about the assumptions it might break by doing this (in general, not specific to 
this patch). We try to recover gracefully whenever possible, but still, a whole 
lot of frontend code relies on knowing when something is invalid to prevent the 
compiler from doing even worse things. I'm not certain the best balance to 
strike with that, but suspect it's going to adversely impact tools like 
clang-tidy which tend to assume that AST matchers match *valid* code and not 
invalid code.




Comment at: lib/Parse/ParseStmt.cpp:1297
 
-  if (Switch.isInvalid()) {
-// Skip the switch body.
-// FIXME: This is not optimal recovery, but parsing the body is more
-// dangerous due to the presence of case and default statements, which
-// will have no place to connect back with the switch.
-if (Tok.is(tok::l_brace)) {
-  ConsumeBrace();
-  SkipUntil(tok::r_brace);
-} else
-  SkipUntil(tok::semi);
-return Switch;
-  }
+  assert(!Switch.isInvalid() && "ActOnStartOfSwitchStmt always succeed");
 

succeed -> succeeds

Are the concerns pointed out in the FIXME addressed by code not in this patch?



Comment at: lib/Sema/SemaStmt.cpp:669
   if (Cond.isInvalid())
-return StmtError();
+Cond = ConditionResult(
+*this, nullptr,

This makes the condition result valid when it isn't. Users of this condition 
result may expect a valid condition result to return nonnull values when 
calling `get()`, which makes me uncomfortable.


https://reviews.llvm.org/D26350



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35427: [clang] Fix handling of "%zd" format specifier

2017-07-14 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308067: [clang] Fix handling of "%zd" format specifier 
(authored by alexshap).

Changed prior to commit:
  https://reviews.llvm.org/D35427?vs=106694=106726#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35427

Files:
  cfe/trunk/lib/Analysis/PrintfFormatString.cpp
  cfe/trunk/test/FixIt/format.m


Index: cfe/trunk/lib/Analysis/PrintfFormatString.cpp
===
--- cfe/trunk/lib/Analysis/PrintfFormatString.cpp
+++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp
@@ -466,8 +466,7 @@
   case LengthModifier::AsIntMax:
 return ArgType(Ctx.getIntMaxType(), "intmax_t");
   case LengthModifier::AsSizeT:
-// FIXME: How to get the corresponding signed version of size_t?
-return ArgType();
+return ArgType(Ctx.getSignedSizeType(), "ssize_t");
   case LengthModifier::AsInt3264:
 return Ctx.getTargetInfo().getTriple().isArch64Bit()
? ArgType(Ctx.LongLongTy, "__int64")
@@ -537,7 +536,7 @@
   case LengthModifier::AsIntMax:
 return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t"));
   case LengthModifier::AsSizeT:
-return ArgType(); // FIXME: ssize_t
+return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
   case LengthModifier::AsPtrDiff:
 return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
   case LengthModifier::AsLongDouble:
Index: cfe/trunk/test/FixIt/format.m
===
--- cfe/trunk/test/FixIt/format.m
+++ cfe/trunk/test/FixIt/format.m
@@ -229,6 +229,19 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld"
 }
 
+void testSizeTypes() {
+  printf("%zu", 0.f); // expected-warning{{format specifies type 'size_t' (aka 
'unsigned long') but the argument has type 'float'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+
+  printf("%zd", 0.f); // expected-warning{{format specifies type 'ssize_t' 
(aka 'long') but the argument has type 'float'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+  
+  int x;
+  printf("%zn", ); // expected-warning{{format specifies type 'ssize_t *' 
(aka 'long *') but the argument has type 'int *'}}
+  // PrintfSpecifier::fixType doesn't handle %n, so a fix-it is not emitted, 
+  // see the comment in PrintfSpecifier::fixType in PrintfFormatString.cpp.
+}
+
 void testEnum() {
   typedef enum {
 ImplicitA = 1,


Index: cfe/trunk/lib/Analysis/PrintfFormatString.cpp
===
--- cfe/trunk/lib/Analysis/PrintfFormatString.cpp
+++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp
@@ -466,8 +466,7 @@
   case LengthModifier::AsIntMax:
 return ArgType(Ctx.getIntMaxType(), "intmax_t");
   case LengthModifier::AsSizeT:
-// FIXME: How to get the corresponding signed version of size_t?
-return ArgType();
+return ArgType(Ctx.getSignedSizeType(), "ssize_t");
   case LengthModifier::AsInt3264:
 return Ctx.getTargetInfo().getTriple().isArch64Bit()
? ArgType(Ctx.LongLongTy, "__int64")
@@ -537,7 +536,7 @@
   case LengthModifier::AsIntMax:
 return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t"));
   case LengthModifier::AsSizeT:
-return ArgType(); // FIXME: ssize_t
+return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
   case LengthModifier::AsPtrDiff:
 return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
   case LengthModifier::AsLongDouble:
Index: cfe/trunk/test/FixIt/format.m
===
--- cfe/trunk/test/FixIt/format.m
+++ cfe/trunk/test/FixIt/format.m
@@ -229,6 +229,19 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld"
 }
 
+void testSizeTypes() {
+  printf("%zu", 0.f); // expected-warning{{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'float'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+
+  printf("%zd", 0.f); // expected-warning{{format specifies type 'ssize_t' (aka 'long') but the argument has type 'float'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+  
+  int x;
+  printf("%zn", ); // expected-warning{{format specifies type 'ssize_t *' (aka 'long *') but the argument has type 'int *'}}
+  // PrintfSpecifier::fixType doesn't handle %n, so a fix-it is not emitted, 
+  // see the comment in PrintfSpecifier::fixType in PrintfFormatString.cpp.
+}
+
 void testEnum() {
   typedef enum {
 ImplicitA = 1,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308067 - [clang] Fix handling of "%zd" format specifier

2017-07-14 Thread Alexander Shaposhnikov via cfe-commits
Author: alexshap
Date: Fri Jul 14 15:57:00 2017
New Revision: 308067

URL: http://llvm.org/viewvc/llvm-project?rev=308067=rev
Log:
[clang] Fix handling of "%zd" format specifier

This diff addresses FIXME in lib/Analysis/PrintfFormatString.cpp
and makes PrintfSpecifier::getArgType return the correct type. 
In particular, this change enables Clang to emit a warning on 
incorrect using of "%zd"/"%zn" format specifiers.

Differential revision: https://reviews.llvm.org/D35427

Test plan: make check-all

Modified:
cfe/trunk/lib/Analysis/PrintfFormatString.cpp
cfe/trunk/test/FixIt/format.m

Modified: cfe/trunk/lib/Analysis/PrintfFormatString.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/PrintfFormatString.cpp?rev=308067=308066=308067=diff
==
--- cfe/trunk/lib/Analysis/PrintfFormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp Fri Jul 14 15:57:00 2017
@@ -466,8 +466,7 @@ ArgType PrintfSpecifier::getArgType(ASTC
   case LengthModifier::AsIntMax:
 return ArgType(Ctx.getIntMaxType(), "intmax_t");
   case LengthModifier::AsSizeT:
-// FIXME: How to get the corresponding signed version of size_t?
-return ArgType();
+return ArgType(Ctx.getSignedSizeType(), "ssize_t");
   case LengthModifier::AsInt3264:
 return Ctx.getTargetInfo().getTriple().isArch64Bit()
? ArgType(Ctx.LongLongTy, "__int64")
@@ -537,7 +536,7 @@ ArgType PrintfSpecifier::getArgType(ASTC
   case LengthModifier::AsIntMax:
 return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t"));
   case LengthModifier::AsSizeT:
-return ArgType(); // FIXME: ssize_t
+return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
   case LengthModifier::AsPtrDiff:
 return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
   case LengthModifier::AsLongDouble:

Modified: cfe/trunk/test/FixIt/format.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/format.m?rev=308067=308066=308067=diff
==
--- cfe/trunk/test/FixIt/format.m (original)
+++ cfe/trunk/test/FixIt/format.m Fri Jul 14 15:57:00 2017
@@ -229,6 +229,19 @@ void testSignedness(long i, unsigned lon
   // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld"
 }
 
+void testSizeTypes() {
+  printf("%zu", 0.f); // expected-warning{{format specifies type 'size_t' (aka 
'unsigned long') but the argument has type 'float'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+
+  printf("%zd", 0.f); // expected-warning{{format specifies type 'ssize_t' 
(aka 'long') but the argument has type 'float'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+  
+  int x;
+  printf("%zn", ); // expected-warning{{format specifies type 'ssize_t *' 
(aka 'long *') but the argument has type 'int *'}}
+  // PrintfSpecifier::fixType doesn't handle %n, so a fix-it is not emitted, 
+  // see the comment in PrintfSpecifier::fixType in PrintfFormatString.cpp.
+}
+
 void testEnum() {
   typedef enum {
 ImplicitA = 1,


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35438: CodeGen: Ensure there is basic block when performing address space cast

2017-07-14 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Hmm.  It doesn't seem unreasonable for this to require an insertion point as a 
precondition.  In what situation do we emit addrspace casts after a return?


https://reviews.llvm.org/D35438



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35427: [clang] Fix handling of "%zd" format specifier

2017-07-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rL LLVM

https://reviews.llvm.org/D35427



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35438: CodeGen: Ensure there is basic block when performing address space cast

2017-07-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.

There are cases when TargetCodeGenInfo::performAddrSpaceCast is called there is 
no basic block,
e.g. right after a `return` statement. This causes dangling addrspacecast.

This patch fixes that.


https://reviews.llvm.org/D35438

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGenCXX/amdgcn-automatic-variable.cpp


Index: test/CodeGenCXX/amdgcn-automatic-variable.cpp
===
--- test/CodeGenCXX/amdgcn-automatic-variable.cpp
+++ test/CodeGenCXX/amdgcn-automatic-variable.cpp
@@ -81,4 +81,10 @@
   func1();
 }
 
+// CHECK-LABEL: define void @_Z5func5v
+void func5() {
+  return;
+  int x = 0;
+}
+
 // CHECK-NOT: !opencl.ocl.version
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -432,6 +432,7 @@
   // space, an address space conversion may end up as a bitcast.
   if (auto *C = dyn_cast(Src))
 return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestAddr, DestTy);
+  CGF.EnsureInsertPoint();
   return CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Src, DestTy);
 }
 


Index: test/CodeGenCXX/amdgcn-automatic-variable.cpp
===
--- test/CodeGenCXX/amdgcn-automatic-variable.cpp
+++ test/CodeGenCXX/amdgcn-automatic-variable.cpp
@@ -81,4 +81,10 @@
   func1();
 }
 
+// CHECK-LABEL: define void @_Z5func5v
+void func5() {
+  return;
+  int x = 0;
+}
+
 // CHECK-NOT: !opencl.ocl.version
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -432,6 +432,7 @@
   // space, an address space conversion may end up as a bitcast.
   if (auto *C = dyn_cast(Src))
 return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestAddr, DestTy);
+  CGF.EnsureInsertPoint();
   return CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Src, DestTy);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34475: [AArch64] Add support for __builtin_ms_va_list on aarch64

2017-07-14 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo updated this revision to Diff 106701.
mstorsjo added a comment.

Updated for the new version of https://reviews.llvm.org/D34474.


https://reviews.llvm.org/D34475

Files:
  include/clang-c/Index.h
  include/clang/Basic/Builtins.def
  include/clang/Basic/BuiltinsX86.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/Specifiers.h
  lib/AST/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/ms_abi.c
  test/CodeGen/ms_abi_aarch64.c
  test/CodeGenObjC/attr-callconv.m
  test/Sema/varargs-aarch64.c
  test/Sema/varargs-x86-32.c
  tools/libclang/CXType.cpp

Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -611,7 +611,7 @@
   TCALLINGCONV(X86Pascal);
   TCALLINGCONV(X86RegCall);
   TCALLINGCONV(X86VectorCall);
-  TCALLINGCONV(X86_64Win64);
+  TCALLINGCONV(Win64);
   TCALLINGCONV(X86_64SysV);
   TCALLINGCONV(AAPCS);
   TCALLINGCONV(AAPCS_VFP);
Index: test/Sema/varargs-x86-32.c
===
--- test/Sema/varargs-x86-32.c
+++ test/Sema/varargs-x86-32.c
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s -triple i386-apple-darwin9
 
 void foo(int a, ...) {
-  __builtin_ms_va_start((void *)0, a); // expected-error {{this builtin is only available on x86-64 targets}}
+  __builtin_ms_va_start((void *)0, a); // expected-error {{this builtin is only available on x86-64 and aarch64 targets}}
 }
Index: test/Sema/varargs-aarch64.c
===
--- /dev/null
+++ test/Sema/varargs-aarch64.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple aarch64-linux-gnu
+
+void f1(int a, ...) {
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap, a); // expected-error {{'__builtin_ms_va_start' used in System V ABI function}}
+}
+
+void __attribute__((ms_abi)) f2(int a, ...) {
+  __builtin_va_list ap;
+  __builtin_va_start(ap, a); // expected-error {{'va_start' used in Win64 ABI function}}
+}
Index: test/CodeGenObjC/attr-callconv.m
===
--- test/CodeGenObjC/attr-callconv.m
+++ test/CodeGenObjC/attr-callconv.m
@@ -9,5 +9,5 @@
 // CHECK: define{{.*}}x86_stdcallcc{{.*}}Test test
 
 - (void)test2 __attribute__((ms_abi)) {}
-// CHECK: define{{.*}}x86_64_win64cc{{.*}}Test test2
+// CHECK: define{{.*}}win64cc{{.*}}Test test2
 @end
Index: test/CodeGen/ms_abi_aarch64.c
===
--- /dev/null
+++ test/CodeGen/ms_abi_aarch64.c
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm < %s | FileCheck -check-prefix=LINUX %s
+// RUN: %clang_cc1 -triple aarch64-pc-win32 -emit-llvm < %s | FileCheck -check-prefix=WIN64 %s
+
+void __attribute__((ms_abi)) f1(void);
+void f2(void);
+void f3(void) {
+  // LINUX-LABEL: define void @f3()
+  // WIN64-LABEL: define void @f3()
+  f1();
+  // LINUX: call win64cc void @f1()
+  // WIN64: call void @f1()
+  f2();
+  // LINUX: call void @f2()
+  // WIN64: call void @f2()
+}
+// LINUX: declare win64cc void @f1()
+// LINUX: declare void @f2()
+// WIN64: declare void @f1()
+// WIN64: declare void @f2()
+
+// Win64 ABI varargs
+void __attribute__((ms_abi)) f4(int a, ...) {
+  // LINUX-LABEL: define win64cc void @f4
+  // WIN64-LABEL: define void @f4
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap, a);
+  // LINUX: %[[AP:.*]] = alloca i8*
+  // LINUX: call void @llvm.va_start
+  // WIN64: %[[AP:.*]] = alloca i8*
+  // WIN64: call void @llvm.va_start
+  int b = __builtin_va_arg(ap, int);
+  // LINUX: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
+  // LINUX-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
+  // LINUX-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
+  // LINUX-NEXT: bitcast i8* %[[AP_CUR]] to i32*
+  // WIN64: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
+  // WIN64-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
+  // WIN64-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
+  // WIN64-NEXT: bitcast i8* %[[AP_CUR]] to i32*
+  __builtin_ms_va_list ap2;
+  __builtin_ms_va_copy(ap2, ap);
+  // LINUX: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
+  // LINUX-NEXT: store i8* %[[AP_VAL]], i8** %[[AP2:.*]]
+  // WIN64: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
+  // WIN64-NEXT: store i8* %[[AP_VAL]], i8** %[[AP2:.*]]
+  __builtin_ms_va_end(ap);
+  // LINUX: call void @llvm.va_end
+  // WIN64: call void @llvm.va_end
+}
+
+// Let's verify that normal va_lists work right on Win64, too.
+void f5(int a, ...) {
+  // WIN64-LABEL: define void @f5
+  __builtin_va_list ap;
+  __builtin_va_start(ap, a);
+  // WIN64: 

[PATCH] D35081: [ThinLTO] Allow multiple summary entries.

2017-07-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In https://reviews.llvm.org/D35081#808789, @tejohnson wrote:

> In https://reviews.llvm.org/D35081#808517, @mehdi_amini wrote:
>
> > In https://reviews.llvm.org/D35081#808207, @tejohnson wrote:
> >
> > > My first option was if any copy is under the threshold, simply pick the 
> > > prevailing copy (it may be over threshold, but assume we want that one 
> > > anyway). Another possibility is to only allow importing of the prevailing 
> > > copy, if it is over the inst limit, too bad. The main reason I think that 
> > > could be better is when we have PGO - the prevailing copy would for sure 
> > > have the matched PGO data, but the non-prevailing copies may not.
> >
> >
> > Ah makes sense, both way are fine with me.
> >
> > I'd rather limit to the prevailing copy though and too bad if it is over 
> > the limit, to avoid the possibility of too large importing just because 
> > there was a small non-prevailing somewhere, but likely a rare case.
>
>
> SGTM. That's also very simple to implement.  I've just been to swamped with 
> other things so far to do it. Just chatted with Yunlian, he is not blocked.


https://reviews.llvm.org/D35436


https://reviews.llvm.org/D35081



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35427: [clang] Fix handling of "%zd" format specifier

2017-07-14 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexshap updated this revision to Diff 106694.
alexshap added a comment.

Address comments


Repository:
  rL LLVM

https://reviews.llvm.org/D35427

Files:
  lib/Analysis/PrintfFormatString.cpp
  test/FixIt/format.m


Index: test/FixIt/format.m
===
--- test/FixIt/format.m
+++ test/FixIt/format.m
@@ -229,6 +229,19 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld"
 }
 
+void testSizeTypes() {
+  printf("%zu", 0.f); // expected-warning{{format specifies type 'size_t' (aka 
'unsigned long') but the argument has type 'float'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+
+  printf("%zd", 0.f); // expected-warning{{format specifies type 'ssize_t' 
(aka 'long') but the argument has type 'float'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+  
+  int x;
+  printf("%zn", ); // expected-warning{{format specifies type 'ssize_t *' 
(aka 'long *') but the argument has type 'int *'}}
+  // PrintfSpecifier::fixType doesn't handle %n, so a fix-it is not emitted, 
+  // see the comment in PrintfSpecifier::fixType in PrintfFormatString.cpp.
+}
+
 void testEnum() {
   typedef enum {
 ImplicitA = 1,
Index: lib/Analysis/PrintfFormatString.cpp
===
--- lib/Analysis/PrintfFormatString.cpp
+++ lib/Analysis/PrintfFormatString.cpp
@@ -466,8 +466,7 @@
   case LengthModifier::AsIntMax:
 return ArgType(Ctx.getIntMaxType(), "intmax_t");
   case LengthModifier::AsSizeT:
-// FIXME: How to get the corresponding signed version of size_t?
-return ArgType();
+return ArgType(Ctx.getSignedSizeType(), "ssize_t");
   case LengthModifier::AsInt3264:
 return Ctx.getTargetInfo().getTriple().isArch64Bit()
? ArgType(Ctx.LongLongTy, "__int64")
@@ -537,7 +536,7 @@
   case LengthModifier::AsIntMax:
 return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t"));
   case LengthModifier::AsSizeT:
-return ArgType(); // FIXME: ssize_t
+return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
   case LengthModifier::AsPtrDiff:
 return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
   case LengthModifier::AsLongDouble:


Index: test/FixIt/format.m
===
--- test/FixIt/format.m
+++ test/FixIt/format.m
@@ -229,6 +229,19 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld"
 }
 
+void testSizeTypes() {
+  printf("%zu", 0.f); // expected-warning{{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'float'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+
+  printf("%zd", 0.f); // expected-warning{{format specifies type 'ssize_t' (aka 'long') but the argument has type 'float'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+  
+  int x;
+  printf("%zn", ); // expected-warning{{format specifies type 'ssize_t *' (aka 'long *') but the argument has type 'int *'}}
+  // PrintfSpecifier::fixType doesn't handle %n, so a fix-it is not emitted, 
+  // see the comment in PrintfSpecifier::fixType in PrintfFormatString.cpp.
+}
+
 void testEnum() {
   typedef enum {
 ImplicitA = 1,
Index: lib/Analysis/PrintfFormatString.cpp
===
--- lib/Analysis/PrintfFormatString.cpp
+++ lib/Analysis/PrintfFormatString.cpp
@@ -466,8 +466,7 @@
   case LengthModifier::AsIntMax:
 return ArgType(Ctx.getIntMaxType(), "intmax_t");
   case LengthModifier::AsSizeT:
-// FIXME: How to get the corresponding signed version of size_t?
-return ArgType();
+return ArgType(Ctx.getSignedSizeType(), "ssize_t");
   case LengthModifier::AsInt3264:
 return Ctx.getTargetInfo().getTriple().isArch64Bit()
? ArgType(Ctx.LongLongTy, "__int64")
@@ -537,7 +536,7 @@
   case LengthModifier::AsIntMax:
 return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t"));
   case LengthModifier::AsSizeT:
-return ArgType(); // FIXME: ssize_t
+return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
   case LengthModifier::AsPtrDiff:
 return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
   case LengthModifier::AsLongDouble:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D34440: [Clang] Expand response files before loading compilation database

2017-07-14 Thread Joerg Sonnenberger via cfe-commits
On Fri, Jul 14, 2017 at 02:40:25PM +, Manuel Klimek via Phabricator via 
cfe-commits wrote:
> klimek added a comment.
> 
> In https://reviews.llvm.org/D34440#809581, @vladimir.plyashkun wrote:
> 
> > > Are there any concerns using the alternative?
> >
> > I can't say that it's a big problems, but i think that:
> >  //CompilationDatabase.json// is more //CMake //specific format. 
> >  It can be generated automatically by //CMake//, while other build systems 
> > may not do it.
> >  So we need to generate it on the fly (by tool or by hand), which also can 
> > lead to hidden problems due to different formats, different escaping rules, 
> > etc.
> >  I think it's always good to have one unified format.
> 
> 
> The compilation database is most certainly not cmake specific. We
> designed it in clang, and then implemented it in cmake as an example,
> because that's the most widely used C++ build system we were aware of
> (aside from autotools, which we didn't want to touch :).  There are
> ways to create it from other build systems (ninja has support, and
> there are tools that provide generic support to intercept compiles).

Don't use interceptors, just use -MJ. It should be very easy to hook up
into any build system that can also use -MM etc.

Joerg
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34475: [AArch64] Add support for __builtin_ms_va_list on aarch64

2017-07-14 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo updated this revision to Diff 106690.
mstorsjo edited the summary of this revision.
mstorsjo added a comment.

Initial attempt at unifying the use of __builtin_ms_va_list and calling 
conventions between x86_64 and aarch64. This goes with the current (un-unified) 
version of https://reviews.llvm.org/D34474.

I only hooked up __attribute__((ms_abi)) on aarch64, I didn't hook up sysv_abi 
yet, because it's not obvious what it should map to, since aarch64 has got two 
other calling conventions in addition to the win64 one; standard AAPCS (for ELF 
systems) and the darwin modification of AAPCS. Since that's not directly needed 
for the wine usecase, I'm omitting that for now.


https://reviews.llvm.org/D34475

Files:
  include/clang-c/Index.h
  include/clang/Basic/Builtins.def
  include/clang/Basic/BuiltinsX86.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/Specifiers.h
  lib/AST/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/ms_abi_aarch64.c
  test/Sema/varargs-aarch64.c
  test/Sema/varargs-x86-32.c
  tools/libclang/CXType.cpp

Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -611,7 +611,7 @@
   TCALLINGCONV(X86Pascal);
   TCALLINGCONV(X86RegCall);
   TCALLINGCONV(X86VectorCall);
-  TCALLINGCONV(X86_64Win64);
+  TCALLINGCONV(Win64);
   TCALLINGCONV(X86_64SysV);
   TCALLINGCONV(AAPCS);
   TCALLINGCONV(AAPCS_VFP);
Index: test/Sema/varargs-x86-32.c
===
--- test/Sema/varargs-x86-32.c
+++ test/Sema/varargs-x86-32.c
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s -triple i386-apple-darwin9
 
 void foo(int a, ...) {
-  __builtin_ms_va_start((void *)0, a); // expected-error {{this builtin is only available on x86-64 targets}}
+  __builtin_ms_va_start((void *)0, a); // expected-error {{this builtin is only available on x86-64 and aarch64 targets}}
 }
Index: test/Sema/varargs-aarch64.c
===
--- /dev/null
+++ test/Sema/varargs-aarch64.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple aarch64-linux-gnu
+
+void f1(int a, ...) {
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap, a); // expected-error {{'__builtin_ms_va_start' used in System V ABI function}}
+}
+
+void __attribute__((ms_abi)) f2(int a, ...) {
+  __builtin_va_list ap;
+  __builtin_va_start(ap, a); // expected-error {{'va_start' used in Win64 ABI function}}
+}
Index: test/CodeGen/ms_abi_aarch64.c
===
--- /dev/null
+++ test/CodeGen/ms_abi_aarch64.c
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm < %s | FileCheck -check-prefix=LINUX %s
+// RUN: %clang_cc1 -triple aarch64-pc-win32 -emit-llvm < %s | FileCheck -check-prefix=WIN64 %s
+
+void __attribute__((ms_abi)) f1(void);
+void f2(void);
+void f3(void) {
+  // LINUX-LABEL: define void @f3()
+  // WIN64-LABEL: define void @f3()
+  f1();
+  // LINUX: call aarch64_win64cc void @f1()
+  // WIN64: call void @f1()
+  f2();
+  // LINUX: call void @f2()
+  // WIN64: call void @f2()
+}
+// LINUX: declare aarch64_win64cc void @f1()
+// LINUX: declare void @f2()
+// WIN64: declare void @f1()
+// WIN64: declare void @f2()
+
+// Win64 ABI varargs
+void __attribute__((ms_abi)) f4(int a, ...) {
+  // LINUX-LABEL: define aarch64_win64cc void @f4
+  // WIN64-LABEL: define void @f4
+  __builtin_ms_va_list ap;
+  __builtin_ms_va_start(ap, a);
+  // LINUX: %[[AP:.*]] = alloca i8*
+  // LINUX: call void @llvm.va_start
+  // WIN64: %[[AP:.*]] = alloca i8*
+  // WIN64: call void @llvm.va_start
+  int b = __builtin_va_arg(ap, int);
+  // LINUX: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
+  // LINUX-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
+  // LINUX-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
+  // LINUX-NEXT: bitcast i8* %[[AP_CUR]] to i32*
+  // WIN64: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
+  // WIN64-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
+  // WIN64-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
+  // WIN64-NEXT: bitcast i8* %[[AP_CUR]] to i32*
+  __builtin_ms_va_list ap2;
+  __builtin_ms_va_copy(ap2, ap);
+  // LINUX: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
+  // LINUX-NEXT: store i8* %[[AP_VAL]], i8** %[[AP2:.*]]
+  // WIN64: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
+  // WIN64-NEXT: store i8* %[[AP_VAL]], i8** %[[AP2:.*]]
+  __builtin_ms_va_end(ap);
+  // LINUX: call void @llvm.va_end
+  // WIN64: call void @llvm.va_end
+}
+
+// Let's verify that normal va_lists work right on Win64, too.
+void f5(int a, ...) {
+  // 

[PATCH] D34937: Suppressing Reference Counting Diagnostics for Functions Containing 'rc_ownership_trusted_implementation' Annotate Attribute

2017-07-14 Thread Malhar Thakkar via Phabricator via cfe-commits
malhar1995 updated this revision to Diff 106685.
malhar1995 added a comment.

Suppresses false positives involving functions which perform reference counting.
Added relevant test-cases to test/Analysis/retain-release-inline.m


https://reviews.llvm.org/D34937

Files:
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
  test/Analysis/retain-release-inline.m

Index: test/Analysis/retain-release-inline.m
===
--- test/Analysis/retain-release-inline.m
+++ test/Analysis/retain-release-inline.m
@@ -12,7 +12,7 @@
 //
 // It includes the basic definitions for the test cases below.
 //===--===//
-
+#define NULL 0
 typedef unsigned int __darwin_natural_t;
 typedef unsigned long uintptr_t;
 typedef unsigned int uint32_t;
@@ -267,6 +267,10 @@
 
 extern CFStringRef CFStringCreateWithCStringNoCopy(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding, CFAllocatorRef contentsDeallocator);
 
+typedef struct {
+  int ref;
+} isl_basic_map;
+
 //===--===//
 // Test cases.
 //===--===//
@@ -285,6 +289,7 @@
   foo(s);
   bar(s);
 }
+
 void test_neg() {
   NSString *s = [[NSString alloc] init]; // no-warning  
   foo(s);
@@ -294,6 +299,56 @@
   bar(s);
 }
 
+__attribute__((cf_returns_retained)) isl_basic_map *isl_basic_map_cow(__attribute__((cf_consumed)) isl_basic_map *bmap);
+void free(void *);
+
+// As 'isl_basic_map_free' is annotated with 'rc_ownership_trusted_implementation', RetainCountChecker trusts its
+// implementation and doesn't analyze its body. If the annotation 'rc_ownership_trusted_implementation' is removed,
+// a leak warning is raised by RetainCountChecker as the analyzer is unable to detect a decrement in the reference
+// count of 'bmap' along the path in 'isl_basic_map_free' assuming the predicate of the second 'if' branch to be
+// true or assuming both the predicates in the function to be false.
+__attribute__((annotate("rc_ownership_trusted_implementation"))) isl_basic_map *isl_basic_map_free(__attribute__((cf_consumed)) isl_basic_map *bmap) {
+  if (!bmap)
+return NULL;
+
+  if (--bmap->ref > 0)
+return NULL;
+
+  free(bmap);
+  return NULL;
+}
+
+// As 'isl_basic_map_copy' is annotated with 'rc_ownership_trusted_implementation', RetainCountChecker trusts its
+// implementation and doesn't analyze its body. If that annotation is removed, a 'use-after-release' warning might
+// be raised by RetainCountChecker as the pointer which is passed as an argument to this function and the pointer
+// which is returned from the function point to the same memory location.
+__attribute__((annotate("rc_ownership_trusted_implementation"))) __attribute__((cf_returns_retained)) isl_basic_map *isl_basic_map_copy(isl_basic_map *bmap)
+{
+  if (!bmap)
+return NULL;
+
+  bmap->ref++;
+  return bmap;
+}
+
+void test_use_after_release_with_trusted_implementation_annotate_attribute(__attribute__((cf_consumed)) isl_basic_map *bmap) {
+  // After this call, 'bmap' has a +1 reference count.
+  bmap = isl_basic_map_cow(bmap);
+  // After the call to 'isl_basic_map_copy', 'bmap' has a +1 reference count.
+  isl_basic_map *temp = isl_basic_map_cow(isl_basic_map_copy(bmap));
+  // After this call, 'bmap' has a +0 reference count.
+  isl_basic_map *temp2 = isl_basic_map_cow(bmap); // no-warning
+  isl_basic_map_free(temp2);
+  isl_basic_map_free(temp);
+}
+
+void test_leak_with_trusted_implementation_annotate_attribute(__attribute__((cf_consumed)) isl_basic_map *bmap) {
+  // After this call, 'bmap' has a +1 reference count.
+  bmap = isl_basic_map_cow(bmap); // no-warning
+  // After this call, 'bmap' has a +0 reference count.
+  isl_basic_map_free(bmap);
+}
+
 //===--===//
 // Test returning retained and not-retained values.
 //===--===//
Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1894,6 +1894,16 @@
   return SFC->getAnalysisDeclContext()->isBodyAutosynthesized();
 }
 
+/// Returns true if the function declaration 'FD' contains
+/// 'rc_ownership_trusted_implementation' annotate attribute.
+bool isTrustedReferenceCountImplementation(const FunctionDecl *FD) {
+  for (const auto *Ann : FD->specific_attrs()) {
+if (Ann->getAnnotation() == "rc_ownership_trusted_implementation")
+  return true;
+  }
+  return false;
+}
+
 std::shared_ptr
 CFRefReportVisitor::VisitNode(const ExplodedNode *N, const ExplodedNode *PrevN,
   BugReporterContext , BugReport ) {
@@ -3380,6 +3390,9 @@
 
   // 

[PATCH] D35379: Add documentation for @available

2017-07-14 Thread Nico Weber via Phabricator via cfe-commits
thakis marked an inline comment as done.
thakis added inline comments.



Comment at: docs/LanguageExtensions.rst:1278
+It is possible use the newest SDK but still build a program that can run on
+older macOS and iOS versions, by passing ``-mmacosx-version-info=`` /
+``--miphoneos-version-min=``.

sdy wrote:
> thakis wrote:
> > sdy wrote:
> > > arphaman wrote:
> > > > Nit: older versions of macOS or iOS
> > > I thought this flag was `--mmacosx-version-min`?
> > > Nit: I would remove the comma after "versions".
> > Nicos-MacBook-Pro:llvm-build thakis$ bin/clang -mmacosx-version-min=10.11 
> > -c test.mm
> > Nicos-MacBook-Pro:llvm-build thakis$ bin/clang --mmacosx-version-min=10.11 
> > -c test.mm
> > clang-3.5: error: unsupported option '--mmacosx-version-min=10.11'
> > 
> > Removed comma.
> Sorry, I added an extra dash in the comment. I meant that the CL says 
> mmacosx-version-**info**, not min.
Oooh I see. Thanks, fixed in 
http://llvm.org/viewvc/llvm-project?rev=308048=rev


https://reviews.llvm.org/D35379



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308048 - Fix flag names in @available docs.

2017-07-14 Thread Nico Weber via cfe-commits
Author: nico
Date: Fri Jul 14 11:52:30 2017
New Revision: 308048

URL: http://llvm.org/viewvc/llvm-project?rev=308048=rev
Log:
Fix flag names in @available docs.

Modified:
cfe/trunk/docs/LanguageExtensions.rst

Modified: cfe/trunk/docs/LanguageExtensions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.rst?rev=308048=308047=308048=diff
==
--- cfe/trunk/docs/LanguageExtensions.rst (original)
+++ cfe/trunk/docs/LanguageExtensions.rst Fri Jul 14 11:52:30 2017
@@ -1275,8 +1275,8 @@ Objective-C @available
 --
 
 It is possible to use the newest SDK but still build a program that can run on
-older versions of macOS and iOS by passing ``-mmacosx-version-info=`` /
-``--miphoneos-version-min=``.
+older versions of macOS and iOS by passing ``-mmacosx-version-min=`` /
+``-miphoneos-version-min=``.
 
 Before LLVM 5.0, when calling a function that exists only in the OS that's
 newer than the target OS (as determined by the minimum deployment version),


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35379: Add documentation for @available

2017-07-14 Thread Sidney San Martín via Phabricator via cfe-commits
sdy added inline comments.



Comment at: docs/LanguageExtensions.rst:1278
+It is possible use the newest SDK but still build a program that can run on
+older macOS and iOS versions, by passing ``-mmacosx-version-info=`` /
+``--miphoneos-version-min=``.

thakis wrote:
> sdy wrote:
> > arphaman wrote:
> > > Nit: older versions of macOS or iOS
> > I thought this flag was `--mmacosx-version-min`?
> > Nit: I would remove the comma after "versions".
> Nicos-MacBook-Pro:llvm-build thakis$ bin/clang -mmacosx-version-min=10.11 -c 
> test.mm
> Nicos-MacBook-Pro:llvm-build thakis$ bin/clang --mmacosx-version-min=10.11 -c 
> test.mm
> clang-3.5: error: unsupported option '--mmacosx-version-min=10.11'
> 
> Removed comma.
Sorry, I added an extra dash in the comment. I meant that the CL says 
mmacosx-version-**info**, not min.


https://reviews.llvm.org/D35379



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308046 - Fix link in docs.

2017-07-14 Thread Nico Weber via cfe-commits
Author: nico
Date: Fri Jul 14 11:45:36 2017
New Revision: 308046

URL: http://llvm.org/viewvc/llvm-project?rev=308046=rev
Log:
Fix link in docs.

Modified:
cfe/trunk/include/clang/Basic/AttrDocs.td

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=308046=308045=308046=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Fri Jul 14 11:45:36 2017
@@ -1027,7 +1027,7 @@ Starting with the macOS 10.12 SDK, the `
   @end
 
 Also see the documentation for `@available
-`_
+`_
   }];
 }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35379: Add documentation for @available

2017-07-14 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

I went ahead and landed this in r308044, given that I addressed the nits and 
removed the possibly contentious bits. Happy to address remaining nits in a 
follow-up.


https://reviews.llvm.org/D35379



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308045 - do more processing in clang-fuzzer (use EmitAssemblyAction)

2017-07-14 Thread Kostya Serebryany via cfe-commits
Author: kcc
Date: Fri Jul 14 11:42:07 2017
New Revision: 308045

URL: http://llvm.org/viewvc/llvm-project?rev=308045=rev
Log:
do more processing in clang-fuzzer (use EmitAssemblyAction)

Summary: use EmitAssemblyAction in clang-fuzzer

Reviewers: klimek, rsmith

Reviewed By: klimek

Subscribers: cfe-commits, mgorny

Differential Revision: https://reviews.llvm.org/D34267

Modified:
cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp

Modified: cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/CMakeLists.txt?rev=308045=308044=308045=diff
==
--- cfe/trunk/tools/clang-fuzzer/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-fuzzer/CMakeLists.txt Fri Jul 14 11:42:07 2017
@@ -1,5 +1,5 @@
 if( LLVM_USE_SANITIZE_COVERAGE )
-  set(LLVM_LINK_COMPONENTS support)
+  set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD})
 
   add_clang_executable(clang-fuzzer
 EXCLUDE_FROM_ALL
@@ -10,6 +10,7 @@ if( LLVM_USE_SANITIZE_COVERAGE )
 ${CLANG_FORMAT_LIB_DEPS}
 clangAST
 clangBasic
+clangCodeGen
 clangDriver
 clangFrontend
 clangRewriteFrontend

Modified: cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp?rev=308045=308044=308045=diff
==
--- cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp (original)
+++ cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp Fri Jul 14 11:42:07 2017
@@ -14,18 +14,25 @@
 
//===--===//
 
 #include "clang/Tooling/Tooling.h"
-#include "clang/Frontend/FrontendActions.h"
+#include "clang/CodeGen/CodeGenAction.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/Option/Option.h"
+#include "llvm/Support/TargetSelect.h"
 
 using namespace clang;
 
 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
   std::string s((const char *)data, size);
+  llvm::InitializeAllTargets();
+  llvm::InitializeAllTargetMCs();
+  llvm::InitializeAllAsmPrinters();
+  llvm::InitializeAllAsmParsers();
+
   llvm::opt::ArgStringList CC1Args;
   CC1Args.push_back("-cc1");
   CC1Args.push_back("./test.cc");
+  CC1Args.push_back("-O2");
   llvm::IntrusiveRefCntPtr Files(
   new FileManager(FileSystemOptions()));
   IgnoringDiagConsumer Diags;
@@ -39,7 +46,7 @@ extern "C" int LLVMFuzzerTestOneInput(ui
   llvm::MemoryBuffer::getMemBuffer(s);
   Invocation->getPreprocessorOpts().addRemappedFile("./test.cc", 
Input.release());
   std::unique_ptr action(
-  tooling::newFrontendActionFactory());
+  tooling::newFrontendActionFactory());
   std::shared_ptr PCHContainerOps =
   std::make_shared();
   action->runInvocation(std::move(Invocation), Files.get(), PCHContainerOps,


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308044 - Add documentation for @available

2017-07-14 Thread Nico Weber via cfe-commits
Author: nico
Date: Fri Jul 14 11:40:52 2017
New Revision: 308044

URL: http://llvm.org/viewvc/llvm-project?rev=308044=rev
Log:
Add documentation for @available

https://reviews.llvm.org/D35379

Modified:
cfe/trunk/docs/LanguageExtensions.rst
cfe/trunk/include/clang/Basic/AttrDocs.td

Modified: cfe/trunk/docs/LanguageExtensions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.rst?rev=308044=308043=308044=diff
==
--- cfe/trunk/docs/LanguageExtensions.rst (original)
+++ cfe/trunk/docs/LanguageExtensions.rst Fri Jul 14 11:40:52 2017
@@ -1271,6 +1271,87 @@ Further examples of these attributes are
 Query for these features with ``__has_attribute(ns_consumed)``,
 ``__has_attribute(ns_returns_retained)``, etc.
 
+Objective-C @available
+--
+
+It is possible to use the newest SDK but still build a program that can run on
+older versions of macOS and iOS by passing ``-mmacosx-version-info=`` /
+``--miphoneos-version-min=``.
+
+Before LLVM 5.0, when calling a function that exists only in the OS that's
+newer than the target OS (as determined by the minimum deployment version),
+programmers had to carefully check if the function exists at runtime, using
+null checks for weakly-linked C functions, ``+class`` for Objective-C classes,
+and ``-respondsToSelector:`` or ``+instancesRespondToSelector:`` for
+Objective-C methods.  If such a check was missed, the program would compile
+fine, run fine on newer systems, but crash on older systems.
+
+As of LLVM 5.0, ``-Wunguarded-availability`` uses the `availability attributes
+`_ together
+with the new ``@available()`` keyword to assist with this issue.
+When a method that's introduced in the OS newer than the target OS is called, a
+-Wunguarded-availability warning is emitted if that call is not guarded:
+
+.. code-block:: objc
+
+  void my_fun(NSSomeClass* var) {
+// If fancyNewMethod was added in e.g. macOS 10.12, but the code is
+// built with -mmacosx-version-min=10.11, then this unconditional call
+// will emit a -Wunguarded-availability warning:
+[var fancyNewMethod];
+  }
+
+To fix the warning and to avoid the crash on macOS 10.11, wrap it in
+``if(@available())``:
+
+.. code-block:: objc
+
+  void my_fun(NSSomeClass* var) {
+if (@available(macOS 10.12, *)) {
+  [var fancyNewMethod];
+} else {
+  // Put fallback behavior for old macOS versions (and for non-mac
+  // platforms) here.
+}
+  }
+
+The ``*`` is required and means that platforms not explicitly listed will take
+the true branch, and the compiler will emit ``-Wunguarded-availability``
+warnings for unlisted platforms based on those platform's deployment target.
+More than one platform can be listed in ``@available()``:
+
+.. code-block:: objc
+
+  void my_fun(NSSomeClass* var) {
+if (@available(macOS 10.12, iOS 10, *)) {
+  [var fancyNewMethod];
+}
+  }
+
+If the caller of ``my_fun()`` already checks that ``my_fun()`` is only called
+on 10.12, then add an `availability attribute
+`_ to it,
+which will also suppress the warning and require that calls to my_fun() are
+checked:
+
+.. code-block:: objc
+
+  API_AVAILABLE(macos(10.12)) void my_fun(NSSomeClass* var) {
+[var fancyNewMethod];  // Now ok.
+  }
+
+``@available()`` is only available in Objective-C code.  To use the feature
+in C and C++ code, use the ``__builtin_available()`` spelling instead.
+
+If existing code uses null checks or ``-respondsToSelector:``, it should
+be changed to use ``@available()`` (or ``__builtin_available``) instead.
+
+``-Wunguarded-availability`` is disabled by default, but
+``-Wunguarded-availability-new``, which only emits this warning for APIs
+that have been introduced in macOS >= 10.13, iOS >= 11, watchOS >= 4 and
+tvOS >= 11, is enabled by default.
+
+.. _langext-overloading:
 
 Objective-C++ ABI: protocol-qualifier mangling of parameters
 
@@ -1287,8 +1368,6 @@ parameters of protocol-qualified type.
 Query the presence of this new mangling with
 ``__has_feature(objc_protocol_qualifier_mangling)``.
 
-.. _langext-overloading:
-
 Initializer lists for complex numbers in C
 ==
 

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=308044=308043=308044=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Fri Jul 14 11:40:52 2017
@@ -910,13 +910,13 @@ the function declaration for a hypotheti
 
   void f(void) 
__attribute__((availability(macos,introduced=10.4,deprecated=10.6,obsoleted=10.7)));
 

r308043 - Prevent ClangTools from generating dependency files.

2017-07-14 Thread Sterling Augustine via cfe-commits
Author: saugustine
Date: Fri Jul 14 11:33:30 2017
New Revision: 308043

URL: http://llvm.org/viewvc/llvm-project?rev=308043=rev
Log:
Prevent ClangTools from generating dependency files.

D34304 created a way for ToolInvocations to conditionally generate
dependency files, and updated call sites to preserve the old behavior
of not generating them by default. CompilerInvocations...

Summary:
...are yet another
call-path that needs updating to preserve the old behavior.

Reviewers: klimek, echristo

Reviewed By: echristo

Subscribers: echristo, cfe-commits

Differential Revision: https://reviews.llvm.org/D35131

Modified:
cfe/trunk/lib/Tooling/Tooling.cpp

Modified: cfe/trunk/lib/Tooling/Tooling.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=308043=308042=308043=diff
==
--- cfe/trunk/lib/Tooling/Tooling.cpp (original)
+++ cfe/trunk/lib/Tooling/Tooling.cpp Fri Jul 14 11:33:30 2017
@@ -336,6 +336,7 @@ ClangTool::ClangTool(const CompilationDa
   OverlayFileSystem->pushOverlay(InMemoryFileSystem);
   appendArgumentsAdjuster(getClangStripOutputAdjuster());
   appendArgumentsAdjuster(getClangSyntaxOnlyAdjuster());
+  appendArgumentsAdjuster(getClangStripDependencyFileAdjuster());
 }
 
 ClangTool::~ClangTool() {}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35131: Prevent ClangTools from generating dependency files.D34304 created a way for ToolInvocations to conditionally generatedependency files, and updated call sites to preserve the old behav

2017-07-14 Thread Eric Christopher via Phabricator via cfe-commits
echristo accepted this revision.
echristo added a comment.
This revision is now accepted and ready to land.

This sort of thing seems obvious in the future :)

-eric


https://reviews.llvm.org/D35131



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308041 - [Dominators] Update Clang's DominatorTree to use the new template argument

2017-07-14 Thread Jakub Kuderski via cfe-commits
Author: kuhar
Date: Fri Jul 14 11:26:21 2017
New Revision: 308041

URL: http://llvm.org/viewvc/llvm-project?rev=308041=rev
Log:
[Dominators] Update Clang's DominatorTree to use the new template argument

Summary: This patch makes the Clang's DominatorTree use the new IsPostDom 
template argument for DominatorTreeBase.

Reviewers: dberlin, sanjoy, davide, grosser

Reviewed By: dberlin

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D35316

Modified:
cfe/trunk/include/clang/Analysis/Analyses/Dominators.h

Modified: cfe/trunk/include/clang/Analysis/Analyses/Dominators.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/Dominators.h?rev=308041=308040=308041=diff
==
--- cfe/trunk/include/clang/Analysis/Analyses/Dominators.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/Dominators.h Fri Jul 14 11:26:21 
2017
@@ -38,15 +38,15 @@ typedef llvm::DomTreeNodeBase
 class DominatorTree : public ManagedAnalysis {
   virtual void anchor();
 public:
-  llvm::DominatorTreeBase* DT;
+  llvm::DomTreeBase* DT;
 
   DominatorTree() {
-DT = new llvm::DominatorTreeBase(false);
+DT = new llvm::DomTreeBase();
   }
 
   ~DominatorTree() override { delete DT; }
 
-  llvm::DominatorTreeBase& getBase() { return *DT; }
+  llvm::DomTreeBase& getBase() { return *DT; }
 
   /// \brief This method returns the root CFGBlock of the dominators tree.
   ///


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35427: [clang] Fix handling of "%zd" format specifier

2017-07-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added inline comments.



Comment at: lib/Analysis/PrintfFormatString.cpp:539
   case LengthModifier::AsSizeT:
 return ArgType(); // FIXME: ssize_t
   case LengthModifier::AsPtrDiff:

What about here?


Repository:
  rL LLVM

https://reviews.llvm.org/D35427



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35426: [clang] Add abi-breaking-checks support to clang

2017-07-14 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

The test clang/test/Rewriter/objc-modern-metadata-visibility2.mm is listed as 
UNSUPPORTED since the test contains REQUIRES:abi-breaking-checks but clang does 
not support this yet.


https://reviews.llvm.org/D35426



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35427: [clang] Fix handling of "%zd" format specifier

2017-07-14 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexshap created this revision.

This diff addresses FIXME in lib/Analysis/PrintfFormatString.cpp
and makes Clang warn on incorrect using of "%zd" format specifier.

Test plan: make check-all


Repository:
  rL LLVM

https://reviews.llvm.org/D35427

Files:
  lib/Analysis/PrintfFormatString.cpp
  test/FixIt/format.m


Index: test/FixIt/format.m
===
--- test/FixIt/format.m
+++ test/FixIt/format.m
@@ -229,6 +229,13 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld"
 }
 
+void testSizeTypes() {
+  printf("%zu", 0.f); // expected-warning{{format specifies type 'size_t' (aka 
'unsigned long') but the argument has type 'float'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+  printf("%zd", 0.f); // expected-warning{{format specifies type 'ssize_t' 
(aka 'long') but the argument has type 'float'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+}
+
 void testEnum() {
   typedef enum {
 ImplicitA = 1,
Index: lib/Analysis/PrintfFormatString.cpp
===
--- lib/Analysis/PrintfFormatString.cpp
+++ lib/Analysis/PrintfFormatString.cpp
@@ -466,8 +466,7 @@
   case LengthModifier::AsIntMax:
 return ArgType(Ctx.getIntMaxType(), "intmax_t");
   case LengthModifier::AsSizeT:
-// FIXME: How to get the corresponding signed version of size_t?
-return ArgType();
+return ArgType(Ctx.getSignedSizeType(), "ssize_t");
   case LengthModifier::AsInt3264:
 return Ctx.getTargetInfo().getTriple().isArch64Bit()
? ArgType(Ctx.LongLongTy, "__int64")


Index: test/FixIt/format.m
===
--- test/FixIt/format.m
+++ test/FixIt/format.m
@@ -229,6 +229,13 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld"
 }
 
+void testSizeTypes() {
+  printf("%zu", 0.f); // expected-warning{{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'float'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+  printf("%zd", 0.f); // expected-warning{{format specifies type 'ssize_t' (aka 'long') but the argument has type 'float'}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+}
+
 void testEnum() {
   typedef enum {
 ImplicitA = 1,
Index: lib/Analysis/PrintfFormatString.cpp
===
--- lib/Analysis/PrintfFormatString.cpp
+++ lib/Analysis/PrintfFormatString.cpp
@@ -466,8 +466,7 @@
   case LengthModifier::AsIntMax:
 return ArgType(Ctx.getIntMaxType(), "intmax_t");
   case LengthModifier::AsSizeT:
-// FIXME: How to get the corresponding signed version of size_t?
-return ArgType();
+return ArgType(Ctx.getSignedSizeType(), "ssize_t");
   case LengthModifier::AsInt3264:
 return Ctx.getTargetInfo().getTriple().isArch64Bit()
? ArgType(Ctx.LongLongTy, "__int64")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35426: [clang] Add abi-breaking-checks support to clang

2017-07-14 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang created this revision.

You can now use REQUIRES:abi-breaking-checks in clang too


https://reviews.llvm.org/D35426

Files:
  test/lit.cfg
  test/lit.site.cfg.in


Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -24,6 +24,7 @@
 config.enable_shared = @ENABLE_SHARED@
 config.enable_backtrace = @ENABLE_BACKTRACES@
 config.host_arch = "@HOST_ARCH@"
+config.enable_abi_breaking_checks = "@LLVM_ENABLE_ABI_BREAKING_CHECKS@"
 
 # Support substitution of the tools and libs dirs with user parameters. This is
 # used when we can't determine the tool dir at configuration time.
Index: test/lit.cfg
===
--- test/lit.cfg
+++ test/lit.cfg
@@ -532,3 +532,6 @@
 macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
 if macOSSDKVersion is not None:
 config.available_features.add('macos-sdk-' + macOSSDKVersion)
+
+if config.enable_abi_breaking_checks == "1":
+config.available_features.add('abi-breaking-checks')


Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -24,6 +24,7 @@
 config.enable_shared = @ENABLE_SHARED@
 config.enable_backtrace = @ENABLE_BACKTRACES@
 config.host_arch = "@HOST_ARCH@"
+config.enable_abi_breaking_checks = "@LLVM_ENABLE_ABI_BREAKING_CHECKS@"
 
 # Support substitution of the tools and libs dirs with user parameters. This is
 # used when we can't determine the tool dir at configuration time.
Index: test/lit.cfg
===
--- test/lit.cfg
+++ test/lit.cfg
@@ -532,3 +532,6 @@
 macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
 if macOSSDKVersion is not None:
 config.available_features.add('macos-sdk-' + macOSSDKVersion)
+
+if config.enable_abi_breaking_checks == "1":
+config.available_features.add('abi-breaking-checks')
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35337: [Solaris] gcc runtime dropped support for .ctors, switch to .init_array

2017-07-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

Committed in r308038.


https://reviews.llvm.org/D35337



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308038 - Unconditionally use .init_array instead of .ctors on Solaris.

2017-07-14 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Jul 14 10:49:52 2017
New Revision: 308038

URL: http://llvm.org/viewvc/llvm-project?rev=308038=rev
Log:
Unconditionally use .init_array instead of .ctors on Solaris.

Patch by Fedor Sergeev

Modified:
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/lib/Driver/ToolChains/Solaris.cpp
cfe/trunk/lib/Driver/ToolChains/Solaris.h
cfe/trunk/test/Driver/constructors.c

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=308038=308037=308038=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Fri Jul 14 10:49:52 2017
@@ -2471,7 +2471,8 @@ void Generic_ELF::addClangTargetOptions(
(!V.isOlderThan(4, 7, 0) || getTriple().isAndroid())) ||
   getTriple().getOS() == llvm::Triple::NaCl ||
   (getTriple().getVendor() == llvm::Triple::MipsTechnologies &&
-   !getTriple().hasEnvironment());
+   !getTriple().hasEnvironment()) ||
+  getTriple().getOS() == llvm::Triple::Solaris;
 
   if (DriverArgs.hasFlag(options::OPT_fuse_init_array,
  options::OPT_fno_use_init_array, UseInitArrayDefault))

Modified: cfe/trunk/lib/Driver/ToolChains/Solaris.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Solaris.cpp?rev=308038=308037=308038=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Solaris.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Solaris.cpp Fri Jul 14 10:49:52 2017
@@ -126,7 +126,7 @@ void solaris::Linker::ConstructJob(Compi
 
 Solaris::Solaris(const Driver , const llvm::Triple ,
  const ArgList )
-: Generic_GCC(D, Triple, Args) {
+: Generic_ELF(D, Triple, Args) {
 
   GCCInstallation.init(Triple, Args);
 

Modified: cfe/trunk/lib/Driver/ToolChains/Solaris.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Solaris.h?rev=308038=308037=308038=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Solaris.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/Solaris.h Fri Jul 14 10:49:52 2017
@@ -50,7 +50,7 @@ public:
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
+class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_ELF {
 public:
   Solaris(const Driver , const llvm::Triple ,
   const llvm::opt::ArgList );

Modified: cfe/trunk/test/Driver/constructors.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/constructors.c?rev=308038=308037=308038=diff
==
--- cfe/trunk/test/Driver/constructors.c (original)
+++ cfe/trunk/test/Driver/constructors.c Fri Jul 14 10:49:52 2017
@@ -74,3 +74,11 @@
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1   \
 // RUN: -target arm64-none-none-eabi \
 // RUN:   | FileCheck --check-prefix=CHECK-INIT-ARRAY %s
+//
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1\
+// RUN: -target sparc-sun-solaris2.11 \
+// RUN:   | FileCheck --check-prefix=CHECK-INIT-ARRAY %s
+//
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1\
+// RUN: -target i386-pc-solaris2.11 \
+// RUN:   | FileCheck --check-prefix=CHECK-INIT-ARRAY %s


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35337: [Solaris] gcc runtime dropped support for .ctors, switch to .init_array

2017-07-14 Thread Fedor Sergeev via Phabricator via cfe-commits
fedor.sergeev added a comment.

Can anybody commit this for me, please? :-/


https://reviews.llvm.org/D35337



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308037 - [clang] Add getSignedSizeType method

2017-07-14 Thread Alexander Shaposhnikov via cfe-commits
Author: alexshap
Date: Fri Jul 14 10:30:14 2017
New Revision: 308037

URL: http://llvm.org/viewvc/llvm-project?rev=308037=rev
Log:
[clang] Add getSignedSizeType method

C11 standard refers to the signed counterpart of the type size_t in
the paragraph 7.21.6.1 where it defines d, i, o, u, x, or x conversion 
specifiers
(in printf format string).
In Clang there is a FIXME (in lib/Analysis/PrintfFormatString.cpp) for this case
(which is not handled correctly at the moment).
This diff adds getSignedSizeType method to TargetInfo and exposes it 
in ASTContext similarly to how it is done for getSizeType.
lib/Analysis/PrintfFormatString.cpp will be changed in a separate commit.

Differential revision: https://reviews.llvm.org/D35378

Test plan: make check-all

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=308037=308036=308037=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Jul 14 10:30:14 2017
@@ -1441,6 +1441,10 @@ public:
   /// The sizeof operator requires this (C99 6.5.3.4p4).
   CanQualType getSizeType() const;
 
+  /// \brief Return the unique signed counterpart of 
+  /// the integer type corresponding to size_t.
+  CanQualType getSignedSizeType() const;
+
   /// \brief Return the unique type for "intmax_t" (C99 7.18.1.5), defined in
   /// .
   CanQualType getIntMaxType() const;

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=308037=308036=308037=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Jul 14 10:30:14 2017
@@ -226,6 +226,20 @@ protected:
 
 public:
   IntType getSizeType() const { return SizeType; }
+  IntType getSignedSizeType() const {
+switch (SizeType) {
+case UnsignedShort:
+  return SignedShort;
+case UnsignedInt:
+  return SignedInt;
+case UnsignedLong:
+  return SignedLong;
+case UnsignedLongLong:
+  return SignedLongLong;
+default:
+  llvm_unreachable("Invalid SizeType");
+}
+  }
   IntType getIntMaxType() const { return IntMaxType; }
   IntType getUIntMaxType() const {
 return getCorrespondingUnsignedType(IntMaxType);

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=308037=308036=308037=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Jul 14 10:30:14 2017
@@ -4525,6 +4525,12 @@ CanQualType ASTContext::getSizeType() co
   return getFromTargetType(Target->getSizeType());
 }
 
+/// Return the unique signed counterpart of the integer type 
+/// corresponding to size_t.
+CanQualType ASTContext::getSignedSizeType() const {
+  return getFromTargetType(Target->getSignedSizeType());
+}
+
 /// getIntMaxType - Return the unique type for "intmax_t" (C99 7.18.1.5).
 CanQualType ASTContext::getIntMaxType() const {
   return getFromTargetType(Target->getIntMaxType());


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35378: [clang] Add getSignedSizeType method

2017-07-14 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308037: [clang] Add getSignedSizeType method (authored by 
alexshap).

Changed prior to commit:
  https://reviews.llvm.org/D35378?vs=106496=106662#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35378

Files:
  cfe/trunk/include/clang/AST/ASTContext.h
  cfe/trunk/include/clang/Basic/TargetInfo.h
  cfe/trunk/lib/AST/ASTContext.cpp


Index: cfe/trunk/include/clang/AST/ASTContext.h
===
--- cfe/trunk/include/clang/AST/ASTContext.h
+++ cfe/trunk/include/clang/AST/ASTContext.h
@@ -1441,6 +1441,10 @@
   /// The sizeof operator requires this (C99 6.5.3.4p4).
   CanQualType getSizeType() const;
 
+  /// \brief Return the unique signed counterpart of 
+  /// the integer type corresponding to size_t.
+  CanQualType getSignedSizeType() const;
+
   /// \brief Return the unique type for "intmax_t" (C99 7.18.1.5), defined in
   /// .
   CanQualType getIntMaxType() const;
Index: cfe/trunk/include/clang/Basic/TargetInfo.h
===
--- cfe/trunk/include/clang/Basic/TargetInfo.h
+++ cfe/trunk/include/clang/Basic/TargetInfo.h
@@ -226,6 +226,20 @@
 
 public:
   IntType getSizeType() const { return SizeType; }
+  IntType getSignedSizeType() const {
+switch (SizeType) {
+case UnsignedShort:
+  return SignedShort;
+case UnsignedInt:
+  return SignedInt;
+case UnsignedLong:
+  return SignedLong;
+case UnsignedLongLong:
+  return SignedLongLong;
+default:
+  llvm_unreachable("Invalid SizeType");
+}
+  }
   IntType getIntMaxType() const { return IntMaxType; }
   IntType getUIntMaxType() const {
 return getCorrespondingUnsignedType(IntMaxType);
Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -4525,6 +4525,12 @@
   return getFromTargetType(Target->getSizeType());
 }
 
+/// Return the unique signed counterpart of the integer type 
+/// corresponding to size_t.
+CanQualType ASTContext::getSignedSizeType() const {
+  return getFromTargetType(Target->getSignedSizeType());
+}
+
 /// getIntMaxType - Return the unique type for "intmax_t" (C99 7.18.1.5).
 CanQualType ASTContext::getIntMaxType() const {
   return getFromTargetType(Target->getIntMaxType());


Index: cfe/trunk/include/clang/AST/ASTContext.h
===
--- cfe/trunk/include/clang/AST/ASTContext.h
+++ cfe/trunk/include/clang/AST/ASTContext.h
@@ -1441,6 +1441,10 @@
   /// The sizeof operator requires this (C99 6.5.3.4p4).
   CanQualType getSizeType() const;
 
+  /// \brief Return the unique signed counterpart of 
+  /// the integer type corresponding to size_t.
+  CanQualType getSignedSizeType() const;
+
   /// \brief Return the unique type for "intmax_t" (C99 7.18.1.5), defined in
   /// .
   CanQualType getIntMaxType() const;
Index: cfe/trunk/include/clang/Basic/TargetInfo.h
===
--- cfe/trunk/include/clang/Basic/TargetInfo.h
+++ cfe/trunk/include/clang/Basic/TargetInfo.h
@@ -226,6 +226,20 @@
 
 public:
   IntType getSizeType() const { return SizeType; }
+  IntType getSignedSizeType() const {
+switch (SizeType) {
+case UnsignedShort:
+  return SignedShort;
+case UnsignedInt:
+  return SignedInt;
+case UnsignedLong:
+  return SignedLong;
+case UnsignedLongLong:
+  return SignedLongLong;
+default:
+  llvm_unreachable("Invalid SizeType");
+}
+  }
   IntType getIntMaxType() const { return IntMaxType; }
   IntType getUIntMaxType() const {
 return getCorrespondingUnsignedType(IntMaxType);
Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -4525,6 +4525,12 @@
   return getFromTargetType(Target->getSizeType());
 }
 
+/// Return the unique signed counterpart of the integer type 
+/// corresponding to size_t.
+CanQualType ASTContext::getSignedSizeType() const {
+  return getFromTargetType(Target->getSignedSizeType());
+}
+
 /// getIntMaxType - Return the unique type for "intmax_t" (C99 7.18.1.5).
 CanQualType ASTContext::getIntMaxType() const {
   return getFromTargetType(Target->getIntMaxType());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-07-14 Thread wangxin via Phabricator via cfe-commits
wangxindsb updated this revision to Diff 106654.
wangxindsb marked an inline comment as done.
wangxindsb added a comment.

- Change two maps to one map.
- Move the declarations of PSM and SVB after the next early return.
- Delete the variable std::string DeclName.
- Delete last return in reportbug().


https://reviews.llvm.org/D34275

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  test/Analysis/virtualcall.cpp

Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -1,79 +1,43 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
-/* When INTERPROCEDURAL is set, we expect diagnostics in all functions reachable
-   from a constructor or destructor. If it is not set, we expect diagnostics
-   only in the constructor or destructor.
-
-   When PUREONLY is set, we expect diagnostics only for calls to pure virtual
-   functions not to non-pure virtual functions.
-*/
+// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
 class A {
 public:
   A();
-  A(int i);
 
   ~A() {};
   
-  virtual int foo() = 0; // from Sema: expected-note {{'foo' declared here}}
-  virtual void bar() = 0;
+  virtual int foo()=0;
+  virtual void bar()=0;
   void f() {
 foo();
-#if INTERPROCEDURAL
-// expected-warning-re@-2 ^}}Call Path : foo <-- fCall to pure virtual function during construction has undefined behavior}}
-#endif
+// expected-warning:Call to virtual function during construction
   }
 };
 
 class B : public A {
 public:
   B() {
 foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-// expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-// expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
-
+// expected-warning:Call to virtual function during construction
   }
   ~B();
   
   virtual int foo();
   virtual void bar() { foo(); }
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : foo <-- barCall to virtual function during destruction will not dispatch to derived class}}
-#endif
+  // expected-warning:Call to virtual function during destruction
 };
 
 A::A() {
   f();
 }
 
-A::A(int i) {
-  foo(); // From Sema: expected-warning {{call to pure virtual member function 'foo' has undefined behavior}}
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : fooCall to pure virtual function during construction has undefined behavior}}
-#else
-  // expected-warning-re@-4 ^}}Call to pure virtual function during construction has undefined behavior}}
-#endif
-}
-
 B::~B() {
   this->B::foo(); // no-warning
   this->B::bar();
   this->foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during destruction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during destruction will not dispatch to derived class}}
-#endif
-#endif
-
+  // expected-warning:Call to virtual function during destruction
 }
 
 class C : public B {
@@ -87,13 +51,7 @@
 
 C::C() {
   f(foo());
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 class D : public B {
@@ -103,7 +61,8 @@
   }
   ~D() { bar(); }
   int foo() final;
-  void bar() final { foo(); } // no-warning
+  void bar() final { foo(); } 
+  // no-warning
 };
 
 class E final : public B {
@@ -115,7 +74,6 @@
   int foo() override;
 };
 
-// Regression test: don't crash when there's no direct callee.
 class F {
 public:
   F() {
@@ -125,17 +83,103 @@
   void foo();
 };
 
-int main() {
-  A *a;
-  B *b;
-  C *c;
-  D *d;
-  E *e;
-  F *f;
+class G {
+public:
+  G() {}
+  virtual void bar();
+  void foo() {
+bar();
+  // no warning
+  }
+};
+
+class H{
+public:
+  H() : initState(0) { init(); }
+  int initState;
+  virtual void f() const;
+  void init() {
+

[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-07-14 Thread wangxin via Phabricator via cfe-commits
wangxindsb marked 5 inline comments as done.
wangxindsb added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp:72
+REGISTER_MAP_WITH_PROGRAMSTATE(CtorMap, const MemRegion *, bool)
+REGISTER_MAP_WITH_PROGRAMSTATE(DtorMap, const MemRegion *, bool)
+

xazax.hun wrote:
> I was wondering if there is another way to represent the state.
> We could have a two element (bool based) enum class like:
> ```
> enum class ObjectState : bool {
>   CtorCalled,
>   DtorCalled
> };
> ```
> 
> Se we could have only one map in the GDM. Either the destructor is called for 
> an object or the constructor.  Or in case none of them is called on a path, 
> the state is empty. What do you think? 
> 
Yes, it's better than the previous two maps.


https://reviews.llvm.org/D34275



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35379: Add documentation for @available

2017-07-14 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Mostly done, thanks!




Comment at: docs/LanguageExtensions.rst:1274
 
+Objective-C @available
+--

sdy wrote:
> sdy wrote:
> > I think "Objective-C" is redundant, this is already in the ObjC section and 
> > most of the other headers don't start with "Objective-C".
> `@available` should probably be wrapped in backticks.
The one below and the two above start with "Objective-C".



Comment at: docs/LanguageExtensions.rst:1278
+It is possible use the newest SDK but still build a program that can run on
+older macOS and iOS versions, by passing ``-mmacosx-version-info=`` /
+``--miphoneos-version-min=``.

sdy wrote:
> arphaman wrote:
> > Nit: older versions of macOS or iOS
> I thought this flag was `--mmacosx-version-min`?
> Nit: I would remove the comma after "versions".
Nicos-MacBook-Pro:llvm-build thakis$ bin/clang -mmacosx-version-min=10.11 -c 
test.mm
Nicos-MacBook-Pro:llvm-build thakis$ bin/clang --mmacosx-version-min=10.11 -c 
test.mm
clang-3.5: error: unsupported option '--mmacosx-version-min=10.11'

Removed comma.


https://reviews.llvm.org/D35379



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35379: Add documentation for @available

2017-07-14 Thread Nico Weber via Phabricator via cfe-commits
thakis updated this revision to Diff 106652.
thakis marked 3 inline comments as done.
thakis added a comment.

sdy comments


https://reviews.llvm.org/D35379

Files:
  docs/LanguageExtensions.rst
  include/clang/Basic/AttrDocs.td

Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -910,13 +910,13 @@
 
   void f(void) __attribute__((availability(macos,introduced=10.4,deprecated=10.6,obsoleted=10.7)));
 
-The availability attribute states that ``f`` was introduced in Mac OS X 10.4,
-deprecated in Mac OS X 10.6, and obsoleted in Mac OS X 10.7.  This information
+The availability attribute states that ``f`` was introduced in macOS 10.4,
+deprecated in macOS 10.6, and obsoleted in macOS 10.7.  This information
 is used by Clang to determine when it is safe to use ``f``: for example, if
-Clang is instructed to compile code for Mac OS X 10.5, a call to ``f()``
-succeeds.  If Clang is instructed to compile code for Mac OS X 10.6, the call
+Clang is instructed to compile code for macOS 10.5, a call to ``f()``
+succeeds.  If Clang is instructed to compile code for macOS 10.6, the call
 succeeds but Clang emits a warning specifying that the function is deprecated.
-Finally, if Clang is instructed to compile code for Mac OS X 10.7, the call
+Finally, if Clang is instructed to compile code for macOS 10.7, the call
 fails because ``f()`` is no longer available.
 
 The availability attribute is a comma-separated list starting with the
@@ -961,7 +961,7 @@
   command-line arguments.
 
 ``macos``
-  Apple's Mac OS X operating system.  The minimum deployment target is
+  Apple's macOS operating system.  The minimum deployment target is
   specified by the ``-mmacosx-version-min=*version*`` command-line argument.
   ``macosx`` is supported for backward-compatibility reasons, but it is
   deprecated.
@@ -1016,6 +1016,19 @@
   - (id)method __attribute__((availability(macos,introduced=10.5))); // error: this method was available via the base class in 10.4
   @end
   }];
+
+Starting with the macOS 10.12 SDK, the ``API_AVAILABLE`` macro from
+ can simplify the spelling:
+
+.. code-block:: objc
+
+  @interface A
+  - (id)method API_AVAILABLE(macos(10.11)));
+  - (id)otherMethod API_AVAILABLE(macos(10.11), ios(11.0));
+  @end
+
+Also see the documentation for `@available
+`_
 }
 
 def ExternalSourceSymbolDocs : Documentation {
Index: docs/LanguageExtensions.rst
===
--- docs/LanguageExtensions.rst
+++ docs/LanguageExtensions.rst
@@ -1271,7 +1271,88 @@
 Query for these features with ``__has_attribute(ns_consumed)``,
 ``__has_attribute(ns_returns_retained)``, etc.
 
+Objective-C @available
+--
 
+It is possible to use the newest SDK but still build a program that can run on
+older versions of macOS and iOS by passing ``-mmacosx-version-info=`` /
+``--miphoneos-version-min=``.
+
+Before LLVM 5.0, when calling a function that exists only in the OS that's
+newer than the target OS (as determined by the minimum deployment version),
+programmers had to carefully check if the function exists at runtime, using
+null checks for weakly-linked C functions, ``+class`` for Objective-C classes,
+and ``-respondsToSelector:`` or ``+instancesRespondToSelector:`` for
+Objective-C methods.  If such a check was missed, the program would compile
+fine, run fine on newer systems, but crash on older systems.
+
+As of LLVM 5.0, ``-Wunguarded-availability`` uses the `availability attributes
+`_ together
+with the new ``@available()`` keyword to assist with this issue.
+When a method that's introduced in the OS newer than the target OS is called, a
+-Wunguarded-availability warning is emitted if that call is not guarded:
+
+.. code-block:: objc
+
+  void my_fun(NSSomeClass* var) {
+// If fancyNewMethod was added in e.g. macOS 10.12, but the code is
+// built with -mmacosx-version-min=10.11, then this unconditional call
+// will emit a -Wunguarded-availability warning:
+[var fancyNewMethod];
+  }
+
+To fix the warning and to avoid the crash on macOS 10.11, wrap it in
+``if(@available())``:
+
+.. code-block:: objc
+
+  void my_fun(NSSomeClass* var) {
+if (@available(macOS 10.12, *)) {
+  [var fancyNewMethod];
+} else {
+  // Put fallback behavior for old macOS versions (and for non-mac
+  // platforms) here.
+}
+  }
+
+The ``*`` is required and means that platforms not explicitly listed will take
+the true branch, and the compiler will emit ``-Wunguarded-availability``
+warnings for unlisted platforms based on those platform's deployment target.
+More than one platform can be listed in ``@available()``:
+
+.. code-block:: objc
+
+  void my_fun(NSSomeClass* var) {
+

[PATCH] D35379: Add documentation for @available

2017-07-14 Thread Sidney San Martín via Phabricator via cfe-commits
sdy added inline comments.



Comment at: docs/LanguageExtensions.rst:1274
 
+Objective-C @available
+--

I think "Objective-C" is redundant, this is already in the ObjC section and 
most of the other headers don't start with "Objective-C".



Comment at: docs/LanguageExtensions.rst:1274
 
+Objective-C @available
+--

sdy wrote:
> I think "Objective-C" is redundant, this is already in the ObjC section and 
> most of the other headers don't start with "Objective-C".
`@available` should probably be wrapped in backticks.



Comment at: docs/LanguageExtensions.rst:1278
+It is possible use the newest SDK but still build a program that can run on
+older macOS and iOS versions, by passing ``-mmacosx-version-info=`` /
+``--miphoneos-version-min=``.

arphaman wrote:
> Nit: older versions of macOS or iOS
I thought this flag was `--mmacosx-version-min`?
Nit: I would remove the comma after "versions".



Comment at: docs/LanguageExtensions.rst:1317
+
+The ``*`` means that platforms not explicitly listed will take the true branch,
+and the compiler will emit ``-Wunguarded-availability`` warnings for unlisted

I would say "The * **is required** and means…"



Comment at: docs/LanguageExtensions.rst:1331
+If the caller of ``my_fun()`` already checks that ``my_fun()`` is only called
+on 10.12, then add an `availability attributes
+`_ to it,

attributes ➔ attribute



Comment at: docs/LanguageExtensions.rst:1333
+`_ to it,
+which will also suppress the warning:
+

Maybe something like "…which will suppress the warning and require that calls 
to `my_fun()` are checked."


https://reviews.llvm.org/D35379



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35379: Add documentation for @available

2017-07-14 Thread Nico Weber via Phabricator via cfe-commits
thakis updated this revision to Diff 106650.
thakis marked an inline comment as done.
thakis added a comment.

arphaman comments


https://reviews.llvm.org/D35379

Files:
  docs/LanguageExtensions.rst
  include/clang/Basic/AttrDocs.td

Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -910,13 +910,13 @@
 
   void f(void) __attribute__((availability(macos,introduced=10.4,deprecated=10.6,obsoleted=10.7)));
 
-The availability attribute states that ``f`` was introduced in Mac OS X 10.4,
-deprecated in Mac OS X 10.6, and obsoleted in Mac OS X 10.7.  This information
+The availability attribute states that ``f`` was introduced in macOS 10.4,
+deprecated in macOS 10.6, and obsoleted in macOS 10.7.  This information
 is used by Clang to determine when it is safe to use ``f``: for example, if
-Clang is instructed to compile code for Mac OS X 10.5, a call to ``f()``
-succeeds.  If Clang is instructed to compile code for Mac OS X 10.6, the call
+Clang is instructed to compile code for macOS 10.5, a call to ``f()``
+succeeds.  If Clang is instructed to compile code for macOS 10.6, the call
 succeeds but Clang emits a warning specifying that the function is deprecated.
-Finally, if Clang is instructed to compile code for Mac OS X 10.7, the call
+Finally, if Clang is instructed to compile code for macOS 10.7, the call
 fails because ``f()`` is no longer available.
 
 The availability attribute is a comma-separated list starting with the
@@ -961,7 +961,7 @@
   command-line arguments.
 
 ``macos``
-  Apple's Mac OS X operating system.  The minimum deployment target is
+  Apple's macOS operating system.  The minimum deployment target is
   specified by the ``-mmacosx-version-min=*version*`` command-line argument.
   ``macosx`` is supported for backward-compatibility reasons, but it is
   deprecated.
@@ -1016,6 +1016,19 @@
   - (id)method __attribute__((availability(macos,introduced=10.5))); // error: this method was available via the base class in 10.4
   @end
   }];
+
+Starting with the macOS 10.12 SDK, the ``API_AVAILABLE`` macro from
+ can simplify the spelling:
+
+.. code-block:: objc
+
+  @interface A
+  - (id)method API_AVAILABLE(macos(10.11)));
+  - (id)otherMethod API_AVAILABLE(macos(10.11), ios(11.0));
+  @end
+
+Also see the documentation for `@available
+`_
 }
 
 def ExternalSourceSymbolDocs : Documentation {
Index: docs/LanguageExtensions.rst
===
--- docs/LanguageExtensions.rst
+++ docs/LanguageExtensions.rst
@@ -1271,7 +1271,87 @@
 Query for these features with ``__has_attribute(ns_consumed)``,
 ``__has_attribute(ns_returns_retained)``, etc.
 
+Objective-C @available
+--
 
+It is possible to use the newest SDK but still build a program that can run on
+older versions of macOS and iOS, by passing ``-mmacosx-version-info=`` /
+``--miphoneos-version-min=``.
+
+Before LLVM 5.0, when calling a function that exists only in the OS that's
+newer than the target OS (as determined by the minimum deployment version),
+programmers had to carefully check if the function exists at runtime, using
+null checks for weakly-linked C functions, ``+class`` for Objective-C classes,
+and ``-respondsToSelector:`` or ``+instancesRespondToSelector:`` for
+Objective-C methods.  If such a check was missed, the program would compile
+fine, run fine on newer systems, but crash on older systems.
+
+As of LLVM 5.0, ``-Wunguarded-availability`` uses the `availability attributes
+`_ together
+with the new ``@available()`` keyword to assist with this issue.
+When a method that's introduced in the OS newer than the target OS is called, a
+-Wunguarded-availability warning is emitted if that call is not guarded:
+
+.. code-block:: objc
+
+  void my_fun(NSSomeClass* var) {
+// If fancyNewMethod was added in e.g. macOS 10.12, but the code is
+// built with -mmacosx-version-min=10.11, then this unconditional call
+// will emit a -Wunguarded-availability warning:
+[var fancyNewMethod];
+  }
+
+To fix the warning and to avoid the crash on macOS 10.11, wrap it in
+``if(@available())``:
+
+.. code-block:: objc
+
+  void my_fun(NSSomeClass* var) {
+if (@available(macOS 10.12, *)) {
+  [var fancyNewMethod];
+} else {
+  // Put fallback behavior for old macOS versions (and for non-mac
+  // platforms) here.
+}
+  }
+
+The ``*`` means that platforms not explicitly listed will take the true branch,
+and the compiler will emit ``-Wunguarded-availability`` warnings for unlisted
+platforms based on those platform's deployment target.  More than one platform
+can be listed in ``@available()``:
+
+.. code-block:: objc
+
+  void my_fun(NSSomeClass* var) {
+if 

[PATCH] D35379: Add documentation for @available

2017-07-14 Thread Nico Weber via Phabricator via cfe-commits
thakis marked 7 inline comments as done.
thakis added a comment.

Thanks, all done, much better!




Comment at: docs/LanguageExtensions.rst:1347
+
+In rare cases, the availability annotation on an API might be overly
+conservative.  For example, ``[NSProcessInfo processInfo]`` secretly responds 
to

arphaman wrote:
> We don't want to encourage usage of undocumented/private APIs before they are 
> officially made public for a number of reasons. Can you please remove or 
> rewrite this paragraph (ideally removing/replacing the specific example)?
I removed it from this patch, but this is something that's necessary every now 
and then. If there's no guidance on this, chances are people will come up with 
worse hacks :-) So I think having some documentation on this is a good thing. 
Once this is in, I'll send out a follow-up and we can iterate on this paragraph 
there (or decide to omit it and let each project decide on what to do here.)


https://reviews.llvm.org/D35379



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308035 - [Hexagon] Add intrinsics for data cache operations

2017-07-14 Thread Krzysztof Parzyszek via cfe-commits
Author: kparzysz
Date: Fri Jul 14 09:01:24 2017
New Revision: 308035

URL: http://llvm.org/viewvc/llvm-project?rev=308035=rev
Log:
[Hexagon] Add intrinsics for data cache operations

This is the clang part, adding support for
  void __builtin_HEXAGON_Y2_dccleana(void*);
  void __builtin_HEXAGON_Y2_dccleaninva(void*);
  void __builtin_HEXAGON_Y2_dcinva(void*);
  void __builtin_HEXAGON_Y2_dczeroa(void*);
  void __builtin_HEXAGON_Y4_l2fetch(void*, unsigned);
  void __builtin_HEXAGON_Y5_l2fetch(void*, unsigned long long);
Requires r308032.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsHexagon.def
cfe/trunk/test/CodeGen/builtins-hexagon.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsHexagon.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsHexagon.def?rev=308035=308034=308035=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsHexagon.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsHexagon.def Fri Jul 14 09:01:24 2017
@@ -882,6 +882,12 @@ BUILTIN(__builtin_HEXAGON_S2_ct0p,"iLLi"
 BUILTIN(__builtin_HEXAGON_S2_ct1p,"iLLi","")
 BUILTIN(__builtin_HEXAGON_S2_interleave,"LLiLLi","")
 BUILTIN(__builtin_HEXAGON_S2_deinterleave,"LLiLLi","")
+BUILTIN(__builtin_HEXAGON_Y2_dccleana,"vv*","")
+BUILTIN(__builtin_HEXAGON_Y2_dccleaninva,"vv*","")
+BUILTIN(__builtin_HEXAGON_Y2_dcinva,"vv*","")
+BUILTIN(__builtin_HEXAGON_Y2_dczeroa,"vv*","")
+BUILTIN(__builtin_HEXAGON_Y4_l2fetch,"vv*Ui","")
+BUILTIN(__builtin_HEXAGON_Y5_l2fetch,"vv*LLUi","")
 
 BUILTIN(__builtin_HEXAGON_S6_rol_i_r,"iii","v:60:")
 BUILTIN(__builtin_HEXAGON_S6_rol_i_p,"LLiLLii","v:60:")

Modified: cfe/trunk/test/CodeGen/builtins-hexagon.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-hexagon.c?rev=308035=308034=308035=diff
==
--- cfe/trunk/test/CodeGen/builtins-hexagon.c (original)
+++ cfe/trunk/test/CodeGen/builtins-hexagon.c Fri Jul 14 09:01:24 2017
@@ -2962,4 +2962,16 @@ void foo() {
   // CHECK: @llvm.hexagon.V6.vzh.128B
   __builtin_HEXAGON_V6_vzh(v16);
   // CHECK: @llvm.hexagon.V6.vzh
+  __builtin_HEXAGON_Y2_dccleana(0);
+  // CHECK: @llvm.hexagon.Y2.dccleana
+  __builtin_HEXAGON_Y2_dccleaninva(0);
+  // CHECK: @llvm.hexagon.Y2.dccleaninva
+  __builtin_HEXAGON_Y2_dcinva(0);
+  // CHECK: @llvm.hexagon.Y2.dcinva
+  __builtin_HEXAGON_Y2_dczeroa(0);
+  // CHECK: @llvm.hexagon.Y2.dczeroa
+  __builtin_HEXAGON_Y4_l2fetch(0, 0);
+  // CHECK: @llvm.hexagon.Y4.l2fetch
+  __builtin_HEXAGON_Y5_l2fetch(0, 0);
+  // CHECK: @llvm.hexagon.Y5.l2fetch
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35406: [clangd] Replace ASTUnit with manual AST management.

2017-07-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In https://reviews.llvm.org/D35406#809623, @malaperle wrote:

> For synching with what I am doing. I am "only" looking right now at the 
> modeling of the index and its on-disk storage, not really on the speeding up 
> of the parsing of the TUs (i.e. the input of the index). I use 
> index::IndexDataConsumer to feed the index and I see that in your change it 
> is still pretty much used the same way as before so there is no problem. I 
> will post on the indexing thread from before with a more detailed proposal 
> from before once it is a bit further along.


Great that this change is not interfering. Eager to see your proposal for the 
indexing.


https://reviews.llvm.org/D35406



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35406: [clangd] Replace ASTUnit with manual AST management.

2017-07-14 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

In https://reviews.llvm.org/D35406#809609, @ilya-biryukov wrote:

> The idea is to allows us changing the way we manage/rebuild PCHs and ASTs.
>  ASTUnit is used for many things and has a fairly complicated and verbose 
> interface and does a lot of mutations all other the place inside it, so 
> making changes to it is not particularly easy.
>  On the other hand, it doesn't add a lot of value for clangd specifically, 
> since we use a very simple subset of it.
>
> The next step I planned was to allow code completion to be run in parallel 
> with recomputing preamble/computing diagnostics. (And in general, allow 
> multiple TUs to be processed in parallel).
>  That would probably involve changes to the interface, so we should 
> definitely sync with you on the work you've been doing.
>  And we were also planning to look into indexing at a later point, so 
> discussing the design there might be interesting as well.


Thanks a lot for the additional information.

For synching with what I am doing. I am "only" looking right now at the 
modeling of the index and its on-disk storage, not really on the speeding up of 
the parsing of the TUs (i.e. the input of the index). I use 
index::IndexDataConsumer to feed the index and I see that in your change it is 
still pretty much used the same way as before so there is no problem. I will 
post on the indexing thread from before with a more detailed proposal from 
before once it is a bit further along.


https://reviews.llvm.org/D35406



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35406: [clangd] Replace ASTUnit with manual AST management.

2017-07-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

The idea is to allows us changing the way we manage/rebuild PCHs and ASTs.
ASTUnit is used for many things and has a fairly complicated and verbose 
interface and does a lot of mutations all other the place inside it, so making 
changes to it is not particularly easy.
On the other hand, it doesn't add a lot of value for clangd specifically, since 
we use a very simple subset of it.

The next step I planned was to allow code completion to be run in parallel with 
recomputing preamble/computing diagnostics. (And in general, allow multiple TUs 
to be processed in parallel).
That would probably involve changes to the interface, so we should definitely 
sync with you on the work you've been doing.
And we were also planning to look into indexing at a later point, so discussing 
the design there might be interesting as well.


https://reviews.llvm.org/D35406



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34440: [Clang] Expand response files before loading compilation database

2017-07-14 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D34440#809581, @vladimir.plyashkun wrote:

> > Are there any concerns using the alternative?
>
> I can't say that it's a big problems, but i think that:
>  //CompilationDatabase.json// is more //CMake //specific format. 
>  It can be generated automatically by //CMake//, while other build systems 
> may not do it.
>  So we need to generate it on the fly (by tool or by hand), which also can 
> lead to hidden problems due to different formats, different escaping rules, 
> etc.
>  I think it's always good to have one unified format.


The compilation database is most certainly not cmake specific. We designed it 
in clang, and then implemented it in cmake as an example, because that's the 
most widely used C++ build system we were aware of (aside from autotools, which 
we didn't want to touch :).  There are ways to create it from other build 
systems (ninja has support, and there are tools that provide generic support to 
intercept compiles).
If you want one unified format, the compilation database is it.
If you want special integration with your IDE, btw, I'd suggest you just 
implement your own compilation database (in C++) and make sure tools you 
support link to it.


Repository:
  rL LLVM

https://reviews.llvm.org/D34440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35406: [clangd] Replace ASTUnit with manual AST management.

2017-07-14 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

Could you explain what the goal of this change is? It would help understand how 
it will impact the indexing work I am currently doing.


https://reviews.llvm.org/D35406



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34440: [Clang] Expand response files before loading compilation database

2017-07-14 Thread Vladimir Plyashkun via Phabricator via cfe-commits
vladimir.plyashkun added a comment.

> Are there any concerns using the alternative?

I can't say that it's a big problems, but i think that:
//CompilationDatabase.json// is more //CMake //specific format. 
It can be generated automatically by //CMake//, while other build systems may 
not do it.
So we need to generate it on the fly (by tool or by hand), which also can lead 
to hidden problems due to different formats, different escaping rules, etc.
I think it's always good to have one unified format.


Repository:
  rL LLVM

https://reviews.llvm.org/D34440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34654: Allow passing a regex for headers to exclude from clang-tidy

2017-07-14 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added reviewers: aaron.ballman, alexfh, hokein.
JonasToth added a comment.

i added reviewers, since it seems nobody takes care of this check.
remove if this was bad.


Repository:
  rL LLVM

https://reviews.llvm.org/D34654



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26350: Keep invalid Switch in the AST

2017-07-14 Thread Olivier Goffart via Phabricator via cfe-commits
ogoffart added a comment.

The problem i'm trying to solve is precisely to keep as much as possible of the 
valid AST in the main AST, despite errors.
I've already done some work with r249982, r272962 and more, and there is still 
a lot to do. But the goal is to keep as much as possible of it.

The reason i'm working on this is highlighting of code where some code might be 
potentially invalid (because you are editing it, or because the tool don't have 
access to all headers)
Things like if statement from my previous patch, or switch statement like this 
patch are the things which have the more impact, because not keeping them 
removes highlighting for potentially big blocks of code.

This is useful for example for IDE such as KDevelop which use clang for 
highlighting, or my own tool [code.woboq.org]

A random example is 
https://code.woboq.org/linux/linux/arch/arm/kernel/module.c.html?style=kdevelop#101
(generated with this patch applied.) There are errors because this is an arm 
file built with the option for an intel kernel. Yet, most of the file is 
properly highlighted. If this patch was not applied, the whole switch statement 
would be removed from the AST and nothing within would be hightlighted, only 
because some case label are invalid.


https://reviews.llvm.org/D26350



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-07-14 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp:72
+REGISTER_MAP_WITH_PROGRAMSTATE(CtorMap, const MemRegion *, bool)
+REGISTER_MAP_WITH_PROGRAMSTATE(DtorMap, const MemRegion *, bool)
+

I was wondering if there is another way to represent the state.
We could have a two element (bool based) enum class like:
```
enum class ObjectState : bool {
  CtorCalled,
  DtorCalled
};
```

Se we could have only one map in the GDM. Either the destructor is called for 
an object or the constructor.  Or in case none of them is called on a path, the 
state is empty. What do you think? 




Comment at: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp:86
+  const LocationContext *LCtx = N->getLocationContext();
+  ProgramStateManager  = State->getStateManager();
+  auto  = PSM.getSValBuilder();

You could move the declarations of PSM and SVB after the next early return. 



Comment at: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp:107
+
+  std::string DeclName;
+  std::string InfoText;

You could eliminate this local variable. 



Comment at: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp:169
 
-  // FIXME: The interprocedural diagnostic experience here is not good.
-  // Ultimately this checker should be re-written to be path sensitive.
-  // For now, only diagnose intraprocedurally, by default.
-  if (IsInterprocedural) {
-os << "Call Path : ";
-// Name of current visiting CallExpr.
-os << *CE->getDirectCallee();
-
-// Name of the CallExpr whose body is current being walked.
-if (visitingCallExpr)
-  os << " <-- " << *visitingCallExpr->getDirectCallee();
-// Names of FunctionDecls in worklist with state PostVisited.
-for (SmallVectorImpl::iterator I = WList.end(),
- E = WList.begin(); I != E; --I) {
-  const FunctionDecl *FD = (*(I-1))->getDirectCallee();
-  assert(FD);
-  if (VisitedFunctions[FD] == PostVisited)
-os << " <-- " << *FD;
-}
+  if (IsPureOnly && !MD->isPure())
+return;

These two checks could be moved before you query the CXXThisVal. 



Comment at: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp:247
+  C.emitReport(std::move(Reporter));
+  return;
 }

This return is redundant. 


https://reviews.llvm.org/D34275



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34440: [Clang] Expand response files before loading compilation database

2017-07-14 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D34440#809522, @klimek wrote:

> In https://reviews.llvm.org/D34440#809325, @vladimir.plyashkun wrote:
>
> > Even if i'll change content of //arguments.rsp// to
> >  `-std=c++11 -Ipath/to/include -Ipath/to/include2 -DMACRO `
> >  and will try to call clang-tidy process in this way:
> >  `clang-tidy -checks=* main.cpp -export-fixes=... -- @arguments.rsp`
> >  it also has no effect, because all compiler options will be ignored (i 
> > thinks it's because that //stripPositionalArgs()// function deletes 
> > @arguments.rsp parameter as unused input).
>
>
> Ah, ok: this is definitely the way it should work (adding the response file 
> after the --). I think this is the use case we should fix - probably by 
> fixing stripPositionalArgs?


At which point is `stripPositionalArgs` called? Also (in case we want to 
actually support this use case) should we only allow response files when using 
the fixed compilation database or for any compilation database (I highly doubt 
about the latter)?


Repository:
  rL LLVM

https://reviews.llvm.org/D34440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34440: [Clang] Expand response files before loading compilation database

2017-07-14 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D34440#808156, @vladimir.plyashkun wrote:

> **To discuss:**
>  ...
>  By this moment, we unable to use //CompilationDatabase.json// from //CLion 
> //side which is widely used in //Clang-Tidy// and in other common tools.


It would be interesting to learn more about the reasons why you can't use JSON 
compilation database. In case you don't want to clutter the project's 
directory, you can place the compile_commands.json file elsewhere (in a 
temporary directory, for example) and point clang tools to this directory using 
the `-p` command line flag.

> Anyway, there are possibility to pass compiler options directly through 
> command line.
>  But we cannot pass compiler options directly through command-line, due to 
> command-line-length restrictions.
>  So, we decided to pass compiler options through //@ResponseFile //mechanism.
>  But there are some problems with this approach.
>  Before this patch, ///clang/lib/Tooling/CommonOptionsParser.cpp// worked in 
> this way:
> 
> 1. Load compilation database from command-line
> 2. Expand response files
> 3. Parse all other command line arguments I think it's strange behavior?

I don't think anyone has tried using response files for clang tools before. So 
the behavior here is almost certainly not intended. The other question is what 
would be a good way to handle response files in clang tools and whether we want 
it at all. IIUC, the only use case for response files is to workaround the 
limits on the size of a command line. If so, clang tools have an alternative 
solution - JSON compilation database. Are there any concerns using the 
alternative?


Repository:
  rL LLVM

https://reviews.llvm.org/D34440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35406: [clangd] Replace ASTUnit with manual AST management.

2017-07-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 106632.
ilya-biryukov added a comment.

- Replaced TODO with FIXME in a comment.


https://reviews.llvm.org/D35406

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h

Index: clangd/ClangdUnit.h
===
--- clangd/ClangdUnit.h
+++ clangd/ClangdUnit.h
@@ -13,6 +13,9 @@
 #include "Path.h"
 #include "Protocol.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/PrecompiledPreamble.h"
+#include "clang/Serialization/ASTBitCodes.h"
+#include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include 
 
@@ -70,11 +73,79 @@
   void dumpAST(llvm::raw_ostream ) const;
 
 private:
+  /// Stores and provides access to parsed AST.
+  class ParsedAST {
+  public:
+/// Attempts to run Clang and store parsed AST. If \p Preamble is non-null
+/// it is reused during parsing.
+static llvm::Optional
+Build(std::unique_ptr CI,
+  const PrecompiledPreamble *Preamble,
+  ArrayRef PreambleDeclIDs,
+  std::unique_ptr Buffer,
+  std::shared_ptr PCHs,
+  IntrusiveRefCntPtr VFS);
+
+ParsedAST(ParsedAST &);
+ParsedAST =(ParsedAST &);
+
+~ParsedAST();
+
+ASTContext ();
+const ASTContext () const;
+
+Preprocessor ();
+const Preprocessor () const;
+
+ArrayRef getTopLevelDecls();
+
+const std::vector () const;
+
+  private:
+ParsedAST(std::unique_ptr Clang,
+  std::unique_ptr Action,
+  std::vector TopLevelDecls,
+  std::vector PendingTopLevelDecls,
+  std::vector Diags);
+
+  private:
+void ensurePreambleDeclsDeserialized();
+
+// We store an "incomplete" FrontendAction (i.e. no EndSourceFile was called
+// on it) and CompilerInstance used to run it. That way we don't have to do
+// complex memory management of all Clang structures on our own. (They are
+// stored in CompilerInstance and cleaned up by
+// FrontendAction.EndSourceFile).
+std::unique_ptr Clang;
+std::unique_ptr Action;
+
+// Data, stored after parsing.
+std::vector Diags;
+std::vector TopLevelDecls;
+std::vector PendingTopLevelDecls;
+  };
+
+  // Store Preamble and all associated data
+  struct PreambleData {
+PreambleData(PrecompiledPreamble Preamble,
+ std::vector TopLevelDeclIDs,
+ std::vector Diags);
+
+PrecompiledPreamble Preamble;
+std::vector TopLevelDeclIDs;
+std::vector Diags;
+  };
+
+  SourceLocation getBeginningOfIdentifier(const Position ,
+  const FileEntry *FE) const;
+
   Path FileName;
-  std::unique_ptr Unit;
-  std::shared_ptr PCHs;
+  tooling::CompileCommand Command;
 
-  SourceLocation getBeginningOfIdentifier(const Position& Pos, const FileEntry* FE) const;
+  llvm::Optional Preamble;
+  llvm::Optional Unit;
+
+  std::shared_ptr PCHs;
 };
 
 } // namespace clangd
Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -9,23 +9,215 @@
 
 #include "ClangdUnit.h"
 
-#include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "clang/Frontend/Utils.h"
-#include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexDataConsumer.h"
+#include "clang/Index/IndexingAction.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Sema/Sema.h"
+#include "clang/Serialization/ASTWriter.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Format.h"
 
 #include 
 
 using namespace clang::clangd;
 using namespace clang;
 
+namespace {
+
+class DeclTrackingASTConsumer : public ASTConsumer {
+public:
+  DeclTrackingASTConsumer(std::vector )
+  : TopLevelDecls(TopLevelDecls) {}
+
+  bool HandleTopLevelDecl(DeclGroupRef DG) override {
+for (const Decl *D : DG) {
+  // ObjCMethodDecl are not actually top-level decls.
+  if (isa(D))
+continue;
+
+  TopLevelDecls.push_back(D);
+}
+return true;
+  }
+
+private:
+  std::vector 
+};
+
+class ClangdFrontendAction : public SyntaxOnlyAction {
+public:
+  std::vector takeTopLevelDecls() {
+return std::move(TopLevelDecls);
+  }
+
+protected:
+  std::unique_ptr CreateASTConsumer(CompilerInstance ,
+ StringRef InFile) override {
+return llvm::make_unique(/*ref*/ TopLevelDecls);
+  }
+
+private:
+  std::vector TopLevelDecls;
+};
+
+class ClangdUnitPreambleCallbacks : public PreambleCallbacks {
+public:
+  std::vector 

[PATCH] D34440: [Clang] Expand response files before loading compilation database

2017-07-14 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D34440#809325, @vladimir.plyashkun wrote:

> Even if i'll change content of //arguments.rsp// to
>  `-std=c++11 -Ipath/to/include -Ipath/to/include2 -DMACRO `
>  and will try to call clang-tidy process in this way:
>  `clang-tidy -checks=* main.cpp -export-fixes=... -- @arguments.rsp`
>  it also has no effect, because all compiler options will be ignored (i 
> thinks it's because that //stripPositionalArgs()// function deletes 
> @arguments.rsp parameter as unused input).


Ah, ok: this is definitely the way it should work (adding the response file 
after the --). I think this is the use case we should fix - probably by fixing 
stripPositionalArgs?


Repository:
  rL LLVM

https://reviews.llvm.org/D34440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r308022 - [clang-tidy] Minor documentation fix. NFC.

2017-07-14 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Fri Jul 14 05:31:21 2017
New Revision: 308022

URL: http://llvm.org/viewvc/llvm-project?rev=308022=rev
Log:
[clang-tidy] Minor documentation fix. NFC.

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-undefined-memory-manipulation.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-undefined-memory-manipulation.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-undefined-memory-manipulation.rst?rev=308022=308021=308022=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-undefined-memory-manipulation.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-undefined-memory-manipulation.rst
 Fri Jul 14 05:31:21 2017
@@ -1,7 +1,7 @@
 .. title:: clang-tidy - bugprone-undefined-memory-manipulation
 
 bugprone-undefined-memory-manipulation
-==
+==
 
 Finds calls of memory manipulation functions ``memset()``, ``memcpy()`` and
 ``memmove()`` on not TriviallyCopyable objects resulting in undefined behavior.


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26350: Keep invalid Switch in the AST

2017-07-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

You've explained how you are accomplishing this but not why. I don't think 
Clang typically keeps erroneous AST nodes in the tree. What kind of problem is 
this intended to solve?


https://reviews.llvm.org/D26350



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35110: [Analyzer] Constraint Manager Negates Difference

2017-07-14 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 106627.
baloghadamsoftware added a comment.

Type selection simplified, FIXME added.


https://reviews.llvm.org/D35110

Files:
  lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  test/Analysis/constraint_manager_negate_difference.c
  test/Analysis/ptr-arith.c

Index: test/Analysis/ptr-arith.c
===
--- test/Analysis/ptr-arith.c
+++ test/Analysis/ptr-arith.c
@@ -265,49 +265,26 @@
   clang_analyzer_eval((rhs - lhs) > 0); // expected-warning{{TRUE}}
 }
 
-//---
-// False positives
-//---
-
 void zero_implies_reversed_equal(int *lhs, int *rhs) {
   clang_analyzer_eval((rhs - lhs) == 0); // expected-warning{{UNKNOWN}}
   if ((rhs - lhs) == 0) {
-#ifdef ANALYZER_CM_Z3
 clang_analyzer_eval(rhs != lhs); // expected-warning{{FALSE}}
 clang_analyzer_eval(rhs == lhs); // expected-warning{{TRUE}}
-#else
-clang_analyzer_eval(rhs != lhs); // expected-warning{{UNKNOWN}}
-clang_analyzer_eval(rhs == lhs); // expected-warning{{UNKNOWN}}
-#endif
 return;
   }
   clang_analyzer_eval((rhs - lhs) == 0); // expected-warning{{FALSE}}
-#ifdef ANALYZER_CM_Z3
   clang_analyzer_eval(rhs == lhs); // expected-warning{{FALSE}}
   clang_analyzer_eval(rhs != lhs); // expected-warning{{TRUE}}
-#else
-  clang_analyzer_eval(rhs == lhs); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(rhs != lhs); // expected-warning{{UNKNOWN}}
-#endif
 }
 
 void canonical_equal(int *lhs, int *rhs) {
   clang_analyzer_eval(lhs == rhs); // expected-warning{{UNKNOWN}}
   if (lhs == rhs) {
-#ifdef ANALYZER_CM_Z3
 clang_analyzer_eval(rhs == lhs); // expected-warning{{TRUE}}
-#else
-clang_analyzer_eval(rhs == lhs); // expected-warning{{UNKNOWN}}
-#endif
 return;
   }
   clang_analyzer_eval(lhs == rhs); // expected-warning{{FALSE}}
-
-#ifdef ANALYZER_CM_Z3
   clang_analyzer_eval(rhs == lhs); // expected-warning{{FALSE}}
-#else
-  clang_analyzer_eval(rhs == lhs); // expected-warning{{UNKNOWN}}
-#endif
 }
 
 void compare_element_region_and_base(int *p) {
Index: test/Analysis/constraint_manager_negate_difference.c
===
--- /dev/null
+++ test/Analysis/constraint_manager_negate_difference.c
@@ -0,0 +1,39 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_eval(int);
+
+void equal(int m, int n) {
+  if (m != n)
+return;
+  clang_analyzer_eval(n == m); // expected-warning{{TRUE}}
+}
+
+void non_equal(int m, int n) {
+  if (m == n)
+return;
+  clang_analyzer_eval(n != m); // expected-warning{{TRUE}}
+}
+
+void less_or_equal(int m, int n) {
+  if (m < n)
+return;
+  clang_analyzer_eval(n <= m); // expected-warning{{TRUE}}
+}
+
+void less(int m, int n) {
+  if (m <= n)
+return;
+  clang_analyzer_eval(n < m); // expected-warning{{TRUE}}
+}
+
+void greater_or_equal(int m, int n) {
+  if (m > n)
+return;
+  clang_analyzer_eval(n >= m); // expected-warning{{TRUE}}
+}
+
+void greater(int m, int n) {
+  if (m >= n)
+return;
+  clang_analyzer_eval(n > m); // expected-warning{{TRUE}}
+}
Index: lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -256,6 +256,29 @@
 return newRanges;
   }
 
+  // Turn all [A, B] ranges to [-B, -A]. Turn minimal signed value to maximal
+  // signed value and vice versa.
+  RangeSet Negate(BasicValueFactory , Factory ) const {
+PrimRangeSet newRanges = F.getEmptySet();
+
+for (iterator i = begin(), e = end(); i != e; ++i) {
+  const llvm::APSInt  = i->From(),  = i->To();
+  const llvm::APSInt  = (to.isMinSignedValue() ?
+ BV.getMaxValue(to) :
+ (to.isMaxSignedValue() ?
+  BV.getMinValue(to) :
+  BV.getValue(- to)));
+  const llvm::APSInt  = (from.isMinSignedValue() ?
+   BV.getMaxValue(from) :
+   (from.isMaxSignedValue() ?
+BV.getMinValue(from) :
+BV.getValue(- from)));
+  newRanges = F.add(newRanges, Range(newFrom, newTo));
+}
+
+return newRanges;
+  }
+
   void print(raw_ostream ) const {
 bool isFirst = true;
 os << "{ ";
@@ -465,11 +488,38 @@
   if (ConstraintRangeTy::data_type *V = State->get(Sym))
 return *V;
 
-  // Lazily generate a new RangeSet representing all possible values for the
-  // given symbol type.
+  // If Sym is a difference of symbols A - B, then maybe we have range set
+  // stored for B - A.
   BasicValueFactory  = getBasicVals();
   QualType T = Sym->getType();
 
+  if (const SymSymExpr 

[PATCH] D35109: [Analyzer] SValBuilder Comparison Rearrangement

2017-07-14 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 106626.
baloghadamsoftware added a comment.

Difference of unsigned is converted to signed.


https://reviews.llvm.org/D35109

Files:
  include/clang/AST/ASTContext.h
  lib/AST/ASTContext.cpp
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  test/Analysis/std-c-library-functions.c
  test/Analysis/svalbuilder-rearrange-comparisons.c

Index: test/Analysis/svalbuilder-rearrange-comparisons.c
===
--- /dev/null
+++ test/Analysis/svalbuilder-rearrange-comparisons.c
@@ -0,0 +1,156 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_dump(int x);
+void clang_analyzer_printState();
+
+int f();
+
+void compare_different_symbol() {
+  int x = f(), y = f();
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$5{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$5{int})) == 0}}
+}
+
+void compare_different_symbol_plus_left_int() {
+  int x = f()+1, y = f();
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) + 1}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$5{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$5{int}) - (conj_$2{int})) == 1}}
+}
+
+void compare_different_symbol_minus_left_int() {
+  int x = f()-1, y = f();
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) - 1}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$5{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$5{int})) == 1}}
+}
+
+void compare_different_symbol_plus_right_int() {
+  int x = f(), y = f()+2;
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$5{int}) + 2}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$5{int})) == 2}}
+}
+
+void compare_different_symbol_minus_right_int() {
+  int x = f(), y = f()-2;
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$5{int}) - 2}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$5{int}) - (conj_$2{int})) == 2}}
+}
+
+void compare_different_symbol_plus_left_plus_right_int() {
+  int x = f()+2, y = f()+1;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) + 2}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$5{int}) + 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$5{int}) - (conj_$2{int})) == 1}}
+}
+
+void compare_different_symbol_plus_left_minus_right_int() {
+  int x = f()+2, y = f()-1;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) + 2}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$5{int}) - 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$5{int}) - (conj_$2{int})) == 3}}
+}
+
+void compare_different_symbol_minus_left_plus_right_int() {
+  int x = f()-2, y = f()+1;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) - 2}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$5{int}) + 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$5{int})) == 3}}
+}
+
+void compare_different_symbol_minus_left_minus_right_int() {
+  int x = f()-2, y = f()-1;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) - 2}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$5{int}) - 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$5{int})) == 1}}
+}
+
+void compare_same_symbol() {
+  int x = f(), y = x;
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{1 S32b}}
+}
+
+void compare_same_symbol_plus_left_int() {
+  int x = f(), y = x;
+  ++x;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) + 1}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{0 S32b}}
+}
+
+void compare_same_symbol_minus_left_int() {
+  int x = f(), y = x;
+  --x;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) - 1}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{0 S32b}}
+}
+
+void compare_same_symbol_plus_right_int() {
+  int x = f(), y = x+1;
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$2{int}) + 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{0 S32b}}
+}
+
+void compare_same_symbol_minus_right_int() {
+  int x = f(), y = x-1;
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$2{int}) - 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{0 S32b}}
+}

[PATCH] D35051: [clang-tidy] Add bugprone-undefined-memory-manipulation check.

2017-07-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308021: [clang-tidy] Add 
bugprone-undefined-memory-manipulation check (authored by xazax).

Changed prior to commit:
  https://reviews.llvm.org/D35051?vs=106234=106625#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35051

Files:
  clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
  
clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-undefined-memory-manipulation.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/trunk/test/clang-tidy/bugprone-undefined-memory-manipulation.cpp

Index: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
@@ -3,6 +3,7 @@
 add_clang_library(clangTidyBugproneModule
   BugproneTidyModule.cpp
   SuspiciousMemsetUsageCheck.cpp
+  UndefinedMemoryManipulationCheck.cpp
 
   LINK_LIBS
   clangAnalysis
Index: clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
@@ -0,0 +1,61 @@
+//===--- UndefinedMemoryManipulationCheck.cpp - clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "UndefinedMemoryManipulationCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+namespace {
+AST_MATCHER(CXXRecordDecl, isNotTriviallyCopyable) {
+  return !Node.isTriviallyCopyable();
+}
+} // namespace
+
+void UndefinedMemoryManipulationCheck::registerMatchers(MatchFinder *Finder) {
+  const auto NotTriviallyCopyableObject =
+  hasType(pointsTo(cxxRecordDecl(isNotTriviallyCopyable(;
+
+  // Check whether destination object is not TriviallyCopyable.
+  // Applicable to all three memory manipulation functions.
+  Finder->addMatcher(callExpr(callee(functionDecl(hasAnyName(
+  "::memset", "::memcpy", "::memmove"))),
+  hasArgument(0, NotTriviallyCopyableObject))
+ .bind("dest"),
+ this);
+
+  // Check whether source object is not TriviallyCopyable.
+  // Only applicable to memcpy() and memmove().
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(hasAnyName("::memcpy", "::memmove"))),
+   hasArgument(1, NotTriviallyCopyableObject))
+  .bind("src"),
+  this);
+}
+
+void UndefinedMemoryManipulationCheck::check(
+const MatchFinder::MatchResult ) {
+  if (const auto *Destination = Result.Nodes.getNodeAs("dest")) {
+diag(Destination->getLocStart(), "undefined behavior, destination "
+ "object is not TriviallyCopyable");
+  }
+  if (const auto *Source = Result.Nodes.getNodeAs("src")) {
+diag(Source->getLocStart(), "undefined behavior, source object is not "
+"TriviallyCopyable");
+  }
+}
+
+} // namespace bugprone
+} // namespace tidy
+} // namespace clang
Index: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "SuspiciousMemsetUsageCheck.h"
+#include "UndefinedMemoryManipulationCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -21,6 +22,8 @@
   void addCheckFactories(ClangTidyCheckFactories ) override {
 CheckFactories.registerCheck(
 "bugprone-suspicious-memset-usage");
+CheckFactories.registerCheck(
+"bugprone-undefined-memory-manipulation");
   }
 };
 
Index: clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.h
+++ clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.h
@@ -0,0 

[clang-tools-extra] r308021 - [clang-tidy] Add bugprone-undefined-memory-manipulation check

2017-07-14 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Fri Jul 14 05:20:19 2017
New Revision: 308021

URL: http://llvm.org/viewvc/llvm-project?rev=308021=rev
Log:
[clang-tidy] Add bugprone-undefined-memory-manipulation check

Patch by: Reka Nikolett Kovacs

Differential Revision: https://reviews.llvm.org/D35051

Added:

clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp

clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-undefined-memory-manipulation.rst

clang-tools-extra/trunk/test/clang-tidy/bugprone-undefined-memory-manipulation.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=308021=308020=308021=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Fri Jul 
14 05:20:19 2017
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "SuspiciousMemsetUsageCheck.h"
+#include "UndefinedMemoryManipulationCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -21,6 +22,8 @@ public:
   void addCheckFactories(ClangTidyCheckFactories ) override {
 CheckFactories.registerCheck(
 "bugprone-suspicious-memset-usage");
+CheckFactories.registerCheck(
+"bugprone-undefined-memory-manipulation");
   }
 };
 

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=308021=308020=308021=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Fri Jul 14 
05:20:19 2017
@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS support)
 add_clang_library(clangTidyBugproneModule
   BugproneTidyModule.cpp
   SuspiciousMemsetUsageCheck.cpp
+  UndefinedMemoryManipulationCheck.cpp
 
   LINK_LIBS
   clangAnalysis

Added: 
clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp?rev=308021=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
 (added)
+++ 
clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
 Fri Jul 14 05:20:19 2017
@@ -0,0 +1,61 @@
+//===--- UndefinedMemoryManipulationCheck.cpp - 
clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "UndefinedMemoryManipulationCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+namespace {
+AST_MATCHER(CXXRecordDecl, isNotTriviallyCopyable) {
+  return !Node.isTriviallyCopyable();
+}
+} // namespace
+
+void UndefinedMemoryManipulationCheck::registerMatchers(MatchFinder *Finder) {
+  const auto NotTriviallyCopyableObject =
+  hasType(pointsTo(cxxRecordDecl(isNotTriviallyCopyable(;
+
+  // Check whether destination object is not TriviallyCopyable.
+  // Applicable to all three memory manipulation functions.
+  Finder->addMatcher(callExpr(callee(functionDecl(hasAnyName(
+  "::memset", "::memcpy", "::memmove"))),
+  hasArgument(0, NotTriviallyCopyableObject))
+ .bind("dest"),
+ this);
+
+  // Check whether source object is not TriviallyCopyable.
+  // Only applicable to memcpy() and memmove().
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(hasAnyName("::memcpy", "::memmove"))),
+   hasArgument(1, NotTriviallyCopyableObject))
+  .bind("src"),
+  this);
+}
+
+void UndefinedMemoryManipulationCheck::check(
+const MatchFinder::MatchResult ) {
+  if (const auto *Destination = Result.Nodes.getNodeAs("dest")) {
+diag(Destination->getLocStart(), "undefined behavior, destination "
+ "object is not TriviallyCopyable");
+  }
+  if 

[PATCH] D32700: [clang-tidy] Add bugprone-suspicious-memset-usage check.

2017-07-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308020: [clang-tidy] Add bugprone-suspicious-memset-usage 
check (authored by xazax).

Changed prior to commit:
  https://reviews.llvm.org/D32700?vs=106620=106624#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32700

Files:
  clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h
  clang-tools-extra/trunk/clang-tidy/google/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/google/MemsetZeroLengthCheck.cpp
  clang-tools-extra/trunk/clang-tidy/google/MemsetZeroLengthCheck.h
  clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-suspicious-memset-usage.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/google-runtime-memset.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/docs/clang-tidy/index.rst
  clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-memset-usage.cpp
  clang-tools-extra/trunk/test/clang-tidy/google-runtime-memset-zero-length.cpp

Index: clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
@@ -15,6 +15,7 @@
   clangTidy
   clangTidyAndroidModule
   clangTidyBoostModule
+  clangTidyBugproneModule
   clangTidyCERTModule
   clangTidyCppCoreGuidelinesModule
   clangTidyGoogleModule
Index: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
@@ -462,6 +462,11 @@
 static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
 BoostModuleAnchorSource;
 
+// This anchor is used to force the linker to link the BugproneModule.
+extern volatile int BugproneModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination =
+BugproneModuleAnchorSource;
+
 // This anchor is used to force the linker to link the LLVMModule.
 extern volatile int LLVMModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
Index: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
@@ -28,6 +28,7 @@
 
 add_subdirectory(android)
 add_subdirectory(boost)
+add_subdirectory(bugprone)
 add_subdirectory(cert)
 add_subdirectory(cppcoreguidelines)
 add_subdirectory(google)
Index: clang-tools-extra/trunk/clang-tidy/google/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/google/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/google/CMakeLists.txt
@@ -8,7 +8,6 @@
   GlobalNamesInHeadersCheck.cpp
   GoogleTidyModule.cpp
   IntegerTypesCheck.cpp
-  MemsetZeroLengthCheck.cpp
   NonConstReferences.cpp
   OverloadedUnaryAndCheck.cpp
   StringReferenceMemberCheck.cpp
Index: clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp
@@ -20,7 +20,6 @@
 #include "ExplicitMakePairCheck.h"
 #include "GlobalNamesInHeadersCheck.h"
 #include "IntegerTypesCheck.h"
-#include "MemsetZeroLengthCheck.h"
 #include "NonConstReferences.h"
 #include "OverloadedUnaryAndCheck.h"
 #include "StringReferenceMemberCheck.h"
@@ -55,8 +54,6 @@
 "google-runtime-references");
 CheckFactories.registerCheck(
 "google-runtime-member-string-references");
-CheckFactories.registerCheck(
-"google-runtime-memset");
 CheckFactories.registerCheck(
 "google-readability-casting");
 CheckFactories.registerCheck(
Index: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
@@ -0,0 +1,16 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_library(clangTidyBugproneModule
+  BugproneTidyModule.cpp
+  SuspiciousMemsetUsageCheck.cpp
+
+  LINK_LIBS
+  clangAnalysis
+  clangAST
+  clangASTMatchers
+  clangBasic
+  

[clang-tools-extra] r308020 - [clang-tidy] Add bugprone-suspicious-memset-usage check

2017-07-14 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Fri Jul 14 05:15:55 2017
New Revision: 308020

URL: http://llvm.org/viewvc/llvm-project?rev=308020=rev
Log:
[clang-tidy] Add bugprone-suspicious-memset-usage check

Created new module bugprone and placed the check in that.

Finds memset() calls with potential mistakes in their arguments.
Replaces and extends the existing google-runtime-memset-zero-length check.

Cases covered:
* Fill value is a character '0'. Integer 0 might have been intended.
* Fill value is out of char range and gets truncated.
* Byte count is zero. Potentially swapped with the fill value argument.

Patch by: Reka Nikolett Kovacs

Differential Revision: https://reviews.llvm.org/D32700

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-suspicious-memset-usage.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-suspicious-memset-usage.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/google/MemsetZeroLengthCheck.cpp
clang-tools-extra/trunk/clang-tidy/google/MemsetZeroLengthCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/google-runtime-memset.rst

clang-tools-extra/trunk/test/clang-tidy/google-runtime-memset-zero-length.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/google/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
clang-tools-extra/trunk/docs/clang-tidy/index.rst

Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=308020=308019=308020=diff
==
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Fri Jul 14 05:15:55 2017
@@ -28,6 +28,7 @@ add_clang_library(clangTidy
 
 add_subdirectory(android)
 add_subdirectory(boost)
+add_subdirectory(bugprone)
 add_subdirectory(cert)
 add_subdirectory(cppcoreguidelines)
 add_subdirectory(google)

Added: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=308020=auto
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Fri Jul 
14 05:15:55 2017
@@ -0,0 +1,38 @@
+//===--- BugproneTidyModule.cpp - clang-tidy 
--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "SuspiciousMemsetUsageCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+class BugproneModule : public ClangTidyModule {
+public:
+  void addCheckFactories(ClangTidyCheckFactories ) override {
+CheckFactories.registerCheck(
+"bugprone-suspicious-memset-usage");
+  }
+};
+
+} // namespace bugprone
+
+// Register the BugproneTidyModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add
+X("bugprone-module", "Adds checks for bugprone code constructs.");
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the BugproneModule.
+volatile int BugproneModuleAnchorSource = 0;
+
+} // namespace tidy
+} // namespace clang

Added: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=308020=auto
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Fri Jul 14 
05:15:55 2017
@@ -0,0 +1,16 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_library(clangTidyBugproneModule
+  BugproneTidyModule.cpp
+  SuspiciousMemsetUsageCheck.cpp
+
+  LINK_LIBS
+  clangAnalysis
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangLex
+  clangTidy
+  clangTidyUtils
+  

[PATCH] D32700: [clang-tidy] Add bugprone-suspicious-memset-usage check.

2017-07-14 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs updated this revision to Diff 106620.
rnkovacs marked an inline comment as done.
rnkovacs added a comment.

Moved comments inside `if` bodies.


https://reviews.llvm.org/D32700

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
  clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h
  clang-tidy/google/CMakeLists.txt
  clang-tidy/google/GoogleTidyModule.cpp
  clang-tidy/google/MemsetZeroLengthCheck.cpp
  clang-tidy/google/MemsetZeroLengthCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-suspicious-memset-usage.rst
  docs/clang-tidy/checks/google-runtime-memset.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/bugprone-suspicious-memset-usage.cpp
  test/clang-tidy/google-runtime-memset-zero-length.cpp

Index: test/clang-tidy/google-runtime-memset-zero-length.cpp
===
--- test/clang-tidy/google-runtime-memset-zero-length.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-// RUN: %check_clang_tidy %s google-runtime-memset %t
-
-void *memset(void *, int, __SIZE_TYPE__);
-
-namespace std {
-  using ::memset;
-}
-
-template 
-void memtmpl() {
-  memset(0, sizeof(int), i);
-  memset(0, sizeof(T), sizeof(T));
-  memset(0, sizeof(T), 0);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: memset(0, 0, sizeof(T));
-  memset(0, sizeof(int), 0);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: memset(0, 0, sizeof(int));
-}
-
-void foo(void *a, int xsize, int ysize) {
-  memset(a, sizeof(int), 0);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: memset(a, 0, sizeof(int));
-#define M memset(a, sizeof(int), 0);
-  M
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: #define M memset(a, sizeof(int), 0);
-  ::memset(a, xsize *
-   ysize, 0);
-// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: ::memset(a, 0, xsize *
-// CHECK-FIXES-NEXT: ysize);
-  std::memset(a, sizeof(int), 0x00);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: std::memset(a, 0x00, sizeof(int));
-
-  const int v = 0;
-  memset(a, sizeof(int), v);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: memset(a, v, sizeof(int));
-
-  memset(a, sizeof(int), v + v);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: memset(a, v + v, sizeof(int));
-
-  memset(a, sizeof(int), v + 1);
-
-  memset(a, -1, sizeof(int));
-  memset(a, 0xcd, 1);
-
-  // Don't warn when the fill char and the length are both known to be
-  // zero.  No bug is possible.
-  memset(a, 0, v);
-  memset(a, v, 0);
-
-  // -1 is clearly not a length by virtue of being negative, so no warning
-  // despite v == 0.
-  memset(a, -1, v);
-
-  memtmpl<0, int>();
-}
Index: test/clang-tidy/bugprone-suspicious-memset-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-suspicious-memset-usage.cpp
@@ -0,0 +1,77 @@
+// RUN: %check_clang_tidy %s bugprone-suspicious-memset-usage %t
+
+void *memset(void *, int, __SIZE_TYPE__);
+
+namespace std {
+  using ::memset;
+}
+
+template 
+void mtempl(int *ptr) {
+  memset(ptr, '0', sizeof(T));
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: memset fill value is char '0', potentially mistaken for int 0 [bugprone-suspicious-memset-usage]
+// CHECK-FIXES: memset(ptr, 0, sizeof(T));
+  memset(ptr, 256, sizeof(T));
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: memset fill value is out of unsigned character range, gets truncated [bugprone-suspicious-memset-usage]
+  memset(0, sizeof(T), 0);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped arguments [bugprone-suspicious-memset-usage]
+// CHECK-FIXES: memset(0, 0, sizeof(T));
+  memset(0, sizeof(int), 0);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped arguments [bugprone-suspicious-memset-usage]
+// CHECK-FIXES: memset(0, 0, sizeof(int));
+}
+
+void foo(int xsize, int ysize) {
+  int i[5] = {1, 2, 3, 4, 5};
+  char ca[3] = {'a', 'b', 'c'};
+  int *p = i;
+  int l = 5;
+  char z = '1';
+  char *c = 
+  int v = 0;
+
+  memset(p, '0', l);
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: memset fill value is char '0', potentially mistaken for int 0 [bugprone-suspicious-memset-usage]
+// CHECK-FIXES: memset(p, 0, l);
+
+  memset(p, 0xabcd, l);
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: memset fill value is out of 

[PATCH] D32700: [clang-tidy] Add bugprone-suspicious-memset-usage check.

2017-07-14 Thread Whisperity via Phabricator via cfe-commits
whisperity added inline comments.



Comment at: clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp:57-58
+void SuspiciousMemsetUsageCheck::check(const MatchFinder::MatchResult ) 
{
+  // Case 1: fill_char of memset() is a character '0'. Probably an integer zero
+  // was intended.
+  if (const auto *CharZeroFill =

@alexfh Your review on putting the comments within their applicable branch 
bodies applies here too?



Comment at: clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp:89-90
+
+  // Case 3: byte_count of memset() is zero. This is most likely an argument
+  // swap.
+  else if (const auto *Call = Result.Nodes.getNodeAs("call")) {

Same as L57-58.


https://reviews.llvm.org/D32700



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35405: [index] Added a method indexTopLevelDecls to run indexing on a list of Decls.

2017-07-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308016: [index] Added a method indexTopLevelDecls to run 
indexing on a list of Decls. (authored by ibiryukov).

Changed prior to commit:
  https://reviews.llvm.org/D35405?vs=106604=106614#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35405

Files:
  cfe/trunk/include/clang/Index/IndexingAction.h
  cfe/trunk/lib/Index/IndexingAction.cpp


Index: cfe/trunk/lib/Index/IndexingAction.cpp
===
--- cfe/trunk/lib/Index/IndexingAction.cpp
+++ cfe/trunk/lib/Index/IndexingAction.cpp
@@ -177,6 +177,18 @@
   DataConsumer->finish();
 }
 
+void index::indexTopLevelDecls(ASTContext , ArrayRef Decls,
+   std::shared_ptr DataConsumer,
+   IndexingOptions Opts) {
+  IndexingContext IndexCtx(Opts, *DataConsumer);
+  IndexCtx.setASTContext(Ctx);
+
+  DataConsumer->initialize(Ctx);
+  for (const Decl *D : Decls)
+IndexCtx.indexTopLevelDecl(D);
+  DataConsumer->finish();
+}
+
 void index::indexModuleFile(serialization::ModuleFile ,
 ASTReader ,
 std::shared_ptr DataConsumer,
Index: cfe/trunk/include/clang/Index/IndexingAction.h
===
--- cfe/trunk/include/clang/Index/IndexingAction.h
+++ cfe/trunk/include/clang/Index/IndexingAction.h
@@ -11,11 +11,14 @@
 #define LLVM_CLANG_INDEX_INDEXINGACTION_H
 
 #include "clang/Basic/LLVM.h"
+#include "llvm/ADT/ArrayRef.h"
 #include 
 
 namespace clang {
+  class ASTContext;
   class ASTReader;
   class ASTUnit;
+  class Decl;
   class FrontendAction;
 
 namespace serialization {
@@ -47,8 +50,11 @@
   std::shared_ptr DataConsumer,
   IndexingOptions Opts);
 
-void indexModuleFile(serialization::ModuleFile ,
- ASTReader ,
+void indexTopLevelDecls(ASTContext , ArrayRef Decls,
+std::shared_ptr DataConsumer,
+IndexingOptions Opts);
+
+void indexModuleFile(serialization::ModuleFile , ASTReader ,
  std::shared_ptr DataConsumer,
  IndexingOptions Opts);
 


Index: cfe/trunk/lib/Index/IndexingAction.cpp
===
--- cfe/trunk/lib/Index/IndexingAction.cpp
+++ cfe/trunk/lib/Index/IndexingAction.cpp
@@ -177,6 +177,18 @@
   DataConsumer->finish();
 }
 
+void index::indexTopLevelDecls(ASTContext , ArrayRef Decls,
+   std::shared_ptr DataConsumer,
+   IndexingOptions Opts) {
+  IndexingContext IndexCtx(Opts, *DataConsumer);
+  IndexCtx.setASTContext(Ctx);
+
+  DataConsumer->initialize(Ctx);
+  for (const Decl *D : Decls)
+IndexCtx.indexTopLevelDecl(D);
+  DataConsumer->finish();
+}
+
 void index::indexModuleFile(serialization::ModuleFile ,
 ASTReader ,
 std::shared_ptr DataConsumer,
Index: cfe/trunk/include/clang/Index/IndexingAction.h
===
--- cfe/trunk/include/clang/Index/IndexingAction.h
+++ cfe/trunk/include/clang/Index/IndexingAction.h
@@ -11,11 +11,14 @@
 #define LLVM_CLANG_INDEX_INDEXINGACTION_H
 
 #include "clang/Basic/LLVM.h"
+#include "llvm/ADT/ArrayRef.h"
 #include 
 
 namespace clang {
+  class ASTContext;
   class ASTReader;
   class ASTUnit;
+  class Decl;
   class FrontendAction;
 
 namespace serialization {
@@ -47,8 +50,11 @@
   std::shared_ptr DataConsumer,
   IndexingOptions Opts);
 
-void indexModuleFile(serialization::ModuleFile ,
- ASTReader ,
+void indexTopLevelDecls(ASTContext , ArrayRef Decls,
+std::shared_ptr DataConsumer,
+IndexingOptions Opts);
+
+void indexModuleFile(serialization::ModuleFile , ASTReader ,
  std::shared_ptr DataConsumer,
  IndexingOptions Opts);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32700: [clang-tidy] Add bugprone-suspicious-memset-usage check.

2017-07-14 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good with a single comment.

Thank you for working on this!




Comment at: clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp:74-75
+
+  // Case 2: fill_char of memset() is larger in size than an unsigned char so
+  // it gets truncated during conversion.
+  else if (const auto *NumFill =

The formatting is rather misleading here. Let's put the comment inside the 
`if`. Same below.


https://reviews.llvm.org/D32700



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308016 - [index] Added a method indexTopLevelDecls to run indexing on a list of Decls.

2017-07-14 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Jul 14 03:47:45 2017
New Revision: 308016

URL: http://llvm.org/viewvc/llvm-project?rev=308016=rev
Log:
[index] Added a method indexTopLevelDecls to run indexing on a list of Decls.

Summary:
We need it in clangd for refactoring that replaces ASTUnit
with manual AST management.

Reviewers: akyrtzi, benlangmuir, arphaman, klimek

Reviewed By: arphaman

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D35405

Modified:
cfe/trunk/include/clang/Index/IndexingAction.h
cfe/trunk/lib/Index/IndexingAction.cpp

Modified: cfe/trunk/include/clang/Index/IndexingAction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexingAction.h?rev=308016=308015=308016=diff
==
--- cfe/trunk/include/clang/Index/IndexingAction.h (original)
+++ cfe/trunk/include/clang/Index/IndexingAction.h Fri Jul 14 03:47:45 2017
@@ -11,11 +11,14 @@
 #define LLVM_CLANG_INDEX_INDEXINGACTION_H
 
 #include "clang/Basic/LLVM.h"
+#include "llvm/ADT/ArrayRef.h"
 #include 
 
 namespace clang {
+  class ASTContext;
   class ASTReader;
   class ASTUnit;
+  class Decl;
   class FrontendAction;
 
 namespace serialization {
@@ -47,8 +50,11 @@ void indexASTUnit(ASTUnit ,
   std::shared_ptr DataConsumer,
   IndexingOptions Opts);
 
-void indexModuleFile(serialization::ModuleFile ,
- ASTReader ,
+void indexTopLevelDecls(ASTContext , ArrayRef Decls,
+std::shared_ptr DataConsumer,
+IndexingOptions Opts);
+
+void indexModuleFile(serialization::ModuleFile , ASTReader ,
  std::shared_ptr DataConsumer,
  IndexingOptions Opts);
 

Modified: cfe/trunk/lib/Index/IndexingAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingAction.cpp?rev=308016=308015=308016=diff
==
--- cfe/trunk/lib/Index/IndexingAction.cpp (original)
+++ cfe/trunk/lib/Index/IndexingAction.cpp Fri Jul 14 03:47:45 2017
@@ -177,6 +177,18 @@ void index::indexASTUnit(ASTUnit ,
   DataConsumer->finish();
 }
 
+void index::indexTopLevelDecls(ASTContext , ArrayRef Decls,
+   std::shared_ptr DataConsumer,
+   IndexingOptions Opts) {
+  IndexingContext IndexCtx(Opts, *DataConsumer);
+  IndexCtx.setASTContext(Ctx);
+
+  DataConsumer->initialize(Ctx);
+  for (const Decl *D : Decls)
+IndexCtx.indexTopLevelDecl(D);
+  DataConsumer->finish();
+}
+
 void index::indexModuleFile(serialization::ModuleFile ,
 ASTReader ,
 std::shared_ptr DataConsumer,


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35349: [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

2017-07-14 Thread Alexander Kornienko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308015: [Clang-Tidy] Preserve Message, FileOffset, FilePath 
in Clang-Tidy YAML output (authored by alexfh).

Changed prior to commit:
  https://reviews.llvm.org/D35349?vs=106406=106609#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35349

Files:
  clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml
  clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml
  
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml
  
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml
  
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml
  clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/crlf/file1.yaml
  clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/no.yaml
  clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/yes.yaml
  
clang-tools-extra/trunk/unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
  clang-tools-extra/trunk/unittests/clang-apply-replacements/CMakeLists.txt

Index: clang-tools-extra/trunk/unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
@@ -0,0 +1,53 @@
+//===- clang-apply-replacements/ApplyReplacementsTest.cpp
+//--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang-apply-replacements/Tooling/ApplyReplacements.h"
+#include "gtest/gtest.h"
+
+using namespace clang::replace;
+using namespace llvm;
+
+namespace clang {
+namespace tooling {
+
+static TUDiagnostics
+makeTUDiagnostics(const std::string , StringRef DiagnosticName,
+  const DiagnosticMessage ,
+  const StringMap ,
+  StringRef BuildDirectory) {
+  TUDiagnostics TUs;
+  TUs.push_back({MainSourceFile,
+ {{DiagnosticName,
+   Message,
+   Replacements,
+   {},
+   Diagnostic::Warning,
+   BuildDirectory}}});
+  return TUs;
+}
+
+// Test to ensure diagnostics with no fixes, will be merged correctly
+// before applying.
+TEST(ApplyReplacementsTest, mergeDiagnosticsWithNoFixes) {
+  IntrusiveRefCntPtr DiagOpts(new DiagnosticOptions());
+  DiagnosticsEngine Diagnostics(
+  IntrusiveRefCntPtr(new DiagnosticIDs()), DiagOpts.get());
+  FileManager Files((FileSystemOptions()));
+  SourceManager SM(Diagnostics, Files);
+  TUDiagnostics TUs =
+  makeTUDiagnostics("path/to/source.cpp", "diagnostic", {}, {}, "path/to");
+  FileToReplacementsMap ReplacementsMap;
+
+  EXPECT_TRUE(mergeAndDeduplicate(TUs, ReplacementsMap, SM));
+  EXPECT_TRUE(ReplacementsMap.empty());
+}
+
+} // end namespace tooling
+} // end namespace clang
Index: clang-tools-extra/trunk/unittests/clang-apply-replacements/CMakeLists.txt
===
--- clang-tools-extra/trunk/unittests/clang-apply-replacements/CMakeLists.txt
+++ clang-tools-extra/trunk/unittests/clang-apply-replacements/CMakeLists.txt
@@ -8,6 +8,7 @@
   )
 
 add_extra_unittest(ClangApplyReplacementsTests
+  ApplyReplacementsTest.cpp
   ReformattingTest.cpp
   )
 
Index: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml
===
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml
@@ -2,6 +2,9 @@
 MainSourceFile: source1.cpp
 Diagnostics:
   - DiagnosticName:  test-conflict
+Message: Fix
+FilePath: $(path)/common.h
+FileOffset: 169
 Replacements:
   - FilePath:$(path)/common.h
 Offset:  169
Index: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml
===
--- clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml
+++ clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml
@@ -1,7 +1,10 @@
 ---
 MainSourceFile: source2.cpp
-Diagnostics: 
+Diagnostics:
   - DiagnosticName:  test-conflict
+Message: Fix
+FilePath: $(path)/common.h
+FileOffset: 106
 Replacements:
   - FilePath:$(path)/common.h
 Offset:  106
Index: clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml

[PATCH] D34404: [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

2017-07-14 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: unittests/Tooling/DiagnosticsYamlTest.cpp:35-45
+TEST(DiagnosticsYamlTest, serializesDiagnostics) {
+  TranslationUnitDiagnostics TUD;
+  TUD.MainSourceFile = "path/to/source.cpp";
+
+  StringMap Fix1 = { 
+{ 
+  "path/to/source.cpp",  

Note: there's a bunch of trailing whitespace here and the formatting is off in 
a few places. git-clang-format fixed both issues, but it would be nice if you 
set up your editor properly or run clang-format yourself next time.

Same for the other CL, but there I had to also clean up trailing whitespace 
from yaml files as well.


Repository:
  rL LLVM

https://reviews.llvm.org/D34404



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34404: [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

2017-07-14 Thread Alexander Kornienko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308014: [Clang-Tidy] Preserve Message, FileOffset, FilePath 
in Clang-Tidy YAML output (authored by alexfh).

Changed prior to commit:
  https://reviews.llvm.org/D34404?vs=106402=106608#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34404

Files:
  cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h
  cfe/trunk/unittests/Tooling/CMakeLists.txt
  cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp

Index: cfe/trunk/unittests/Tooling/CMakeLists.txt
===
--- cfe/trunk/unittests/Tooling/CMakeLists.txt
+++ cfe/trunk/unittests/Tooling/CMakeLists.txt
@@ -14,6 +14,7 @@
   CastExprTest.cpp
   CommentHandlerTest.cpp
   CompilationDatabaseTest.cpp
+  DiagnosticsYamlTest.cpp
   FixItTest.cpp
   LookupTest.cpp
   QualTypeNamesTest.cpp
Index: cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp
===
--- cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp
+++ cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp
@@ -0,0 +1,166 @@
+//===- unittests/Tooling/DiagnosticsYamlTest.cpp - Serialization tests ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Tests for serialization of Diagnostics.
+//
+//===--===//
+
+#include "clang/Tooling/DiagnosticsYaml.h"
+#include "clang/Tooling/Core/Diagnostic.h"
+#include "clang/Tooling/ReplacementsYaml.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace clang::tooling;
+
+static Diagnostic makeDiagnostic(StringRef DiagnosticName,
+ const std::string , int FileOffset,
+ const std::string ,
+ const StringMap ) {
+  DiagnosticMessage DiagMessage;
+  DiagMessage.Message = Message;
+  DiagMessage.FileOffset = FileOffset;
+  DiagMessage.FilePath = FilePath;
+  return Diagnostic(DiagnosticName, DiagMessage, Fix, {}, Diagnostic::Warning,
+"path/to/build/directory");
+}
+
+TEST(DiagnosticsYamlTest, serializesDiagnostics) {
+  TranslationUnitDiagnostics TUD;
+  TUD.MainSourceFile = "path/to/source.cpp";
+
+  StringMap Fix1 = {
+  {"path/to/source.cpp",
+   Replacements({"path/to/source.cpp", 100, 12, "replacement #1"})}};
+  TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#1", "message #1", 55,
+   "path/to/source.cpp", Fix1));
+
+  StringMap Fix2 = {
+  {"path/to/header.h",
+   Replacements({"path/to/header.h", 62, 2, "replacement #2"})}};
+  TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#2", "message #2", 60,
+   "path/to/header.h", Fix2));
+
+  TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#3", "message #3", 72,
+   "path/to/source2.cpp", {}));
+
+  std::string YamlContent;
+  raw_string_ostream YamlContentStream(YamlContent);
+
+  yaml::Output YAML(YamlContentStream);
+  YAML << TUD;
+
+  EXPECT_EQ("---\n"
+"MainSourceFile:  path/to/source.cpp\n"
+"Diagnostics: \n"
+"  - DiagnosticName:  'diagnostic#1\'\n"
+"Message: 'message #1'\n"
+"FileOffset:  55\n"
+"FilePath:path/to/source.cpp\n"
+"Replacements:\n"
+"  - FilePath:path/to/source.cpp\n"
+"Offset:  100\n"
+"Length:  12\n"
+"ReplacementText: 'replacement #1'\n"
+"  - DiagnosticName:  'diagnostic#2'\n"
+"Message: 'message #2'\n"
+"FileOffset:  60\n"
+"FilePath:path/to/header.h\n"
+"Replacements:\n"
+"  - FilePath:path/to/header.h\n"
+"Offset:  62\n"
+"Length:  2\n"
+"ReplacementText: 'replacement #2'\n"
+"  - DiagnosticName:  'diagnostic#3'\n"
+"Message: 'message #3'\n"
+"FileOffset:  72\n"
+"FilePath:path/to/source2.cpp\n"
+"Replacements:\n"
+"...\n",
+YamlContentStream.str());
+}
+
+TEST(DiagnosticsYamlTest, deserializesDiagnostics) {
+  std::string YamlContent = "---\n"
+"MainSourceFile:  path/to/source.cpp\n"
+"Diagnostics: \n"
+"  - DiagnosticName:  'diagnostic#1'\n"
+"Message:   

[clang-tools-extra] r308015 - [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

2017-07-14 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Jul 14 03:37:46 2017
New Revision: 308015

URL: http://llvm.org/viewvc/llvm-project?rev=308015=rev
Log:
[Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

Summary:
To get properly integration Clang-Tidy with CLion IDE, next things were 
implemented:
* Preserve `Message`, `FileOffset`, `FilePath` in the clang-tidy output.
* Export all diagnostics, not just the ones with fixes
* Test-cases

Reviewers: alexfh, ilya-biryukov

Subscribers: mgorny, JDevlieghere, xazax.hun, cfe-commits

Tags: #clang-tools-extra

Patch by Vladimir Plyashkun!

Differential Revision: https://reviews.llvm.org/D35349

Added:

clang-tools-extra/trunk/unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
Modified:

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml

clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/crlf/file1.yaml
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/no.yaml
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/format/yes.yaml
clang-tools-extra/trunk/unittests/clang-apply-replacements/CMakeLists.txt

Modified: 
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml?rev=308015=308014=308015=diff
==
--- 
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml 
(original)
+++ 
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file1.yaml 
Fri Jul 14 03:37:46 2017
@@ -2,6 +2,9 @@
 MainSourceFile: source1.cpp
 Diagnostics:
   - DiagnosticName: test-basic
+Message: Fix
+FilePath: $(path)/basic.h
+FileOffset: 242
 Replacements:
   - FilePath:$(path)/basic.h
 Offset:  242

Modified: 
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml?rev=308015=308014=308015=diff
==
--- 
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml 
(original)
+++ 
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/basic/file2.yaml 
Fri Jul 14 03:37:46 2017
@@ -2,6 +2,9 @@
 MainSourceFile: source2.cpp
 Diagnostics:
   - DiagnosticName: test-basic
+Message: Fix
+FilePath: $(path)/basic.h
+FileOffset: 148
 Replacements:
   - FilePath:$(path)/basic.h
 Offset:  148

Modified: 
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml?rev=308015=308014=308015=diff
==
--- 
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml
 (original)
+++ 
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file1.yaml
 Fri Jul 14 03:37:46 2017
@@ -2,6 +2,9 @@
 MainSourceFile: source1.cpp
 Diagnostics:
   - DiagnosticName: test-conflict
+Message: Fix
+FilePath: $(path)/common.h
+FileOffset: 106
 Replacements:
   - FilePath:$(path)/common.h
 Offset:  106

Modified: 
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml?rev=308015=308014=308015=diff
==
--- 
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml
 (original)
+++ 
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file2.yaml
 Fri Jul 14 03:37:46 2017
@@ -1,7 +1,10 @@
 ---
 MainSourceFile: source2.cpp
-Diagnostics: 
+Diagnostics:
   - DiagnosticName:  test-conflict
+Message: Fix
+FilePath: $(path)/common.h
+FileOffset: 106
 Replacements:
   - FilePath:$(path)/common.h
 Offset:  106

Modified: 
clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-apply-replacements/Inputs/conflict/file3.yaml?rev=308015=308014=308015=diff
==
--- 

r308014 - [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

2017-07-14 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Jul 14 03:37:44 2017
New Revision: 308014

URL: http://llvm.org/viewvc/llvm-project?rev=308014=rev
Log:
[Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

Summary:
To get properly integration Clang-Tidy with CLion IDE, next things were 
implemented:
1) Preserve `Message`, `FileOffset`, `FilePath` in the clang-tidy output.
2) Export all diagnostics, not just the ones with fixes
3) Test-cases

Reviewers: klimek, ilya-biryukov, alexfh

Reviewed By: alexfh

Subscribers: alexfh, JDevlieghere, mgorny, xazax.hun, cfe-commits, klimek

Tags: #clang-tools-extra

Patch by Vladimir Plyashkun!

Differential Revision: https://reviews.llvm.org/D34404

Added:
cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp
Modified:
cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h
cfe/trunk/unittests/Tooling/CMakeLists.txt

Modified: cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h?rev=308014=308013=308014=diff
==
--- cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h (original)
+++ cfe/trunk/include/clang/Tooling/DiagnosticsYaml.h Fri Jul 14 03:37:44 2017
@@ -56,6 +56,9 @@ template <> struct MappingTraits 
Keys(
 Io, D);
 Io.mapRequired("DiagnosticName", Keys->DiagnosticName);
+Io.mapRequired("Message", Keys->Message.Message);
+Io.mapRequired("FileOffset", Keys->Message.FileOffset);
+Io.mapRequired("FilePath", Keys->Message.FilePath);
 
 // FIXME: Export properly all the different fields.
 
@@ -82,17 +85,7 @@ template <> struct MappingTraits struct MappingTraits {
   static void mapping(IO , clang::tooling::TranslationUnitDiagnostics ) 
{
 Io.mapRequired("MainSourceFile", Doc.MainSourceFile);
-
-std::vector Diagnostics;
-for (auto  : Doc.Diagnostics) {
-  // FIXME: Export all diagnostics, not just the ones with fixes.
-  // Update MappingTraits::mapping.
-  if (Diagnostic.Fix.size() > 0) {
-Diagnostics.push_back(Diagnostic);
-  }
-}
-Io.mapRequired("Diagnostics", Diagnostics);
-Doc.Diagnostics = Diagnostics;
+Io.mapRequired("Diagnostics", Doc.Diagnostics);
   }
 };
 } // end namespace yaml

Modified: cfe/trunk/unittests/Tooling/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/CMakeLists.txt?rev=308014=308013=308014=diff
==
--- cfe/trunk/unittests/Tooling/CMakeLists.txt (original)
+++ cfe/trunk/unittests/Tooling/CMakeLists.txt Fri Jul 14 03:37:44 2017
@@ -14,6 +14,7 @@ add_clang_unittest(ToolingTests
   CastExprTest.cpp
   CommentHandlerTest.cpp
   CompilationDatabaseTest.cpp
+  DiagnosticsYamlTest.cpp
   FixItTest.cpp
   LookupTest.cpp
   QualTypeNamesTest.cpp

Added: cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp?rev=308014=auto
==
--- cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp (added)
+++ cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp Fri Jul 14 03:37:44 2017
@@ -0,0 +1,166 @@
+//===- unittests/Tooling/DiagnosticsYamlTest.cpp - Serialization tests ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Tests for serialization of Diagnostics.
+//
+//===--===//
+
+#include "clang/Tooling/DiagnosticsYaml.h"
+#include "clang/Tooling/Core/Diagnostic.h"
+#include "clang/Tooling/ReplacementsYaml.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace clang::tooling;
+
+static Diagnostic makeDiagnostic(StringRef DiagnosticName,
+ const std::string , int FileOffset,
+ const std::string ,
+ const StringMap ) {
+  DiagnosticMessage DiagMessage;
+  DiagMessage.Message = Message;
+  DiagMessage.FileOffset = FileOffset;
+  DiagMessage.FilePath = FilePath;
+  return Diagnostic(DiagnosticName, DiagMessage, Fix, {}, Diagnostic::Warning,
+"path/to/build/directory");
+}
+
+TEST(DiagnosticsYamlTest, serializesDiagnostics) {
+  TranslationUnitDiagnostics TUD;
+  TUD.MainSourceFile = "path/to/source.cpp";
+
+  StringMap Fix1 = {
+  {"path/to/source.cpp",
+   Replacements({"path/to/source.cpp", 100, 12, "replacement #1"})}};
+  TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#1", "message #1", 55,
+   "path/to/source.cpp", Fix1));
+
+  StringMap Fix2 = {
+  

[PATCH] D35186: [analyzer] Add annotation for functions taking user-facing strings

2017-07-14 Thread Erik Verbruggen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308012: [analyzer] Add annotation for functions taking 
user-facing strings (authored by erikjv).

Changed prior to commit:
  https://reviews.llvm.org/D35186?vs=105792=106605#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35186

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  cfe/trunk/test/Analysis/localization-aggressive.m

Index: cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
@@ -57,7 +57,7 @@
 };
 
 class NonLocalizedStringChecker
-: public Checker {
 
@@ -79,9 +79,10 @@
   void setNonLocalizedState(SVal S, CheckerContext ) const;
   void setLocalizedState(SVal S, CheckerContext ) const;
 
-  bool isAnnotatedAsLocalized(const Decl *D) const;
-  void reportLocalizationError(SVal S, const ObjCMethodCall ,
-   CheckerContext , int argumentNumber = 0) const;
+  bool isAnnotatedAsReturningLocalized(const Decl *D) const;
+  bool isAnnotatedAsTakingLocalized(const Decl *D) const;
+  void reportLocalizationError(SVal S, const CallEvent , CheckerContext ,
+   int argumentNumber = 0) const;
 
   int getLocalizedArgumentForSelector(const IdentifierInfo *Receiver,
   Selector S) const;
@@ -97,6 +98,7 @@
   void checkPreObjCMessage(const ObjCMethodCall , CheckerContext ) const;
   void checkPostObjCMessage(const ObjCMethodCall , CheckerContext ) const;
   void checkPostStmt(const ObjCStringLiteral *SL, CheckerContext ) const;
+  void checkPreCall(const CallEvent , CheckerContext ) const;
   void checkPostCall(const CallEvent , CheckerContext ) const;
 };
 
@@ -644,7 +646,8 @@
 
 /// Checks to see if the method / function declaration includes
 /// __attribute__((annotate("returns_localized_nsstring")))
-bool NonLocalizedStringChecker::isAnnotatedAsLocalized(const Decl *D) const {
+bool NonLocalizedStringChecker::isAnnotatedAsReturningLocalized(
+const Decl *D) const {
   if (!D)
 return false;
   return std::any_of(
@@ -654,6 +657,19 @@
   });
 }
 
+/// Checks to see if the method / function declaration includes
+/// __attribute__((annotate("takes_localized_nsstring")))
+bool NonLocalizedStringChecker::isAnnotatedAsTakingLocalized(
+const Decl *D) const {
+  if (!D)
+return false;
+  return std::any_of(
+  D->specific_attr_begin(),
+  D->specific_attr_end(), [](const AnnotateAttr *Ann) {
+return Ann->getAnnotation() == "takes_localized_nsstring";
+  });
+}
+
 /// Returns true if the given SVal is marked as Localized in the program state
 bool NonLocalizedStringChecker::hasLocalizedState(SVal S,
   CheckerContext ) const {
@@ -733,8 +749,7 @@
 
 /// Reports a localization error for the passed in method call and SVal
 void NonLocalizedStringChecker::reportLocalizationError(
-SVal S, const ObjCMethodCall , CheckerContext ,
-int argumentNumber) const {
+SVal S, const CallEvent , CheckerContext , int argumentNumber) const {
 
   // Don't warn about localization errors in classes and methods that
   // may be debug code.
@@ -832,7 +847,21 @@
 }
   }
 
-  if (argumentNumber < 0) // There was no match in UIMethods
+  if (argumentNumber < 0) { // There was no match in UIMethods
+if (const Decl *D = msg.getDecl()) {
+  if (const ObjCMethodDecl *OMD = dyn_cast_or_null(D)) {
+auto formals = OMD->parameters();
+for (unsigned i = 0, ei = formals.size(); i != ei; ++i) {
+  if (isAnnotatedAsTakingLocalized(formals[i])) {
+argumentNumber = i;
+break;
+  }
+}
+  }
+}
+  }
+
+  if (argumentNumber < 0) // Still no match
 return;
 
   SVal svTitle = msg.getArgSVal(argumentNumber);
@@ -855,6 +884,25 @@
   }
 }
 
+void NonLocalizedStringChecker::checkPreCall(const CallEvent ,
+ CheckerContext ) const {
+  const Decl *D = Call.getDecl();
+  if (D && isa(D)) {
+const FunctionDecl *FD = dyn_cast(D);
+auto formals = FD->parameters();
+for (unsigned i = 0,
+  ei = std::min(unsigned(formals.size()), Call.getNumArgs());
+ i != ei; ++i) {
+  if (isAnnotatedAsTakingLocalized(formals[i])) {
+auto actual = Call.getArgSVal(i);
+if (hasNonLocalizedState(actual, C)) {
+  reportLocalizationError(actual, Call, C, i + 1);
+}
+  }
+}
+  }
+}
+
 static inline bool isNSStringType(QualType T, ASTContext ) {
 
   const 

r308012 - [analyzer] Add annotation for functions taking user-facing strings

2017-07-14 Thread Erik Verbruggen via cfe-commits
Author: erikjv
Date: Fri Jul 14 03:24:36 2017
New Revision: 308012

URL: http://llvm.org/viewvc/llvm-project?rev=308012=rev
Log:
[analyzer] Add annotation for functions taking user-facing strings

There was already a returns_localized_nsstring annotation to indicate
that the return value could be passed to UIKit methods that would
display them. However, those UIKit methods were hard-coded, and it was
not possible to indicate that other classes/methods in a code-base would
do the same.

The takes_localized_nsstring annotation can be put on function
parameters and selector parameters to indicate that those will also show
the string to the user.

Differential Revision: https://reviews.llvm.org/D35186

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
cfe/trunk/test/Analysis/localization-aggressive.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp?rev=308012=308011=308012=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp Fri Jul 14 
03:24:36 2017
@@ -57,7 +57,7 @@ public:
 };
 
 class NonLocalizedStringChecker
-: public Checker {
 
@@ -79,9 +79,10 @@ class NonLocalizedStringChecker
   void setNonLocalizedState(SVal S, CheckerContext ) const;
   void setLocalizedState(SVal S, CheckerContext ) const;
 
-  bool isAnnotatedAsLocalized(const Decl *D) const;
-  void reportLocalizationError(SVal S, const ObjCMethodCall ,
-   CheckerContext , int argumentNumber = 0) 
const;
+  bool isAnnotatedAsReturningLocalized(const Decl *D) const;
+  bool isAnnotatedAsTakingLocalized(const Decl *D) const;
+  void reportLocalizationError(SVal S, const CallEvent , CheckerContext ,
+   int argumentNumber = 0) const;
 
   int getLocalizedArgumentForSelector(const IdentifierInfo *Receiver,
   Selector S) const;
@@ -97,6 +98,7 @@ public:
   void checkPreObjCMessage(const ObjCMethodCall , CheckerContext ) const;
   void checkPostObjCMessage(const ObjCMethodCall , CheckerContext ) 
const;
   void checkPostStmt(const ObjCStringLiteral *SL, CheckerContext ) const;
+  void checkPreCall(const CallEvent , CheckerContext ) const;
   void checkPostCall(const CallEvent , CheckerContext ) const;
 };
 
@@ -644,7 +646,8 @@ void NonLocalizedStringChecker::initLocS
 
 /// Checks to see if the method / function declaration includes
 /// __attribute__((annotate("returns_localized_nsstring")))
-bool NonLocalizedStringChecker::isAnnotatedAsLocalized(const Decl *D) const {
+bool NonLocalizedStringChecker::isAnnotatedAsReturningLocalized(
+const Decl *D) const {
   if (!D)
 return false;
   return std::any_of(
@@ -654,6 +657,19 @@ bool NonLocalizedStringChecker::isAnnota
   });
 }
 
+/// Checks to see if the method / function declaration includes
+/// __attribute__((annotate("takes_localized_nsstring")))
+bool NonLocalizedStringChecker::isAnnotatedAsTakingLocalized(
+const Decl *D) const {
+  if (!D)
+return false;
+  return std::any_of(
+  D->specific_attr_begin(),
+  D->specific_attr_end(), [](const AnnotateAttr *Ann) {
+return Ann->getAnnotation() == "takes_localized_nsstring";
+  });
+}
+
 /// Returns true if the given SVal is marked as Localized in the program state
 bool NonLocalizedStringChecker::hasLocalizedState(SVal S,
   CheckerContext ) const {
@@ -733,8 +749,7 @@ static bool isDebuggingContext(CheckerCo
 
 /// Reports a localization error for the passed in method call and SVal
 void NonLocalizedStringChecker::reportLocalizationError(
-SVal S, const ObjCMethodCall , CheckerContext ,
-int argumentNumber) const {
+SVal S, const CallEvent , CheckerContext , int argumentNumber) const {
 
   // Don't warn about localization errors in classes and methods that
   // may be debug code.
@@ -832,7 +847,21 @@ void NonLocalizedStringChecker::checkPre
 }
   }
 
-  if (argumentNumber < 0) // There was no match in UIMethods
+  if (argumentNumber < 0) { // There was no match in UIMethods
+if (const Decl *D = msg.getDecl()) {
+  if (const ObjCMethodDecl *OMD = dyn_cast_or_null(D)) {
+auto formals = OMD->parameters();
+for (unsigned i = 0, ei = formals.size(); i != ei; ++i) {
+  if (isAnnotatedAsTakingLocalized(formals[i])) {
+argumentNumber = i;
+break;
+  }
+}
+  }
+}
+  }
+
+  if (argumentNumber < 0) // Still no match
 return;
 
   SVal svTitle = 

[PATCH] D35405: [index] Added a method indexTopLevelDecls to run indexing on a list of Decls.

2017-07-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

LGTM, thanks.


https://reviews.llvm.org/D35405



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35405: [index] Added a method indexTopLevelDecls to run indexing on a list of Decls.

2017-07-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked 2 inline comments as done.
ilya-biryukov added inline comments.



Comment at: lib/Index/IndexingAction.cpp:181
+void index::indexTopLevelDecls(ASTContext , ArrayRef Decls,
+std::shared_ptr DataConsumer,
+IndexingOptions Opts) {

arphaman wrote:
> clang-format?
Sorry, didn't rerun it after a rename of the method. Fixed now.


https://reviews.llvm.org/D35405



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35405: [index] Added a method indexTopLevelDecls to run indexing on a list of Decls.

2017-07-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 106604.
ilya-biryukov added a comment.

- Fixed formatting.


https://reviews.llvm.org/D35405

Files:
  include/clang/Index/IndexingAction.h
  lib/Index/IndexingAction.cpp


Index: lib/Index/IndexingAction.cpp
===
--- lib/Index/IndexingAction.cpp
+++ lib/Index/IndexingAction.cpp
@@ -177,6 +177,18 @@
   DataConsumer->finish();
 }
 
+void index::indexTopLevelDecls(ASTContext , ArrayRef Decls,
+   std::shared_ptr DataConsumer,
+   IndexingOptions Opts) {
+  IndexingContext IndexCtx(Opts, *DataConsumer);
+  IndexCtx.setASTContext(Ctx);
+
+  DataConsumer->initialize(Ctx);
+  for (const Decl *D : Decls)
+IndexCtx.indexTopLevelDecl(D);
+  DataConsumer->finish();
+}
+
 void index::indexModuleFile(serialization::ModuleFile ,
 ASTReader ,
 std::shared_ptr DataConsumer,
Index: include/clang/Index/IndexingAction.h
===
--- include/clang/Index/IndexingAction.h
+++ include/clang/Index/IndexingAction.h
@@ -11,11 +11,14 @@
 #define LLVM_CLANG_INDEX_INDEXINGACTION_H
 
 #include "clang/Basic/LLVM.h"
+#include 
 #include 
 
 namespace clang {
+  class ASTContext;
   class ASTReader;
   class ASTUnit;
+  class Decl;
   class FrontendAction;
 
 namespace serialization {
@@ -47,8 +50,11 @@
   std::shared_ptr DataConsumer,
   IndexingOptions Opts);
 
-void indexModuleFile(serialization::ModuleFile ,
- ASTReader ,
+void indexTopLevelDecls(ASTContext , ArrayRef Decls,
+std::shared_ptr DataConsumer,
+IndexingOptions Opts);
+
+void indexModuleFile(serialization::ModuleFile , ASTReader ,
  std::shared_ptr DataConsumer,
  IndexingOptions Opts);
 


Index: lib/Index/IndexingAction.cpp
===
--- lib/Index/IndexingAction.cpp
+++ lib/Index/IndexingAction.cpp
@@ -177,6 +177,18 @@
   DataConsumer->finish();
 }
 
+void index::indexTopLevelDecls(ASTContext , ArrayRef Decls,
+   std::shared_ptr DataConsumer,
+   IndexingOptions Opts) {
+  IndexingContext IndexCtx(Opts, *DataConsumer);
+  IndexCtx.setASTContext(Ctx);
+
+  DataConsumer->initialize(Ctx);
+  for (const Decl *D : Decls)
+IndexCtx.indexTopLevelDecl(D);
+  DataConsumer->finish();
+}
+
 void index::indexModuleFile(serialization::ModuleFile ,
 ASTReader ,
 std::shared_ptr DataConsumer,
Index: include/clang/Index/IndexingAction.h
===
--- include/clang/Index/IndexingAction.h
+++ include/clang/Index/IndexingAction.h
@@ -11,11 +11,14 @@
 #define LLVM_CLANG_INDEX_INDEXINGACTION_H
 
 #include "clang/Basic/LLVM.h"
+#include 
 #include 
 
 namespace clang {
+  class ASTContext;
   class ASTReader;
   class ASTUnit;
+  class Decl;
   class FrontendAction;
 
 namespace serialization {
@@ -47,8 +50,11 @@
   std::shared_ptr DataConsumer,
   IndexingOptions Opts);
 
-void indexModuleFile(serialization::ModuleFile ,
- ASTReader ,
+void indexTopLevelDecls(ASTContext , ArrayRef Decls,
+std::shared_ptr DataConsumer,
+IndexingOptions Opts);
+
+void indexModuleFile(serialization::ModuleFile , ASTReader ,
  std::shared_ptr DataConsumer,
  IndexingOptions Opts);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35405: [index] Added a method indexTopLevelDecls to run indexing on a list of Decls.

2017-07-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman requested changes to this revision.
arphaman added a comment.
This revision now requires changes to proceed.

Nice, I will need something like this for the refactoring stress test tool in 
the future that verifies that the indexer and renaming engine have a similar 
view of the code.




Comment at: include/clang/Index/IndexingAction.h:21
   class FrontendAction;
+  class ASTContext;
+  class Decl;

Please arrange the added declarations so that the whole list is in ordered 
alphabetically.



Comment at: lib/Index/IndexingAction.cpp:181
+void index::indexTopLevelDecls(ASTContext , ArrayRef Decls,
+std::shared_ptr DataConsumer,
+IndexingOptions Opts) {

clang-format?


https://reviews.llvm.org/D35405



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35406: [clangd] Replace ASTUnit with manual AST management.

2017-07-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Depends on change to cfe (https://reviews.llvm.org/D35405) to compile properly.


https://reviews.llvm.org/D35406



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35405: [index] Added a method indexTopLevelDecls to run indexing on a list of Decls.

2017-07-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

For reference: clangd refactoring https://reviews.llvm.org/D35406


https://reviews.llvm.org/D35405



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35406: [clangd] Replace ASTUnit with manual AST management.

2017-07-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.

This refactoring does not aim to introduce any significant changes to
the behaviour of clangd to keep the change as simple as possible.


https://reviews.llvm.org/D35406

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h

Index: clangd/ClangdUnit.h
===
--- clangd/ClangdUnit.h
+++ clangd/ClangdUnit.h
@@ -13,6 +13,9 @@
 #include "Path.h"
 #include "Protocol.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/PrecompiledPreamble.h"
+#include "clang/Serialization/ASTBitCodes.h"
+#include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include 
 
@@ -70,11 +73,79 @@
   void dumpAST(llvm::raw_ostream ) const;
 
 private:
+  /// Stores and provides access to parsed AST.
+  class ParsedAST {
+  public:
+/// Attempts to run Clang and store parsed AST. If \p Preamble is non-null
+/// it is reused during parsing.
+static llvm::Optional
+Build(std::unique_ptr CI,
+  const PrecompiledPreamble *Preamble,
+  ArrayRef PreambleDeclIDs,
+  std::unique_ptr Buffer,
+  std::shared_ptr PCHs,
+  IntrusiveRefCntPtr VFS);
+
+ParsedAST(ParsedAST &);
+ParsedAST =(ParsedAST &);
+
+~ParsedAST();
+
+ASTContext ();
+const ASTContext () const;
+
+Preprocessor ();
+const Preprocessor () const;
+
+ArrayRef getTopLevelDecls();
+
+const std::vector () const;
+
+  private:
+ParsedAST(std::unique_ptr Clang,
+  std::unique_ptr Action,
+  std::vector TopLevelDecls,
+  std::vector PendingTopLevelDecls,
+  std::vector Diags);
+
+  private:
+void ensurePreambleDeclsDeserialized();
+
+// We store an "incomplete" FrontendAction (i.e. no EndSourceFile was called
+// on it) and CompilerInstance used to run it. That way we don't have to do
+// complex memory management of all Clang structures on our own. (They are
+// stored in CompilerInstance and cleaned up by
+// FrontendAction.EndSourceFile).
+std::unique_ptr Clang;
+std::unique_ptr Action;
+
+// Data, stored after parsing.
+std::vector Diags;
+std::vector TopLevelDecls;
+std::vector PendingTopLevelDecls;
+  };
+
+  // Store Preamble and all associated data
+  struct PreambleData {
+PreambleData(PrecompiledPreamble Preamble,
+ std::vector TopLevelDeclIDs,
+ std::vector Diags);
+
+PrecompiledPreamble Preamble;
+std::vector TopLevelDeclIDs;
+std::vector Diags;
+  };
+
+  SourceLocation getBeginningOfIdentifier(const Position ,
+  const FileEntry *FE) const;
+
   Path FileName;
-  std::unique_ptr Unit;
-  std::shared_ptr PCHs;
+  tooling::CompileCommand Command;
 
-  SourceLocation getBeginningOfIdentifier(const Position& Pos, const FileEntry* FE) const;
+  llvm::Optional Preamble;
+  llvm::Optional Unit;
+
+  std::shared_ptr PCHs;
 };
 
 } // namespace clangd
Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -9,23 +9,215 @@
 
 #include "ClangdUnit.h"
 
-#include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "clang/Frontend/Utils.h"
-#include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexDataConsumer.h"
+#include "clang/Index/IndexingAction.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Sema/Sema.h"
+#include "clang/Serialization/ASTWriter.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Format.h"
 
 #include 
 
 using namespace clang::clangd;
 using namespace clang;
 
+namespace {
+
+class DeclTrackingASTConsumer : public ASTConsumer {
+public:
+  DeclTrackingASTConsumer(std::vector )
+  : TopLevelDecls(TopLevelDecls) {}
+
+  bool HandleTopLevelDecl(DeclGroupRef DG) override {
+for (const Decl *D : DG) {
+  // ObjCMethodDecl are not actually top-level decls.
+  if (isa(D))
+continue;
+
+  TopLevelDecls.push_back(D);
+}
+return true;
+  }
+
+private:
+  std::vector 
+};
+
+class ClangdFrontendAction : public SyntaxOnlyAction {
+public:
+  std::vector takeTopLevelDecls() {
+return std::move(TopLevelDecls);
+  }
+
+protected:
+  std::unique_ptr CreateASTConsumer(CompilerInstance ,
+ StringRef InFile) override {
+return llvm::make_unique(/*ref*/ TopLevelDecls);
+  }
+
+private:
+  std::vector TopLevelDecls;
+};
+
+class ClangdUnitPreambleCallbacks : public 

[PATCH] D34440: [Clang] Expand response files before loading compilation database

2017-07-14 Thread Vladimir Plyashkun via Phabricator via cfe-commits
vladimir.plyashkun added a comment.

Even if i'll change content of //arguments.rsp// to
`-std=c++11 -Ipath/to/include -Ipath/to/include2 -DMACRO `
and will try to call clang-tidy process in this way:
`clang-tidy -checks=* main.cpp -export-fixes=... -- @arguments.rsp`
it also has no effect, because all compiler options will be ignored (i thinks 
it's because that //stripPositionalArgs()// function deletes @arguments.rsp 
parameter as unused input).


Repository:
  rL LLVM

https://reviews.llvm.org/D34440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35405: [index] Added a method indexTopLevelDecls to run indexing on a list of Decls.

2017-07-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.

We need it in clangd for refactoring that replaces ASTUnit
with manual AST management.


https://reviews.llvm.org/D35405

Files:
  include/clang/Index/IndexingAction.h
  lib/Index/IndexingAction.cpp


Index: lib/Index/IndexingAction.cpp
===
--- lib/Index/IndexingAction.cpp
+++ lib/Index/IndexingAction.cpp
@@ -177,6 +177,18 @@
   DataConsumer->finish();
 }
 
+void index::indexTopLevelDecls(ASTContext , ArrayRef Decls,
+std::shared_ptr DataConsumer,
+IndexingOptions Opts) {
+  IndexingContext IndexCtx(Opts, *DataConsumer);
+  IndexCtx.setASTContext(Ctx);
+
+  DataConsumer->initialize(Ctx);
+  for (const Decl *D : Decls)
+IndexCtx.indexTopLevelDecl(D);
+  DataConsumer->finish();
+}
+
 void index::indexModuleFile(serialization::ModuleFile ,
 ASTReader ,
 std::shared_ptr DataConsumer,
Index: include/clang/Index/IndexingAction.h
===
--- include/clang/Index/IndexingAction.h
+++ include/clang/Index/IndexingAction.h
@@ -11,12 +11,15 @@
 #define LLVM_CLANG_INDEX_INDEXINGACTION_H
 
 #include "clang/Basic/LLVM.h"
+#include 
 #include 
 
 namespace clang {
   class ASTReader;
   class ASTUnit;
   class FrontendAction;
+  class ASTContext;
+  class Decl;
 
 namespace serialization {
   class ModuleFile;
@@ -47,8 +50,11 @@
   std::shared_ptr DataConsumer,
   IndexingOptions Opts);
 
-void indexModuleFile(serialization::ModuleFile ,
- ASTReader ,
+void indexTopLevelDecls(ASTContext , ArrayRef Decls,
+std::shared_ptr DataConsumer,
+IndexingOptions Opts);
+
+void indexModuleFile(serialization::ModuleFile , ASTReader ,
  std::shared_ptr DataConsumer,
  IndexingOptions Opts);
 


Index: lib/Index/IndexingAction.cpp
===
--- lib/Index/IndexingAction.cpp
+++ lib/Index/IndexingAction.cpp
@@ -177,6 +177,18 @@
   DataConsumer->finish();
 }
 
+void index::indexTopLevelDecls(ASTContext , ArrayRef Decls,
+std::shared_ptr DataConsumer,
+IndexingOptions Opts) {
+  IndexingContext IndexCtx(Opts, *DataConsumer);
+  IndexCtx.setASTContext(Ctx);
+
+  DataConsumer->initialize(Ctx);
+  for (const Decl *D : Decls)
+IndexCtx.indexTopLevelDecl(D);
+  DataConsumer->finish();
+}
+
 void index::indexModuleFile(serialization::ModuleFile ,
 ASTReader ,
 std::shared_ptr DataConsumer,
Index: include/clang/Index/IndexingAction.h
===
--- include/clang/Index/IndexingAction.h
+++ include/clang/Index/IndexingAction.h
@@ -11,12 +11,15 @@
 #define LLVM_CLANG_INDEX_INDEXINGACTION_H
 
 #include "clang/Basic/LLVM.h"
+#include 
 #include 
 
 namespace clang {
   class ASTReader;
   class ASTUnit;
   class FrontendAction;
+  class ASTContext;
+  class Decl;
 
 namespace serialization {
   class ModuleFile;
@@ -47,8 +50,11 @@
   std::shared_ptr DataConsumer,
   IndexingOptions Opts);
 
-void indexModuleFile(serialization::ModuleFile ,
- ASTReader ,
+void indexTopLevelDecls(ASTContext , ArrayRef Decls,
+std::shared_ptr DataConsumer,
+IndexingOptions Opts);
+
+void indexModuleFile(serialization::ModuleFile , ASTReader ,
  std::shared_ptr DataConsumer,
  IndexingOptions Opts);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308008 - Keep the IdentifierInfo in the Token for alternative operator keyword

2017-07-14 Thread Olivier Goffart via cfe-commits
Author: ogoffart
Date: Fri Jul 14 02:23:40 2017
New Revision: 308008

URL: http://llvm.org/viewvc/llvm-project?rev=308008=rev
Log:
Keep the IdentifierInfo in the Token for alternative operator keyword

The goal of this commit is to fix clang-format so it does not merge tokens when
using the alternative spelling keywords. (eg: "not foo" should not become 
"notfoo")

The problem is that Preprocessor::HandleIdentifier used to drop the identifier 
info
from the token for these keyword. This means the first condition of
TokenAnnotator::spaceRequiredBefore is not met. We could add explicit check for
the spelling in that condition, but I think it is better to keep the 
IdentifierInfo
and handle the operator keyword explicitly when needed. That actually leads to 
simpler
code, and probably slightly more efficient as well.

Another side effect of this change is that __identifier(and) will now work as
one would expect, removing a FIXME from the MicrosoftExtensions.cpp test

Differential Revision: https://reviews.llvm.org/D35172

Modified:
cfe/trunk/include/clang/Basic/IdentifierTable.h
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PPExpressions.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/test/Parser/MicrosoftExtensions.cpp
cfe/trunk/test/Preprocessor/cxx_oper_keyword.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/include/clang/Basic/IdentifierTable.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=308008=308007=308008=diff
==
--- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Basic/IdentifierTable.h Fri Jul 14 02:23:40 2017
@@ -272,10 +272,6 @@ public:
   /// this identifier is a C++ alternate representation of an operator.
   void setIsCPlusPlusOperatorKeyword(bool Val = true) {
 IsCPPOperatorKeyword = Val;
-if (Val)
-  NeedsHandleIdentifier = true;
-else
-  RecomputeNeedsHandleIdentifier();
   }
   bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; }
 
@@ -381,10 +377,9 @@ private:
   /// This method is very tied to the definition of HandleIdentifier.  Any
   /// change to it should be reflected here.
   void RecomputeNeedsHandleIdentifier() {
-NeedsHandleIdentifier =
-  (isPoisoned() | hasMacroDefinition() | isCPlusPlusOperatorKeyword() |
-   isExtensionToken() | isFutureCompatKeyword() || isOutOfDate() ||
-   isModulesImport());
+NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
+isExtensionToken() || isFutureCompatKeyword() ||
+isOutOfDate() || isModulesImport();
   }
 };
 

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=308008=308007=308008=diff
==
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Fri Jul 14 02:23:40 2017
@@ -220,26 +220,18 @@ bool Preprocessor::CheckMacroName(Token
 return Diag(MacroNameTok, diag::err_pp_missing_macro_name);
 
   IdentifierInfo *II = MacroNameTok.getIdentifierInfo();
-  if (!II) {
-bool Invalid = false;
-std::string Spelling = getSpelling(MacroNameTok, );
-if (Invalid)
-  return Diag(MacroNameTok, diag::err_pp_macro_not_identifier);
-II = getIdentifierInfo(Spelling);
-
-if (!II->isCPlusPlusOperatorKeyword())
-  return Diag(MacroNameTok, diag::err_pp_macro_not_identifier);
+  if (!II)
+return Diag(MacroNameTok, diag::err_pp_macro_not_identifier);
 
+  if (II->isCPlusPlusOperatorKeyword()) {
 // C++ 2.5p2: Alternative tokens behave the same as its primary token
 // except for their spellings.
 Diag(MacroNameTok, getLangOpts().MicrosoftExt
? diag::ext_pp_operator_used_as_macro_name
: diag::err_pp_operator_used_as_macro_name)
 << II << MacroNameTok.getKind();
-
 // Allow #defining |and| and friends for Microsoft compatibility or
 // recovery when legacy C headers are included in C++.
-MacroNameTok.setIdentifierInfo(II);
   }
 
   if ((isDefineUndef != MU_Other) && II->getPPKeywordID() == tok::pp_defined) {

Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=308008=308007=308008=diff
==
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Fri Jul 14 02:23:40 2017
@@ -237,35 +237,32 @@ static bool EvaluateValue(PPValue 
 PP.setCodeCompletionReached();
 PP.LexNonComment(PeekTok);
   }
-  
-  // If this token's spelling is a pp-identifier, check to see if it is
-  // 'defined' or if it is a macro.  Note that we check here 

[PATCH] D35172: Keep the IdentifierInfo in the Token for alternative operator keyword

2017-07-14 Thread Olivier Goffart via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308008: Keep the IdentifierInfo in the Token for alternative 
operator keyword (authored by ogoffart).

Changed prior to commit:
  https://reviews.llvm.org/D35172?vs=105816=106594#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35172

Files:
  cfe/trunk/include/clang/Basic/IdentifierTable.h
  cfe/trunk/lib/Lex/PPDirectives.cpp
  cfe/trunk/lib/Lex/PPExpressions.cpp
  cfe/trunk/lib/Lex/Preprocessor.cpp
  cfe/trunk/test/Parser/MicrosoftExtensions.cpp
  cfe/trunk/test/Preprocessor/cxx_oper_keyword.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp

Index: cfe/trunk/lib/Lex/PPDirectives.cpp
===
--- cfe/trunk/lib/Lex/PPDirectives.cpp
+++ cfe/trunk/lib/Lex/PPDirectives.cpp
@@ -220,26 +220,18 @@
 return Diag(MacroNameTok, diag::err_pp_missing_macro_name);
 
   IdentifierInfo *II = MacroNameTok.getIdentifierInfo();
-  if (!II) {
-bool Invalid = false;
-std::string Spelling = getSpelling(MacroNameTok, );
-if (Invalid)
-  return Diag(MacroNameTok, diag::err_pp_macro_not_identifier);
-II = getIdentifierInfo(Spelling);
-
-if (!II->isCPlusPlusOperatorKeyword())
-  return Diag(MacroNameTok, diag::err_pp_macro_not_identifier);
+  if (!II)
+return Diag(MacroNameTok, diag::err_pp_macro_not_identifier);
 
+  if (II->isCPlusPlusOperatorKeyword()) {
 // C++ 2.5p2: Alternative tokens behave the same as its primary token
 // except for their spellings.
 Diag(MacroNameTok, getLangOpts().MicrosoftExt
? diag::ext_pp_operator_used_as_macro_name
: diag::err_pp_operator_used_as_macro_name)
 << II << MacroNameTok.getKind();
-
 // Allow #defining |and| and friends for Microsoft compatibility or
 // recovery when legacy C headers are included in C++.
-MacroNameTok.setIdentifierInfo(II);
   }
 
   if ((isDefineUndef != MU_Other) && II->getPPKeywordID() == tok::pp_defined) {
Index: cfe/trunk/lib/Lex/Preprocessor.cpp
===
--- cfe/trunk/lib/Lex/Preprocessor.cpp
+++ cfe/trunk/lib/Lex/Preprocessor.cpp
@@ -712,14 +712,6 @@
 II.setIsFutureCompatKeyword(false);
   }
 
-  // C++ 2.11p2: If this is an alternative representation of a C++ operator,
-  // then we act as if it is the actual operator and not the textual
-  // representation of it.
-  if (II.isCPlusPlusOperatorKeyword() &&
-  !(getLangOpts().MSVCCompat &&
-getSourceManager().isInSystemHeader(Identifier.getLocation(
-Identifier.setIdentifierInfo(nullptr);
-
   // If this is an extension token, diagnose its use.
   // We avoid diagnosing tokens that originate from macro definitions.
   // FIXME: This warning is disabled in cases where it shouldn't be,
Index: cfe/trunk/lib/Lex/PPExpressions.cpp
===
--- cfe/trunk/lib/Lex/PPExpressions.cpp
+++ cfe/trunk/lib/Lex/PPExpressions.cpp
@@ -237,35 +237,32 @@
 PP.setCodeCompletionReached();
 PP.LexNonComment(PeekTok);
   }
-  
-  // If this token's spelling is a pp-identifier, check to see if it is
-  // 'defined' or if it is a macro.  Note that we check here because many
-  // keywords are pp-identifiers, so we can't check the kind.
-  if (IdentifierInfo *II = PeekTok.getIdentifierInfo()) {
-// Handle "defined X" and "defined(X)".
-if (II->isStr("defined"))
-  return EvaluateDefined(Result, PeekTok, DT, ValueLive, PP);
-
-// If this identifier isn't 'defined' or one of the special
-// preprocessor keywords and it wasn't macro expanded, it turns
-// into a simple 0, unless it is the C++ keyword "true", in which case it
-// turns into "1".
-if (ValueLive &&
-II->getTokenID() != tok::kw_true &&
-II->getTokenID() != tok::kw_false)
-  PP.Diag(PeekTok, diag::warn_pp_undef_identifier) << II;
-Result.Val = II->getTokenID() == tok::kw_true;
-Result.Val.setIsUnsigned(false);  // "0" is signed intmax_t 0.
-Result.setIdentifier(II);
-Result.setRange(PeekTok.getLocation());
-DT.IncludedUndefinedIds = (II->getTokenID() != tok::kw_true &&
-   II->getTokenID() != tok::kw_false);
-PP.LexNonComment(PeekTok);
-return false;
-  }
 
   switch (PeekTok.getKind()) {
-  default:  // Non-value token.
+  default:
+// If this token's spelling is a pp-identifier, check to see if it is
+// 'defined' or if it is a macro.  Note that we check here because many
+// keywords are pp-identifiers, so we can't check the kind.
+if (IdentifierInfo *II = PeekTok.getIdentifierInfo()) {
+  // Handle "defined X" and "defined(X)".
+  if (II->isStr("defined"))
+return EvaluateDefined(Result, PeekTok, DT, ValueLive, PP);
+
+  if (!II->isCPlusPlusOperatorKeyword()) {
+// If this identifier isn't 'defined' or 

[PATCH] D34440: [Clang] Expand response files before loading compilation database

2017-07-14 Thread Vladimir Plyashkun via Phabricator via cfe-commits
vladimir.plyashkun added a comment.

Thanks @klimek for the response!
Let me give an example.
Suppose we want to check //main.cpp// by clang-tidy.
As i said before, i cannot use //CompilationDatabase.json// (due to some 
technical reasons), 
but there is way to pass all options though command line and call external 
process of clang-tidy in this way:
`clang-tidy -checks=* main.cpp -export-fixes=... --  -std=c++11 
-Ipath/to/include -Ipath/to/include2 -DMACRO `
All compiler related options appear in the command line after `--` symbol.
But due to command line length restrictions (especially on Windows OS) it's 
better to use //@ResponseFile// mechanism.
To achieve it, i've created //arguments.rsp// file with this content:
`-checks=* main.cpp -export-fixes=... --  -std=c++11 -Ipath/to/include 
-Ipath/to/include2 -DMACRO `
and tried to call clang-tidy in this way:
`clang-tidy @arguments.rsp`
But all compiler options are ignored by this call!
If you check how //CommonOptionsParser.cpp// parses command line arguments, you 
will see, that first of all, it tries to load fixed compilation database (by 
finding `--` symbol in the command line).
Only after that it calls //cl::ParseCommandLineOptions// which loads content of 
//arguments.rsp// file and parses all the rest arguments.
So, my question was why not to expand response files before loading fixed 
compilation db from command line?
Or i'm doing something wrong?


Repository:
  rL LLVM

https://reviews.llvm.org/D34440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35109: [Analyzer] SValBuilder Comparison Rearrangement

2017-07-14 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

The other possibility is to make the difference signed.


https://reviews.llvm.org/D35109



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34440: [Clang] Expand response files before loading compilation database

2017-07-14 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D34440#808156, @vladimir.plyashkun wrote:

> **To discuss:**
>  This patch is required for correct integration //Clang-Tidy// with //CLion 
> IDE//.
>  By this moment, we unable to use //CompilationDatabase.json// from //CLion 
> //side which is widely used in //Clang-Tidy// and in other common tools.
>  Anyway, there are possibility to pass compiler options directly through 
> command line.
>  But we cannot pass compiler options directly through command-line, due to 
> command-line-length restrictions.
>  So, we decided to pass compiler options through //@ResponseFile //mechanism.
>  But there are some problems with this approach.
>  Before this patch, ///clang/lib/Tooling/CommonOptionsParser.cpp// worked in 
> this way:
>
> 1. Load compilation database from command-line
> 2. Expand response files
> 3. Parse all other command line arguments I think it's strange behavior? Why 
> we try to load compilation database first? Maybe it's better to expand 
> response files and only after that try to load compilation database and parse 
> another options? It's hard to refactor //cl::ParseCommandLineOptions// and 
> //cl::ExpandResponseFiles// functions, due to high number of usages, so i 
> copied some block directly into 
> ///clang/lib/Tooling/CommonOptionsParser.cpp// I don't think that is a best 
> solution, but i don't have another one.


I don't fully understand the problem yet, especially what you mean with "expand 
response files first".
Generally, the fixed-compilation-db mechanism is there so you can pass a single 
command line that will be used by all translation units - the response files in 
that command line would be expanded each time we run a tool on some TU. That 
seems in line with the design.
Can you post an example of what you're trying to do and what error message you 
get?


Repository:
  rL LLVM

https://reviews.llvm.org/D34440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34267: do more processing in clang-fuzzer (use EmitAssemblyAction)

2017-07-14 Thread Manuel Klimek via Phabricator via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

lg


https://reviews.llvm.org/D34267



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26350: Keep invalid Switch in the AST

2017-07-14 Thread Olivier Goffart via Phabricator via cfe-commits
ogoffart added a comment.

re-ping


https://reviews.llvm.org/D26350



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >