[PATCH] D39279: Stringizing raw string literals containing newline

2017-10-25 Thread Taewook Oh via Phabricator via cfe-commits
twoh updated this revision to Diff 120195.
twoh added a comment.

clang-format


https://reviews.llvm.org/D39279

Files:
  lib/Lex/Lexer.cpp
  test/Preprocessor/macro_raw_string.cpp
  unittests/Lex/LexerTest.cpp

Index: unittests/Lex/LexerTest.cpp
===
--- unittests/Lex/LexerTest.cpp
+++ unittests/Lex/LexerTest.cpp
@@ -37,7 +37,7 @@
   DiagID(new DiagnosticIDs()),
   Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
   SourceMgr(Diags, FileMgr),
-  TargetOpts(new TargetOptions) 
+  TargetOpts(new TargetOptions)
   {
 TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
 Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
@@ -478,4 +478,18 @@
   EXPECT_TRUE(LexedTokens.empty());
 }
 
+TEST_F(LexerTest, StringizingRasString) {
+  std::string String1 = R"(foo
+{"bar":[]}
+baz)";
+  SmallString<128> String2;
+  String2 += String1.c_str();
+
+  String1 = Lexer::Stringify(StringRef(String1));
+  Lexer::Stringify(String2);
+
+  EXPECT_EQ(String1, R"(foo\n{\"bar\":[]}\nbaz)");
+  EXPECT_EQ(String2, R"(foo\n{\"bar\":[]}\nbaz)");
+}
+
 } // anonymous namespace
Index: test/Preprocessor/macro_raw_string.cpp
===
--- /dev/null
+++ test/Preprocessor/macro_raw_string.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -E -std=c++11 %s -o %t
+// RUN: %clang_cc1 %t
+
+#define FOO(str) foo(#str)
+
+extern void foo(const char *str);
+
+void bar() {
+  FOO(R"(foo
+bar)");
+}
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -210,26 +210,47 @@
 }
 
 /// Stringify - Convert the specified string into a C string, with surrounding
-/// ""'s, and with escaped \ and " characters.
+/// ""'s, and with escaped \ and " characters. The function replaces each
+/// newline character with the "\n" escape code as well.
 std::string Lexer::Stringify(StringRef Str, bool Charify) {
   std::string Result = Str;
   char Quote = Charify ? '\'' : '"';
-  for (unsigned i = 0, e = Result.size(); i != e; ++i) {
+  for (unsigned i = 0, e = Result.size(); i < e; ++i) {
 if (Result[i] == '\\' || Result[i] == Quote) {
-  Result.insert(Result.begin()+i, '\\');
-  ++i; ++e;
+  Result.insert(Result.begin() + i, '\\');
+  ++i;
+  ++e;
+} else if (auto Size = getEscapedNewLineSize(Result.substr(i).data())) {
+  Result.erase(Result.begin() + i, Result.begin() + i + Size);
+  Result.insert(Result.begin() + i, '\\');
+  Result.insert(Result.begin() + i + 1, 'n');
+  i += 2;
+  e += (2 - Size);
 }
   }
   return Result;
 }
 
 /// Stringify - Convert the specified string into a C string by escaping '\'
-/// and " characters.  This does not add surrounding ""'s to the string.
+/// and " characters. The function replaces each newline character with the
+/// "\n" escape code as well. This does not add surrounding ""'s to the string.
 void Lexer::Stringify(SmallVectorImpl &Str) {
-  for (unsigned i = 0, e = Str.size(); i != e; ++i) {
+  for (unsigned i = 0, e = Str.size(); i < e; ++i) {
 if (Str[i] == '\\' || Str[i] == '"') {
-  Str.insert(Str.begin()+i, '\\');
-  ++i; ++e;
+  Str.insert(Str.begin() + i, '\\');
+  ++i;
+  ++e;
+} else if (Str[i] == '\n' || Str[i] == '\r') {
+  unsigned Size = 1;
+  if ((i < e - 1) && (Str[i + 1] == '\n' || Str[i + 1] == '\r') &&
+  Str[i] != Str[i + 1])
+Size += 1;
+
+  Str.erase(Str.begin() + i, Str.begin() + i + Size);
+  Str.insert(Str.begin() + i, '\\');
+  Str.insert(Str.begin() + i + 1, 'n');
+  i += 2;
+  e += (2 - Size);
 }
   }
 }
@@ -367,7 +388,7 @@
 /// to point to a constant buffer with the data already in it (avoiding a
 /// copy).  The caller is not allowed to modify the returned buffer pointer
 /// if an internal buffer is returned.
-unsigned Lexer::getSpelling(const Token &Tok, const char *&Buffer, 
+unsigned Lexer::getSpelling(const Token &Tok, const char *&Buffer,
 const SourceManager &SourceMgr,
 const LangOptions &LangOpts, bool *Invalid) {
   assert((int)Tok.getLength() >= 0 && "Token character range is bogus!");
@@ -592,17 +613,17 @@
   if (TheTok.getKind() == tok::eof) {
 break;
   }
-  
+
   // If we haven't hit the end of the preprocessor directive, skip this
   // token.
   if (!TheTok.isAtStartOfLine())
 continue;
-
+
   // We've passed the end of the preprocessor directive, and will look
   // at this token again below.
   InPreprocessorDirective = false;
 }
-
+
 // Keep track of the # of lines in the preamble.
 if (TheTok.isAtStartOfLine()) {
   unsigned TokOffset = TheTok.getLocation().getRawEncoding() - StartOffset;
@@ -619,13 +640,13 @@
 ActiveCommentLoc = TheTok

[PATCH] D39241: [clang-rename] Fix and enable the failing TemplatedClassFunction test.

2017-10-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 120199.
hokein added a comment.

improve the code and add more tests.


https://reviews.llvm.org/D39241

Files:
  lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
  test/clang-rename/TemplatedClassFunction.cpp


Index: test/clang-rename/TemplatedClassFunction.cpp
===
--- test/clang-rename/TemplatedClassFunction.cpp
+++ test/clang-rename/TemplatedClassFunction.cpp
@@ -6,17 +6,22 @@
 
 int main(int argc, char **argv) {
   A a;
-  a.foo();   /* Test 2 */ // CHECK: a.bar()   /* Test 2 */
+  A b;
+  A c;
+  a.foo();   /* Test 2 */ // CHECK: a.bar();   /* Test 2 */
+  b.foo();   /* Test 3 */ // CHECK: b.bar();   /* Test 3 */
+  c.foo();   /* Test 4 */ // CHECK: c.bar();   /* Test 4 */
   return 0;
 }
 
 // Test 1.
-// RUN: clang-refactor rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' 
| FileCheck %s
+// RUN: clang-rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
 // Test 2.
-// RUN: clang-refactor rename -offset=162 -new-name=bar %s -- | sed 's,//.*,,' 
| FileCheck %s
-//
-// Currently unsupported test.
-// XFAIL: *
+// RUN: clang-rename -offset=191 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=255 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
+// Test 4.
+// RUN: clang-rename -offset=319 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
 
 // To find offsets after modifying the file, use:
 //   grep -Ubo 'foo.*' 
Index: lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
===
--- lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -73,6 +73,7 @@
 if (checkIfOverriddenFunctionAscends(OverriddenMethod))
   USRSet.insert(getUSRForDecl(OverriddenMethod));
   }
+  addUSRsOfInstantiatedMethods(MethodDecl);
 } else if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
   handleCXXRecordDecl(RecordDecl);
 } else if (const auto *TemplateDecl =
@@ -84,9 +85,13 @@
 return std::vector(USRSet.begin(), USRSet.end());
   }
 
+  bool shouldVisitTemplateInstantiations() const { return true; }
+
   bool VisitCXXMethodDecl(const CXXMethodDecl *MethodDecl) {
 if (MethodDecl->isVirtual())
   OverriddenMethods.push_back(MethodDecl);
+if (MethodDecl->getInstantiatedFromMemberFunction())
+  InstantiatedMethods.push_back(MethodDecl);
 return true;
   }
 
@@ -137,6 +142,20 @@
   addUSRsOfOverridenFunctions(OverriddenMethod);
   }
 
+  void addUSRsOfInstantiatedMethods(const CXXMethodDecl *MethodDecl) {
+// For renaming a class template method, all references of the instantiated
+// member methods should be renamed too, so add USRs of the instantiated
+// methods to the USR set.
+USRSet.insert(getUSRForDecl(MethodDecl));
+if (const auto *FT = MethodDecl->getInstantiatedFromMemberFunction())
+  USRSet.insert(getUSRForDecl(FT));
+for (const auto *Method : InstantiatedMethods) {
+  if (USRSet.find(getUSRForDecl(
+  Method->getInstantiatedFromMemberFunction())) != USRSet.end())
+USRSet.insert(getUSRForDecl(Method));
+}
+  }
+
   bool checkIfOverriddenFunctionAscends(const CXXMethodDecl *MethodDecl) {
 for (const auto &OverriddenMethod : MethodDecl->overridden_methods()) {
   if (USRSet.find(getUSRForDecl(OverriddenMethod)) != USRSet.end())
@@ -150,6 +169,7 @@
   ASTContext &Context;
   std::set USRSet;
   std::vector OverriddenMethods;
+  std::vector InstantiatedMethods;
   std::vector PartialSpecs;
 };
 } // namespace


Index: test/clang-rename/TemplatedClassFunction.cpp
===
--- test/clang-rename/TemplatedClassFunction.cpp
+++ test/clang-rename/TemplatedClassFunction.cpp
@@ -6,17 +6,22 @@
 
 int main(int argc, char **argv) {
   A a;
-  a.foo();   /* Test 2 */ // CHECK: a.bar()   /* Test 2 */
+  A b;
+  A c;
+  a.foo();   /* Test 2 */ // CHECK: a.bar();   /* Test 2 */
+  b.foo();   /* Test 3 */ // CHECK: b.bar();   /* Test 3 */
+  c.foo();   /* Test 4 */ // CHECK: c.bar();   /* Test 4 */
   return 0;
 }
 
 // Test 1.
-// RUN: clang-refactor rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
+// RUN: clang-rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
 // Test 2.
-// RUN: clang-refactor rename -offset=162 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
-//
-// Currently unsupported test.
-// XFAIL: *
+// RUN: clang-rename -offset=191 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=255 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
+// Test 4.
+// RUN: clang-rename -offset=319 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
 
 // To find offsets after modifying the file, use:
 //   grep -Ubo 'foo.*' 
Index: lib/Tooli

[PATCH] D39224: Moved QualTypeNames.h from Tooling to AST.

2017-10-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In https://reviews.llvm.org/D39224#905431, @rnk wrote:

> Can you remind me why `NamedDecl::printQualifiedName` is not appropriate for 
> your needs?


The use-case in code completion (see https://reviews.llvm.org/D38538,  the 
interesting bit is in `SemaCodeComplete.cpp`) creates a `QualType` that is 
being pretty-printed later on.
There does not seem to be a way to rewrite it to use `printQualifiedName`for 
that particular case without messing up the code. I was initially planning to 
simply create `ElaborateType` with proper `NestedNameSpecifier`, but that's 
essentially what the code in `QualTypeNames`  does already (it has logic to 
create both the `NestedNameSpecifier` and `ElaboratedType` out of it), so we 
should definitely reuse it.

In general, helpers like this look somewhat useful when writing features that 
present code to the user and the usage in `SemaCodeComplete` feels natural, at 
least from my perspective.


https://reviews.llvm.org/D39224



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


[libunwind] r316559 - Fix the context/cursor size for ARM with WMMX enabled

2017-10-25 Thread Martin Storsjo via cfe-commits
Author: mstorsjo
Date: Wed Oct 25 01:07:19 2017
New Revision: 316559

URL: http://llvm.org/viewvc/llvm-project?rev=316559&view=rev
Log:
Fix the context/cursor size for ARM with WMMX enabled

This was missed in SVN r274744 when the WMMX part was made optional;
when made optional, some struct fields were reordered, which caused
the total struct size to grow due to padding/alignment.

Modified:
libunwind/trunk/include/__libunwind_config.h

Modified: libunwind/trunk/include/__libunwind_config.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/include/__libunwind_config.h?rev=316559&r1=316558&r2=316559&view=diff
==
--- libunwind/trunk/include/__libunwind_config.h (original)
+++ libunwind/trunk/include/__libunwind_config.h Wed Oct 25 01:07:19 2017
@@ -39,8 +39,8 @@
 # elif defined(__arm__)
 #  define _LIBUNWIND_TARGET_ARM 1
 #  if defined(__ARM_WMMX)
-#define _LIBUNWIND_CONTEXT_SIZE 60
-#define _LIBUNWIND_CURSOR_SIZE 67
+#define _LIBUNWIND_CONTEXT_SIZE 61
+#define _LIBUNWIND_CURSOR_SIZE 68
 #  else
 #define _LIBUNWIND_CONTEXT_SIZE 42
 #define _LIBUNWIND_CURSOR_SIZE 49


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


[PATCH] D38939: [clangd] Handle exit notification (proper shutdown)

2017-10-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In https://reviews.llvm.org/D38939#904318, @rwols wrote:

> I'll have to think about if I want that responsibility!


While you're at it, I'll submit this patch for you. But I'd definitely 
encourage you to get commit access. You've been contributing a bunch of useful 
stuff to clangd (BTW, thanks for the contributions!)


https://reviews.llvm.org/D38939



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


r316561 - [clang-rename] Fix and enable the failing TemplatedClassFunction test.

2017-10-25 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Oct 25 01:25:25 2017
New Revision: 316561

URL: http://llvm.org/viewvc/llvm-project?rev=316561&view=rev
Log:
[clang-rename] Fix and enable the failing TemplatedClassFunction test.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
cfe/trunk/test/clang-rename/TemplatedClassFunction.cpp

Modified: cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp?rev=316561&r1=316560&r2=316561&view=diff
==
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp Wed Oct 25 
01:25:25 2017
@@ -73,6 +73,7 @@ public:
 if (checkIfOverriddenFunctionAscends(OverriddenMethod))
   USRSet.insert(getUSRForDecl(OverriddenMethod));
   }
+  addUSRsOfInstantiatedMethods(MethodDecl);
 } else if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
   handleCXXRecordDecl(RecordDecl);
 } else if (const auto *TemplateDecl =
@@ -84,9 +85,13 @@ public:
 return std::vector(USRSet.begin(), USRSet.end());
   }
 
+  bool shouldVisitTemplateInstantiations() const { return true; }
+
   bool VisitCXXMethodDecl(const CXXMethodDecl *MethodDecl) {
 if (MethodDecl->isVirtual())
   OverriddenMethods.push_back(MethodDecl);
+if (MethodDecl->getInstantiatedFromMemberFunction())
+  InstantiatedMethods.push_back(MethodDecl);
 return true;
   }
 
@@ -137,6 +142,20 @@ private:
   addUSRsOfOverridenFunctions(OverriddenMethod);
   }
 
+  void addUSRsOfInstantiatedMethods(const CXXMethodDecl *MethodDecl) {
+// For renaming a class template method, all references of the instantiated
+// member methods should be renamed too, so add USRs of the instantiated
+// methods to the USR set.
+USRSet.insert(getUSRForDecl(MethodDecl));
+if (const auto *FT = MethodDecl->getInstantiatedFromMemberFunction())
+  USRSet.insert(getUSRForDecl(FT));
+for (const auto *Method : InstantiatedMethods) {
+  if (USRSet.find(getUSRForDecl(
+  Method->getInstantiatedFromMemberFunction())) != USRSet.end())
+USRSet.insert(getUSRForDecl(Method));
+}
+  }
+
   bool checkIfOverriddenFunctionAscends(const CXXMethodDecl *MethodDecl) {
 for (const auto &OverriddenMethod : MethodDecl->overridden_methods()) {
   if (USRSet.find(getUSRForDecl(OverriddenMethod)) != USRSet.end())
@@ -150,6 +169,7 @@ private:
   ASTContext &Context;
   std::set USRSet;
   std::vector OverriddenMethods;
+  std::vector InstantiatedMethods;
   std::vector PartialSpecs;
 };
 } // namespace

Modified: cfe/trunk/test/clang-rename/TemplatedClassFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/clang-rename/TemplatedClassFunction.cpp?rev=316561&r1=316560&r2=316561&view=diff
==
--- cfe/trunk/test/clang-rename/TemplatedClassFunction.cpp (original)
+++ cfe/trunk/test/clang-rename/TemplatedClassFunction.cpp Wed Oct 25 01:25:25 
2017
@@ -6,17 +6,22 @@ public:
 
 int main(int argc, char **argv) {
   A a;
-  a.foo();   /* Test 2 */ // CHECK: a.bar()   /* Test 2 */
+  A b;
+  A c;
+  a.foo();   /* Test 2 */ // CHECK: a.bar();   /* Test 2 */
+  b.foo();   /* Test 3 */ // CHECK: b.bar();   /* Test 3 */
+  c.foo();   /* Test 4 */ // CHECK: c.bar();   /* Test 4 */
   return 0;
 }
 
 // Test 1.
-// RUN: clang-refactor rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' 
| FileCheck %s
+// RUN: clang-rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
 // Test 2.
-// RUN: clang-refactor rename -offset=162 -new-name=bar %s -- | sed 's,//.*,,' 
| FileCheck %s
-//
-// Currently unsupported test.
-// XFAIL: *
+// RUN: clang-rename -offset=191 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=255 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
+// Test 4.
+// RUN: clang-rename -offset=319 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
 
 // To find offsets after modifying the file, use:
 //   grep -Ubo 'foo.*' 


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


[PATCH] D39241: [clang-rename] Fix and enable the failing TemplatedClassFunction test.

2017-10-25 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316561: [clang-rename] Fix and enable the failing 
TemplatedClassFunction test. (authored by hokein).

Repository:
  rL LLVM

https://reviews.llvm.org/D39241

Files:
  cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
  cfe/trunk/test/clang-rename/TemplatedClassFunction.cpp


Index: cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
===
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -73,6 +73,7 @@
 if (checkIfOverriddenFunctionAscends(OverriddenMethod))
   USRSet.insert(getUSRForDecl(OverriddenMethod));
   }
+  addUSRsOfInstantiatedMethods(MethodDecl);
 } else if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
   handleCXXRecordDecl(RecordDecl);
 } else if (const auto *TemplateDecl =
@@ -84,9 +85,13 @@
 return std::vector(USRSet.begin(), USRSet.end());
   }
 
+  bool shouldVisitTemplateInstantiations() const { return true; }
+
   bool VisitCXXMethodDecl(const CXXMethodDecl *MethodDecl) {
 if (MethodDecl->isVirtual())
   OverriddenMethods.push_back(MethodDecl);
+if (MethodDecl->getInstantiatedFromMemberFunction())
+  InstantiatedMethods.push_back(MethodDecl);
 return true;
   }
 
@@ -137,6 +142,20 @@
   addUSRsOfOverridenFunctions(OverriddenMethod);
   }
 
+  void addUSRsOfInstantiatedMethods(const CXXMethodDecl *MethodDecl) {
+// For renaming a class template method, all references of the instantiated
+// member methods should be renamed too, so add USRs of the instantiated
+// methods to the USR set.
+USRSet.insert(getUSRForDecl(MethodDecl));
+if (const auto *FT = MethodDecl->getInstantiatedFromMemberFunction())
+  USRSet.insert(getUSRForDecl(FT));
+for (const auto *Method : InstantiatedMethods) {
+  if (USRSet.find(getUSRForDecl(
+  Method->getInstantiatedFromMemberFunction())) != USRSet.end())
+USRSet.insert(getUSRForDecl(Method));
+}
+  }
+
   bool checkIfOverriddenFunctionAscends(const CXXMethodDecl *MethodDecl) {
 for (const auto &OverriddenMethod : MethodDecl->overridden_methods()) {
   if (USRSet.find(getUSRForDecl(OverriddenMethod)) != USRSet.end())
@@ -150,6 +169,7 @@
   ASTContext &Context;
   std::set USRSet;
   std::vector OverriddenMethods;
+  std::vector InstantiatedMethods;
   std::vector PartialSpecs;
 };
 } // namespace
Index: cfe/trunk/test/clang-rename/TemplatedClassFunction.cpp
===
--- cfe/trunk/test/clang-rename/TemplatedClassFunction.cpp
+++ cfe/trunk/test/clang-rename/TemplatedClassFunction.cpp
@@ -6,17 +6,22 @@
 
 int main(int argc, char **argv) {
   A a;
-  a.foo();   /* Test 2 */ // CHECK: a.bar()   /* Test 2 */
+  A b;
+  A c;
+  a.foo();   /* Test 2 */ // CHECK: a.bar();   /* Test 2 */
+  b.foo();   /* Test 3 */ // CHECK: b.bar();   /* Test 3 */
+  c.foo();   /* Test 4 */ // CHECK: c.bar();   /* Test 4 */
   return 0;
 }
 
 // Test 1.
-// RUN: clang-refactor rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' 
| FileCheck %s
+// RUN: clang-rename -offset=48 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
 // Test 2.
-// RUN: clang-refactor rename -offset=162 -new-name=bar %s -- | sed 's,//.*,,' 
| FileCheck %s
-//
-// Currently unsupported test.
-// XFAIL: *
+// RUN: clang-rename -offset=191 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
+// Test 3.
+// RUN: clang-rename -offset=255 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
+// Test 4.
+// RUN: clang-rename -offset=319 -new-name=bar %s -- | sed 's,//.*,,' | 
FileCheck %s
 
 // To find offsets after modifying the file, use:
 //   grep -Ubo 'foo.*' 


Index: cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
===
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
@@ -73,6 +73,7 @@
 if (checkIfOverriddenFunctionAscends(OverriddenMethod))
   USRSet.insert(getUSRForDecl(OverriddenMethod));
   }
+  addUSRsOfInstantiatedMethods(MethodDecl);
 } else if (const auto *RecordDecl = dyn_cast(FoundDecl)) {
   handleCXXRecordDecl(RecordDecl);
 } else if (const auto *TemplateDecl =
@@ -84,9 +85,13 @@
 return std::vector(USRSet.begin(), USRSet.end());
   }
 
+  bool shouldVisitTemplateInstantiations() const { return true; }
+
   bool VisitCXXMethodDecl(const CXXMethodDecl *MethodDecl) {
 if (MethodDecl->isVirtual())
   OverriddenMethods.push_back(MethodDecl);
+if (MethodDecl->getInstantiatedFromMemberFunction())
+  InstantiatedMethods.push_back(MethodDecl);
 return true;
   }
 
@@ -137,6 +142,20 @@
   addUSRsOfOverridenFunctions(Overridd

[PATCH] D39280: [libunwind] Use uint64_t for unw_word_t in ARM EHABI

2017-10-25 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
Herald added subscribers: kristof.beyls, aprantl, aemerson.

This reduces the differences between the EHABI and DWARF cases.

This allows getting rid of some casts in _LIBUNWIND_TRACE_API log lines, making 
them match what's in UnwindLevel1.c for DWARF.

The only non-obvious detail is in _Unwind_VRS_Get_Internal (called via 
_Unwind_VRS_Get), where a void pointer is assumed to be uint32_t or uintptr_t 
(depending on the caller); this can no longer use unw_word_t directly as before.


https://reviews.llvm.org/D39280

Files:
  include/__libunwind_config.h
  include/libunwind.h
  src/Unwind-EHABI.cpp

Index: src/Unwind-EHABI.cpp
===
--- src/Unwind-EHABI.cpp
+++ src/Unwind-EHABI.cpp
@@ -14,6 +14,7 @@
 
 #if defined(_LIBUNWIND_ARM_EHABI)
 
+#include 
 #include 
 #include 
 #include 
@@ -468,11 +469,11 @@
   unw_word_t pc;
   unw_get_reg(cursor, UNW_REG_IP, &pc);
   _LIBUNWIND_TRACE_UNWINDING(
-  "unwind_phase1(ex_ojb=%p): pc=0x%llX, start_ip=0x%llX, func=%s, "
-  "lsda=0x%llX, personality=0x%llX",
-  static_cast(exception_object), (long long)pc,
-  (long long)frameInfo.start_ip, functionName,
-  (long long)frameInfo.lsda, (long long)frameInfo.handler);
+  "unwind_phase1(ex_ojb=%p): pc=0x%" PRIX64 ", start_ip=0x%" PRIX64 " func=%s, "
+  "lsda=0x" PRIX64 ", personality=0x" PRIX64 "",
+  static_cast(exception_object), pc,
+  frameInfo.start_ip, functionName,
+  frameInfo.lsda, frameInfo.handler);
 }
 
 // If there is a personality routine, ask it if it will want to stop at
@@ -584,11 +585,11 @@
   (frameInfo.start_ip + offset > frameInfo.end_ip))
 functionName = ".anonymous.";
   _LIBUNWIND_TRACE_UNWINDING(
-  "unwind_phase2(ex_ojb=%p): start_ip=0x%llX, func=%s, sp=0x%llX, "
-  "lsda=0x%llX, personality=0x%llX",
-  static_cast(exception_object), (long long)frameInfo.start_ip,
-  functionName, (long long)sp, (long long)frameInfo.lsda,
-  (long long)frameInfo.handler);
+  "unwind_phase2(ex_ojb=%p): start_ip=0x%" PRIX64 " func=%s, sp=0x%" PRIX64 ", "
+  "lsda=0x%" PRIX64 ", personality=0x%" PRIX64 "",
+  static_cast(exception_object), frameInfo.start_ip,
+  functionName, sp, frameInfo.lsda,
+  frameInfo.handler);
 }
 
 // If there is a personality routine, tell it we are unwinding.
@@ -627,9 +628,9 @@
   unw_get_reg(cursor, UNW_REG_IP, &pc);
   unw_get_reg(cursor, UNW_REG_SP, &sp);
   _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): re-entering "
- "user code with ip=0x%llX, sp=0x%llX",
+ "user code with ip=0x%" PRIX64 ", sp=0x%" PRIX64 "",
  static_cast(exception_object),
- (long long)pc, (long long)sp);
+ pc, sp);
 }
 
 {
@@ -727,8 +728,8 @@
   if (unw_get_proc_info(cursor, &frameInfo) == UNW_ESUCCESS)
 result = (uintptr_t)frameInfo.lsda;
   _LIBUNWIND_TRACE_API(
-  "_Unwind_GetLanguageSpecificData(context=%p) => 0x%llx",
-  static_cast(context), (long long)result);
+  "_Unwind_GetLanguageSpecificData(context=%p) => 0x%" PRIx64 "",
+  static_cast(context), result);
   return result;
 }
 
@@ -765,7 +766,7 @@
   if (representation != _UVRSD_UINT32 || regno > 15)
 return _UVRSR_FAILED;
   return unw_set_reg(cursor, (unw_regnum_t)(UNW_ARM_R0 + regno),
- *(unw_word_t *)valuep) == UNW_ESUCCESS
+ *(uintptr_t *)valuep) == UNW_ESUCCESS
  ? _UVRSR_OK
  : _UVRSR_FAILED;
 case _UVRSC_VFP:
@@ -789,7 +790,7 @@
   if (representation != _UVRSD_UINT32 || regno > 3)
 return _UVRSR_FAILED;
   return unw_set_reg(cursor, (unw_regnum_t)(UNW_ARM_WC0 + regno),
- *(unw_word_t *)valuep) == UNW_ESUCCESS
+ *(uintptr_t *)valuep) == UNW_ESUCCESS
  ? _UVRSR_OK
  : _UVRSR_FAILED;
 case _UVRSC_WMMXD:
@@ -814,14 +815,18 @@
  _Unwind_VRS_DataRepresentation representation,
  void *valuep) {
   unw_cursor_t *cursor = (unw_cursor_t *)context;
+  unw_word_t word;
+  _Unwind_VRS_Result ret;
   switch (regclass) {
 case _UVRSC_CORE:
   if (representation != _UVRSD_UINT32 || regno > 15)
 return _UVRSR_FAILED;
-  return unw_get_reg(cursor, (unw_regnum_t)(UNW_ARM_R0 + regno),
- (unw_word_t *)valuep) == UNW_ESUCCESS
+  ret = unw_get_reg(cursor, (unw_regnum_t)(UNW_ARM_R0 + regno),
+ &word) == UNW_ESUCCESS
  ? _UVRSR_OK
  : _UVRSR_FAILED;
+  *(uintptr_t *)valuep = word;
+  

[PATCH] D39251: [libunwind] Fix building for ARM with dwarf exception handling

2017-10-25 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added inline comments.



Comment at: src/UnwindLevel1.c:79
   _LIBUNWIND_TRACE_UNWINDING(
   "unwind_phase1(ex_ojb=%p): pc=0x%" PRIx64 ", start_ip=0x%" PRIx64
   ", func=%s, lsda=0x%" PRIx64 ", personality=0x%" PRIx64 "",

mstorsjo wrote:
> compnerd wrote:
> > Please convert these to `%p` instead.  The casting and conversion is kinda 
> > ... unnecessary.
> Using `%p` wouldn't work when on 32 bit systems currently, while most of 
> these fields are defined to be `uint64_t` except for the arm ehabi case. I 
> guess I could look at how hard it would be to switch it to uint64_t for the 
> arm/dwarf case as well.
This part can be avoided if we consistently use unw_word_t == uint64_t, as done 
in D39280.


https://reviews.llvm.org/D39251



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


[PATCH] D39281: [libunwind] Express Registers_*::lastDwarfReg using _LIBUNWIND_HIGHEST_DWARF_REGISTER

2017-10-25 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.

This avoids having to keep the same information duplicated in multiple places.


https://reviews.llvm.org/D39281

Files:
  src/Registers.hpp


Index: src/Registers.hpp
===
--- src/Registers.hpp
+++ src/Registers.hpp
@@ -44,7 +44,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 8; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 
1; }
 
   uint32_t  getSP() const  { return _registers.__esp; }
   void  setSP(uint32_t value)  { _registers.__esp = value; }
@@ -250,7 +250,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 16; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 
1; }
 
   uint64_t  getSP() const  { return _registers.__rsp; }
   void  setSP(uint64_t value)  { _registers.__rsp = value; }
@@ -500,7 +500,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 112; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 
1; }
 
   uint64_t  getSP() const { return _registers.__r1; }
   void  setSP(uint32_t value) { _registers.__r1 = value; }
@@ -1066,7 +1066,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 95; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 
1; }
 
   uint64_t  getSP() const { return _registers.__sp; }
   void  setSP(uint64_t value) { _registers.__sp = value; }
@@ -1815,7 +1815,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 31; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 
1; }
 
   uint64_t  getSP() const { return _registers.__r[1]; }
   void  setSP(uint32_t value) { _registers.__r[1] = value; }


Index: src/Registers.hpp
===
--- src/Registers.hpp
+++ src/Registers.hpp
@@ -44,7 +44,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 8; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; }
 
   uint32_t  getSP() const  { return _registers.__esp; }
   void  setSP(uint32_t value)  { _registers.__esp = value; }
@@ -250,7 +250,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 16; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; }
 
   uint64_t  getSP() const  { return _registers.__rsp; }
   void  setSP(uint64_t value)  { _registers.__rsp = value; }
@@ -500,7 +500,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 112; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; }
 
   uint64_t  getSP() const { return _registers.__r1; }
   void  setSP(uint32_t value) { _registers.__r1 = value; }
@@ -1066,7 +1066,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 95; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; }
 
   uint64_t  getSP() const { return _registers.__sp; }
   void  setSP(uint64_t value) { _registers.__sp = value; }
@@ -1815,7 +1815,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 31; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER - 1; }
 
   uint64_t  getSP() const { return _registers.__r[1]; }
   void  setSP(uint32_t value) { _registers.__r[1] = value; }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39251: [libunwind] Fix building for ARM with dwarf exception handling

2017-10-25 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added inline comments.



Comment at: src/Registers.hpp:1342
   }
+  static int  lastDwarfRegNum() { return 287; }
 

mstorsjo wrote:
> compnerd wrote:
> > Can we not use `_LIBUNWIND_HIGHEST_DWARF_REGISTER` here?
> I guess we could - we could do that consistently throughout all the 
> `Registers_*` classes then. Or even omit the method at all and just check 
> `_LIBUNWIND_HIGHEST_DWARF_REGISTER` in the caller? Or perhaps the last part 
> clashes with part of the (incomplete afaik?) intended design to support 
> unwinding foreign systems as well.
This gets taken care of for the existing ones in D39281 - if that one goes 
through I'll update this patch accordingly.


https://reviews.llvm.org/D39251



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


[clang-tools-extra] r316564 - [clangd] Handle exit notification (proper shutdown)

2017-10-25 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Oct 25 01:45:41 2017
New Revision: 316564

URL: http://llvm.org/viewvc/llvm-project?rev=316564&view=rev
Log:
[clangd] Handle exit notification (proper shutdown)

Summary:
This changes the onShutdown handler to do essentially nothing (for now), and
instead exits the runloop when we receive the exit notification from the client.

Some clients may wait on the reply from the shutdown request before sending an
exit notification. If we exit the runloop already in the shutdown request, a
client might block forever.

This also gives us the opportunity to do any global cleanups and/or
serializations of PCH preambles to disk, but I've left that out for now.

See the LSP protocol documentation for details.

Reviewers: malaperle, krasimir, bkramer, sammccall, ilya-biryukov

Reviewed By: malaperle, sammccall, ilya-biryukov

Subscribers: cfe-commits

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

Added:
clang-tools-extra/trunk/test/clangd/shutdown-with-exit.test
clang-tools-extra/trunk/test/clangd/shutdown-without-exit.test
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
clang-tools-extra/trunk/test/clangd/authority-less-uri.test
clang-tools-extra/trunk/test/clangd/completion-priorities.test
clang-tools-extra/trunk/test/clangd/completion-qualifiers.test
clang-tools-extra/trunk/test/clangd/completion-snippet.test
clang-tools-extra/trunk/test/clangd/completion.test
clang-tools-extra/trunk/test/clangd/definitions.test
clang-tools-extra/trunk/test/clangd/diagnostics-preamble.test
clang-tools-extra/trunk/test/clangd/diagnostics.test
clang-tools-extra/trunk/test/clangd/did-change-watch-files.test
clang-tools-extra/trunk/test/clangd/extra-flags.test
clang-tools-extra/trunk/test/clangd/fixits.test
clang-tools-extra/trunk/test/clangd/formatting.test
clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test
clang-tools-extra/trunk/test/clangd/initialize-params.test
clang-tools-extra/trunk/test/clangd/input-mirror.test
clang-tools-extra/trunk/test/clangd/protocol.test
clang-tools-extra/trunk/test/clangd/signature-help.test
clang-tools-extra/trunk/test/clangd/unsupported-method.test

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=316564&r1=316563&r2=316564&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Oct 25 01:45:41 2017
@@ -56,9 +56,13 @@ void ClangdLSPServer::onInitialize(Ctx C
 }
 
 void ClangdLSPServer::onShutdown(Ctx C, ShutdownParams &Params) {
-  IsDone = true;
+  // Do essentially nothing, just say we're ready to exit.
+  ShutdownRequestReceived = true;
+  C.reply("null");
 }
 
+void ClangdLSPServer::onExit(Ctx C, ExitParams &Params) { IsDone = true; }
+
 void ClangdLSPServer::onDocumentDidOpen(Ctx C,
 DidOpenTextDocumentParams &Params) {
   if (Params.metadata && !Params.metadata->extraFlags.empty())
@@ -197,7 +201,7 @@ ClangdLSPServer::ClangdLSPServer(JSONOut
  /*EnableSnippetsAndCodePatterns=*/SnippetCompletions),
  /*Logger=*/Out, ResourceDir) {}
 
-void ClangdLSPServer::run(std::istream &In) {
+bool ClangdLSPServer::run(std::istream &In) {
   assert(!IsDone && "Run was called before");
 
   // Set up JSONRPCDispatcher.
@@ -213,6 +217,8 @@ void ClangdLSPServer::run(std::istream &
   // Make sure IsDone is set to true after this method exits to ensure 
assertion
   // at the start of the method fires if it's ever executed again.
   IsDone = true;
+
+  return ShutdownRequestReceived;
 }
 
 std::vector

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=316564&r1=316563&r2=316564&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Wed Oct 25 01:45:41 2017
@@ -39,7 +39,9 @@ public:
   /// opened in binary mode. Output will be written using Out variable passed 
to
   /// class constructor. This method must not be executed more than once for
   /// each instance of ClangdLSPServer.
-  void run(std::istream &In);
+  ///
+  /// \return Wether we received a 'shutdown' request before an 'exit' request
+  bool run(std::istream &In);
 
 private:
   // Implement DiagnosticsConsumer.
@@ -50,6 +52,7 @@ private:
   // Implement ProtocolCallbac

[PATCH] D38939: [clangd] Handle exit notification (proper shutdown)

2017-10-25 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316564: [clangd] Handle exit notification (proper shutdown) 
(authored by ibiryukov).

Changed prior to commit:
  https://reviews.llvm.org/D38939?vs=119941&id=120210#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38939

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/ClangdLSPServer.h
  clang-tools-extra/trunk/clangd/Protocol.h
  clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
  clang-tools-extra/trunk/clangd/ProtocolHandlers.h
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
  clang-tools-extra/trunk/test/clangd/authority-less-uri.test
  clang-tools-extra/trunk/test/clangd/completion-priorities.test
  clang-tools-extra/trunk/test/clangd/completion-qualifiers.test
  clang-tools-extra/trunk/test/clangd/completion-snippet.test
  clang-tools-extra/trunk/test/clangd/completion.test
  clang-tools-extra/trunk/test/clangd/definitions.test
  clang-tools-extra/trunk/test/clangd/diagnostics-preamble.test
  clang-tools-extra/trunk/test/clangd/diagnostics.test
  clang-tools-extra/trunk/test/clangd/did-change-watch-files.test
  clang-tools-extra/trunk/test/clangd/extra-flags.test
  clang-tools-extra/trunk/test/clangd/fixits.test
  clang-tools-extra/trunk/test/clangd/formatting.test
  clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test
  clang-tools-extra/trunk/test/clangd/initialize-params.test
  clang-tools-extra/trunk/test/clangd/input-mirror.test
  clang-tools-extra/trunk/test/clangd/protocol.test
  clang-tools-extra/trunk/test/clangd/shutdown-with-exit.test
  clang-tools-extra/trunk/test/clangd/shutdown-without-exit.test
  clang-tools-extra/trunk/test/clangd/signature-help.test
  clang-tools-extra/trunk/test/clangd/unsupported-method.test

Index: clang-tools-extra/trunk/clangd/Protocol.h
===
--- clang-tools-extra/trunk/clangd/Protocol.h
+++ clang-tools-extra/trunk/clangd/Protocol.h
@@ -173,6 +173,7 @@
   }
 };
 using ShutdownParams = NoParams;
+using ExitParams = NoParams;
 
 struct InitializeParams {
   /// The process Id of the parent process that started
Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h
@@ -39,7 +39,9 @@
   /// opened in binary mode. Output will be written using Out variable passed to
   /// class constructor. This method must not be executed more than once for
   /// each instance of ClangdLSPServer.
-  void run(std::istream &In);
+  ///
+  /// \return Wether we received a 'shutdown' request before an 'exit' request
+  bool run(std::istream &In);
 
 private:
   // Implement DiagnosticsConsumer.
@@ -50,6 +52,7 @@
   // Implement ProtocolCallbacks.
   void onInitialize(Ctx C, InitializeParams &Params) override;
   void onShutdown(Ctx C, ShutdownParams &Params) override;
+  void onExit(Ctx C, ExitParams &Params) override;
   void onDocumentDidOpen(Ctx C, DidOpenTextDocumentParams &Params) override;
   void onDocumentDidChange(Ctx C, DidChangeTextDocumentParams &Params) override;
   void onDocumentDidClose(Ctx C, DidCloseTextDocumentParams &Params) override;
@@ -79,6 +82,10 @@
   JSONOutput &Out;
   /// Used to indicate that the 'shutdown' request was received from the
   /// Language Server client.
+  bool ShutdownRequestReceived = false;
+
+  /// Used to indicate that the 'exit' notification was received from the
+  /// Language Server client.
   /// It's used to break out of the LSP parsing loop.
   bool IsDone = false;
 
Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
@@ -56,9 +56,13 @@
 }
 
 void ClangdLSPServer::onShutdown(Ctx C, ShutdownParams &Params) {
-  IsDone = true;
+  // Do essentially nothing, just say we're ready to exit.
+  ShutdownRequestReceived = true;
+  C.reply("null");
 }
 
+void ClangdLSPServer::onExit(Ctx C, ExitParams &Params) { IsDone = true; }
+
 void ClangdLSPServer::onDocumentDidOpen(Ctx C,
 DidOpenTextDocumentParams &Params) {
   if (Params.metadata && !Params.metadata->extraFlags.empty())
@@ -197,7 +201,7 @@
  /*EnableSnippetsAndCodePatterns=*/SnippetCompletions),
  /*Logger=*/Out, ResourceDir) {}
 
-void ClangdLSPServer::run(std::istream &In) {
+bool ClangdLSPServer::run(std::istream &In) {
   assert(!IsDone && "Run was called before");
 
   // Set up JSONRPCDispatcher.
@@ -213,6 +217,8 @@
   // Make sure IsDone is set to true after this method exits to ensure assertion
   // at the start of the method fires if it's ever executed again.
   IsDone = true;
+
+  return ShutdownRequestReceived;
 }
 
 std::vector
In

[PATCH] D39217: [libclang, bindings]: add spelling location

2017-10-25 Thread Johann Klähn via Phabricator via cfe-commits
jklaehn added inline comments.



Comment at: test/Index/c-index-getCursor-test.m:167
 // CHECK: [57:1 - 57:10] FunctionDecl=f:57:6 (Definition)
-// CHECK: [58:4 - 58:8] VarDecl=my_var:58:8 (Definition)
+// CHECK: [58:4 - 58:8] VarDecl=my_var:2:1 (Definition)
 // CHECK: [58:8 - 58:15] macro expansion=CONCAT:55:9

frutiger wrote:
> jklaehn wrote:
> > This does not seem to refer to a valid location? (line 2 only contains a 
> > comment)
> I don't really understand this output.  What is `-test-file-scan` supposed to 
> show?
Given this argument `c-index-test` will use `clang_getCursor` to iterate 
through all cursors in the file (by calling it on each character location and 
checking if it is equal to the previous cursor).
The numbers in brackets (e.g. `[58:4 - 58:8]`) indicate the locations for which 
`clang_getCursor` returned the same cursor. `VarDecl=my_var:2:1 (Definition)` 
is the output of `PrintCursor`. In this case `:2:1` is IIUC produced by
```
Referenced = clang_getCursorReferenced(Cursor);
if (!clang_equalCursors(Referenced, clang_getNullCursor())) {
  if (clang_getCursorKind(Referenced) == CXCursor_OverloadedDeclRef) {
// [...]
  } else {
CXSourceLocation Loc = clang_getCursorLocation(Referenced);
clang_getSpellingLocation(Loc, 0, &line, &column, 0);
printf(":%d:%d", line, column);
  }

  // [...]
}
```

So it is affected by the change to `clang_getSpellingLocation`. I'm not sure 
what the referenced cursor is in this case. Maybe it would be helpful to also 
print its kind.


https://reviews.llvm.org/D39217



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


Re: r316539 - [Analyzer] Remove spaces inside comments mentioning the parameter name,

2017-10-25 Thread Alexander Kornienko via cfe-commits
Thanks! This should be enough for the tools, however I would also remove
all other spaces inside the argument comments for consistency with the rest
of LLVM code. Currently different ways of putting spaces inside the
argument comments are used in LLVM as follows:
  1. /*Name=*/ - in 78 files (this is also
misunderstood by clang-format)
  2. /*Name=*/ - in 2 files
  3. /*Name=*/ - in 3 files
  4. /*Name=*/ - in 693 files.

So #4 is clearly the prevalent style.

-- Alex

On Tue, Oct 24, 2017 at 5:03 PM, George Karpenkov via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: george.karpenkov
> Date: Tue Oct 24 17:03:45 2017
> New Revision: 316539
>
> URL: http://llvm.org/viewvc/llvm-project?rev=316539&view=rev
> Log:
> [Analyzer] Remove spaces inside comments mentioning the parameter name,
>
> to aid clang-tidy comprehension.
> Requested by @alexfh in https://reviews.llvm.org/D39015
>
> Modified:
> cfe/trunk/lib/Analysis/BodyFarm.cpp
>
> Modified: cfe/trunk/lib/Analysis/BodyFarm.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/
> Analysis/BodyFarm.cpp?rev=316539&r1=316538&r2=316539&view=diff
> 
> ==
> --- cfe/trunk/lib/Analysis/BodyFarm.cpp (original)
> +++ cfe/trunk/lib/Analysis/BodyFarm.cpp Tue Oct 24 17:03:45 2017
> @@ -168,10 +168,10 @@ ASTMaker::makeLvalueToRvalue(const VarDe
>  ImplicitCastExpr *ASTMaker::makeImplicitCast(const Expr *Arg, QualType
> Ty,
>   CastKind CK) {
>return ImplicitCastExpr::Create(C, Ty,
> -  /* CastKind= */ CK,
> -  /* Expr= */ const_cast(Arg),
> -  /* CXXCastPath= */ nullptr,
> -  /* ExprValueKind= */ VK_RValue);
> +  /* CastKind=*/ CK,
> +  /* Expr=*/ const_cast(Arg),
> +  /* CXXCastPath=*/ nullptr,
> +  /* ExprValueKind=*/ VK_RValue);
>  }
>
>  Expr *ASTMaker::makeIntegralCast(const Expr *Arg, QualType Ty) {
> @@ -222,7 +222,7 @@ MemberExpr *ASTMaker::makeMemberExpressi
>C, base, IsArrow, SourceLocation(), NestedNameSpecifierLoc(),
>SourceLocation(), MemberDecl, FoundDecl,
>DeclarationNameInfo(MemberDecl->getDeclName(), SourceLocation()),
> -  /* TemplateArgumentListInfo= */ nullptr, MemberDecl->getType(),
> ValueKind,
> +  /* TemplateArgumentListInfo=*/ nullptr, MemberDecl->getType(),
> ValueKind,
>OK_Ordinary);
>  }
>
> @@ -231,7 +231,7 @@ ValueDecl *ASTMaker::findMemberField(con
>CXXBasePaths Paths(
>/* FindAmbiguities=*/false,
>/* RecordPaths=*/false,
> -  /* DetectVirtual= */ false);
> +  /* DetectVirtual=*/ false);
>const IdentifierInfo &II = C.Idents.get(Name);
>DeclarationName DeclName = C.DeclarationNames.getIdentifier(&II);
>
> @@ -282,14 +282,14 @@ static CallExpr *create_call_once_lambda
>assert(callOperatorDecl != nullptr);
>
>DeclRefExpr *callOperatorDeclRef =
> -  DeclRefExpr::Create(/* Ctx = */ C,
> -  /* QualifierLoc = */ NestedNameSpecifierLoc(),
> -  /* TemplateKWLoc = */ SourceLocation(),
> +  DeclRefExpr::Create(/* Ctx =*/ C,
> +  /* QualifierLoc =*/ NestedNameSpecifierLoc(),
> +  /* TemplateKWLoc =*/ SourceLocation(),
>const_cast(callOperatorDecl),
> -  /* RefersToEnclosingVariableOrCapture= */
> false,
> -  /* NameLoc = */ SourceLocation(),
> -  /* T = */ callOperatorDecl->getType(),
> -  /* VK = */ VK_LValue);
> +  /* RefersToEnclosingVariableOrCapture=*/ false,
> +  /* NameLoc =*/ SourceLocation(),
> +  /* T =*/ callOperatorDecl->getType(),
> +  /* VK =*/ VK_LValue);
>
>return new (C)
>CXXOperatorCallExpr(/*AstContext=*/C, OO_Call, callOperatorDeclRef,
> @@ -372,7 +372,7 @@ static Stmt *create_call_once(ASTContext
>  // Lambda requires callback itself inserted as a first parameter.
>  CallArgs.push_back(
>  M.makeDeclRefExpr(Callback,
> -  /* RefersToEnclosingVariableOrCapture= */
> true));
> +  /* RefersToEnclosingVariableOrCapture=*/
> true));
>  CallbackFunctionType = CallbackRecordDecl->getLambdaCallOperator()
> ->getType()
> ->getAs();
> @@ -429,13 +429,13 @@ static Stmt *create_call_once(ASTContext
>
>// Negation predicate.
>UnaryOperator *FlagCheck = new (C) UnaryOperator(
> -  /* input= */
> +  /* input=*/
>M.makeImplicitCast(M.makeLvalueToRvalue(Deref, DerefType),
> DerefType,
>  

[PATCH] D39057: [clangd][WIP] Integrate the refactoring actions into clangd

2017-10-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a subscriber: malaperle.
ilya-biryukov added a comment.

There's another patch (https://reviews.llvm.org/D39276) that tries to add 
`workspace/executeCommand` for a slightly different use-case.
Could we take the code for parsing/handling `workspace/executeCommand` from 
this patch and extract it into a separate change so that these two patches can 
be reviewed independently?
I expect that the only addition the other patch needs 
(https://reviews.llvm.org/D39276) is to add a new kind of `CommandArgument`.


Repository:
  rL LLVM

https://reviews.llvm.org/D39057



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


[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc

2017-10-25 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 120214.
baloghadamsoftware added a comment.

Updated according to comments.


https://reviews.llvm.org/D39121

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
  clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp

Index: test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
@@ -0,0 +1,43 @@
+// RUN: %check_clang_tidy %s bugprone-misplaced-operator-in-strlen-in-alloc %t
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+void *alloca(size_t);
+void *calloc(size_t, size_t);
+void *realloc(void *, size_t);
+
+size_t strlen(const char*);
+
+void bad_malloc(char *name) {
+  char *new_name = (char*) malloc(strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Binary operator + 1 is inside strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) malloc\(}}strlen(name) + 1{{\);$}}
+}
+
+void bad_alloca(char *name) {
+  char *new_name = (char*) alloca(strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Binary operator + 1 is inside strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) alloca\(}}strlen(name) + 1{{\);$}}
+}
+
+void bad_calloc(char *name) {
+  char *new_names = (char*) calloc(2, strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: Binary operator + 1 is inside strlen
+  // CHECK-FIXES: {{^  char \*new_names = \(char\*\) calloc\(2, }}strlen(name) + 1{{\);$}}
+}
+
+void bad_realloc(char * old_name, char *name) {
+  char *new_name = (char*) realloc(old_name, strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Binary operator + 1 is inside strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) realloc\(old_name, }}strlen(name) + 1{{\);$}}
+}
+
+void intentional1(char *name) {
+  char *new_name = (char*) malloc(strlen(name + 1) + 1);
+}
+
+
+void intentional2(char *name) {
+  char *new_name = (char*) malloc(strlen(name + 2));
+}
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -18,6 +18,7 @@
android-cloexec-socket
boost-use-to-string
bugprone-integer-division
+   bugprone-misplaced-operator-in-strlen-in-alloc
bugprone-suspicious-memset-usage
bugprone-undefined-memory-manipulation
cert-dcl03-c (redirects to misc-static-assert) 
Index: docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - bugprone-misplaced-operator-in-strlen-in-alloc
+
+bugprone-misplaced-operator-in-strlen-in-alloc
+==
+
+Finds cases a value is added to or subtracted from the string in the parameter
+of ``strlen()`` method instead of to the result and use its return value as an
+argument of a memory allocation function (``malloc()``, ``calloc()``,
+``realloc()``).
+
+Example code:
+
+.. code-block:: c
+
+void bad_malloc(char *str) {
+  char *c = (char*) malloc(strlen(str + 1));
+}
+
+
+The suggested fix is to add value to the return value of ``strlen()`` and not
+to its argument. In the example above the fix would be
+
+.. code-block:: c
+
+  char *c = (char*) malloc(strlen(str) + 1);
+
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,14 @@
 Improvements to clang-tidy
 --
 
+- New `bugprone-misplaced-operator-in-strlen-in-alloc
+  `_ check
+
+  Finds cases a value is added to or subtracted from the string in the parameter
+  of ``strlen()`` method instead of to the result and use its return value as an
+  argument of a memory allocation function (``malloc()``, ``calloc()``,
+  ``realloc()``). The check also suggests the appropriate fix.
+
 - Renamed checks to use correct term "implicit conversion" instead of "implicit
   cast" and modified messages and option names accordingly:
 
Index: clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h
===
--- /dev/null
+++ clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h
@@ -0,0 +1,37 @@
+//===--- MisplacedOperatorInStrlenInAllocCheck.h - clang-tidy*-

[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc

2017-10-25 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware marked 5 inline comments as done.
baloghadamsoftware added inline comments.



Comment at: clang-tidy/misc/MisplacedOperatorInStrlenInAllocCheck.cpp:30
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(hasName("malloc"))),
+   hasArgument(0, anyOf(hasDescendant(BadUse), BadUse)))

xazax.hun wrote:
> Maybe it is worth to have a configurable list of allocation functions?
> 
> Maybe it would be worth to support`alloca` as well?
Support for ``alloca`` added.

I agree, it is worth to have a configurable list, but I think it is better to 
be done in a separate patch.



Comment at: clang-tidy/misc/MisplacedOperatorInStrlenInAllocCheck.cpp:44
+const MatchFinder::MatchResult &Result) {
+  // FIXME: Add callback implementation.
+  const auto *Alloc = Result.Nodes.getNodeAs("Alloc");

xazax.hun wrote:
> What is this fixme?
Sorry, I forgot to remove it.



Comment at: clang-tidy/misc/MisplacedOperatorInStrlenInAllocCheck.h:19
+
+/// FIXME: Write a short description.
+///

xazax.hun wrote:
> There is a missing description.
No longer. Sorry, I forgot it.



Comment at: docs/clang-tidy/checks/list.rst:10
android-cloexec-creat
+   android-cloexec-dup
android-cloexec-epoll-create

Eugene.Zelenko wrote:
> I think will be better to fix order of other checks separately from this 
> check.
I agree, but I did not do it. It was the script that created the new check. I 
changed it back to the wrong order.



Comment at: 
docs/clang-tidy/checks/misc-misplaced-operator-in-strlen-in-alloc.rst:16
+void bad_malloc(char *str) {
+  char *c = (char*) malloc(strlen(str + 1));
+}

aaron.ballman wrote:
> xazax.hun wrote:
> > What if this code is intentional for some reason?
> > I think in thase case it could be rewritten like the following (which is 
> > much cleaner):
> > ```
> > char *c = (char*) malloc(strlen(str)-1);
> > ```
> > I think it might be a good idea to mention this possibility as a way to 
> > suppress this warning in the documentation. 
> This is my concern as well -- I'd like to know how chatty this diagnostic is 
> on real-world code bases, especially ones that rely on C rather than C++. A 
> somewhat common code pattern in Win32 coding are double-null-terminated lists 
> of strings, where you have null terminated strings at adjacent memory 
> locations with two null characters for the end of the list. This could result 
> in reasonable code like `malloc(strlen(str + offset) + 1)`.
It is now more conservative: only ``+ 1`` counts, and only if there is no 
additional ``+ 1`` outside.


https://reviews.llvm.org/D39121



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


[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc

2017-10-25 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware marked 4 inline comments as done.
baloghadamsoftware added a comment.

In https://reviews.llvm.org/D39121#902728, @alexfh wrote:

> Apart from all other comments, I think, this check would better be placed 
> under bugprone/.


I moved it there.


https://reviews.llvm.org/D39121



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


[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc

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

In https://reviews.llvm.org/D39121#902121, @martong wrote:

> Consider the use of a function pointer:
>
>   void* malloc(int);
>   int strlen(char*);
>   auto fp = malloc;
>   void bad_malloc(char *str) { char *c = (char *)fp(strlen(str + 1)); }
>
>
> I think, the checker will not match in this case.
>
> One might use allocation functions via a function pointer in case of more 
> possible allocation strategies (e.g having a different strategy for a shared 
> memory allocation).


Good point! But I think we should keep this first patch small, so I will do it 
in a follow-up patch.


https://reviews.llvm.org/D39121



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


[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc

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

In https://reviews.llvm.org/D39121#902145, @Eugene.Zelenko wrote:

> Same mistake  could be made with new[] operator.


Yes! However, it seems that I need a new matcher for it so I would do it in a 
follow-up patch.


https://reviews.llvm.org/D39121



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


[PATCH] D38819: [libunwind] Add support for dwarf unwinding on windows on x86_64

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

Updated to take care of saving/restoring XMM registers as well.


https://reviews.llvm.org/D38819

Files:
  docs/index.rst
  include/__libunwind_config.h
  include/libunwind.h
  include/unwind.h
  src/AddressSpace.hpp
  src/Registers.hpp
  src/UnwindLevel1.c
  src/UnwindRegistersRestore.S
  src/UnwindRegistersSave.S

Index: src/UnwindRegistersSave.S
===
--- src/UnwindRegistersSave.S
+++ src/UnwindRegistersSave.S
@@ -63,6 +63,43 @@
 #  thread_state pointer is in rdi
 #
 DEFINE_LIBUNWIND_FUNCTION(unw_getcontext)
+#if defined(_WIN64)
+  movq  %rax,   (%rcx)
+  movq  %rbx,  8(%rcx)
+  movq  %rcx, 16(%rcx)
+  movq  %rdx, 24(%rcx)
+  movq  %rdi, 32(%rcx)
+  movq  %rsi, 40(%rcx)
+  movq  %rbp, 48(%rcx)
+  movq  %rsp, 56(%rcx)
+  addq  $8,   56(%rcx)
+  movq  %r8,  64(%rcx)
+  movq  %r9,  72(%rcx)
+  movq  %r10, 80(%rcx)
+  movq  %r11, 88(%rcx)
+  movq  %r12, 96(%rcx)
+  movq  %r13,104(%rcx)
+  movq  %r14,112(%rcx)
+  movq  %r15,120(%rcx)
+  movq  (%rsp),%rdx
+  movq  %rdx,128(%rcx) # store return address as rip
+  movdqu %xmm0,168(%rcx)
+  movdqu %xmm1,184(%rcx)
+  movdqu %xmm2,200(%rcx)
+  movdqu %xmm3,216(%rcx)
+  movdqu %xmm4,232(%rcx)
+  movdqu %xmm5,248(%rcx)
+  movdqu %xmm6,264(%rcx)
+  movdqu %xmm7,280(%rcx)
+  movdqu %xmm8,296(%rcx)
+  movdqu %xmm9,312(%rcx)
+  movdqu %xmm10,328(%rcx)
+  movdqu %xmm11,344(%rcx)
+  movdqu %xmm12,360(%rcx)
+  movdqu %xmm13,376(%rcx)
+  movdqu %xmm14,392(%rcx)
+  movdqu %xmm15,408(%rcx)
+#else
   movq  %rax,   (%rdi)
   movq  %rbx,  8(%rdi)
   movq  %rcx, 16(%rdi)
@@ -82,6 +119,7 @@
   movq  %r15,120(%rdi)
   movq  (%rsp),%rsi
   movq  %rsi,128(%rdi) # store return address as rip
+#endif
   # skip rflags
   # skip cs
   # skip fs
Index: src/UnwindRegistersRestore.S
===
--- src/UnwindRegistersRestore.S
+++ src/UnwindRegistersRestore.S
@@ -65,6 +65,56 @@
 #
 # void libunwind::Registers_x86_64::jumpto()
 #
+#if defined(_WIN64)
+# On entry, thread_state pointer is in rcx
+
+  movq  56(%rcx), %rax # rax holds new stack pointer
+  subq  $16, %rax
+  movq  %rax, 56(%rcx)
+  movq  16(%rcx), %rdx  # store new rcx on new stack
+  movq  %rdx, 0(%rax)
+  movq  128(%rcx), %rdx # store new rip on new stack
+  movq  %rdx, 8(%rax)
+  # restore all registers
+  movq0(%rcx), %rax
+  movq8(%rcx), %rbx
+  # restore rcx later
+  movq   24(%rcx), %rdx
+  movq   32(%rcx), %rdi
+  movq   40(%rcx), %rsi
+  movq   48(%rcx), %rbp
+  # restore rsp later
+  movq   64(%rcx), %r8
+  movq   72(%rcx), %r9
+  movq   80(%rcx), %r10
+  movq   88(%rcx), %r11
+  movq   96(%rcx), %r12
+  movq  104(%rcx), %r13
+  movq  112(%rcx), %r14
+  movq  120(%rcx), %r15
+  # skip rflags
+  # skip cs
+  # skip fs
+  # skip gs
+  movdqu 168(%rcx),%xmm0
+  movdqu 184(%rcx),%xmm1
+  movdqu 200(%rcx),%xmm2
+  movdqu 216(%rcx),%xmm3
+  movdqu 232(%rcx),%xmm4
+  movdqu 248(%rcx),%xmm5
+  movdqu 264(%rcx),%xmm6
+  movdqu 280(%rcx),%xmm7
+  movdqu 296(%rcx),%xmm8
+  movdqu 312(%rcx),%xmm9
+  movdqu 328(%rcx),%xmm10
+  movdqu 344(%rcx),%xmm11
+  movdqu 360(%rcx),%xmm12
+  movdqu 376(%rcx),%xmm13
+  movdqu 392(%rcx),%xmm14
+  movdqu 408(%rcx),%xmm15
+  movq  56(%rcx), %rsp  # cut back rsp to new location
+  pop%rcx  # rcx was saved here earlier
+#else
 # On entry, thread_state pointer is in rdi
 
   movq  56(%rdi), %rax # rax holds new stack pointer
@@ -97,6 +147,7 @@
   # skip gs
   movq  56(%rdi), %rsp  # cut back rsp to new location
   pop%rdi  # rdi was saved here earlier
+#endif
   ret# rip was saved here
 
 
Index: src/UnwindLevel1.c
===
--- src/UnwindLevel1.c
+++ src/UnwindLevel1.c
@@ -86,7 +86,7 @@
 // this frame.
 if (frameInfo.handler != 0) {
   __personality_routine p =
-  (__personality_routine)(long)(frameInfo.handler);
+  (__personality_routine)(uintptr_t)(frameInfo.handler);
   _LIBUNWIND_TRACE_UNWINDING(
   "unwind_phase1(ex_ojb=%p): calling personality function %p",
   (void *)exception_object, (void *)(uintptr_t)p);
@@ -181,7 +181,7 @@
 // If there is a personality routine, tell it we are unwinding.
 if (frameInfo.handler != 0) {
   __personality_routine p =
-  (__personality_routine)(long)(frameInfo.handler);
+  (__personality_routine)(uintptr_t)(frameInfo.handler);
   _Unwind_Action action = _UA_CLEANUP_PHASE;
   if (sp == exception_object->private_2) {
 // Tell personality this was the frame it marked in phase 1.
Index: src/Registers.hpp
===
--- src/Registers.hpp
+++ src/Registers.hpp
@@ -245,12 +245,12 @@
   boolvalidFloatRegister(int) const { return false; }
   double  getFloatRegister(int num) const;
   vo

[PATCH] D26105: Allow CaseStmt to be initialized with a SubStmt

2017-10-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun abandoned this revision.
xazax.hun added a comment.

Since r316069 this is no longer relevant.


https://reviews.llvm.org/D26105



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


[PATCH] D39239: [AST] Incorrectly qualified unscoped enumeration as template actual parameter.

2017-10-25 Thread Carlos Alberto Enciso via Phabricator via cfe-commits
CarlosAlbertoEnciso added a comment.

In https://reviews.llvm.org/D39239#905641, @probinson wrote:

> Have you tried this change against the GDB and LLDB test suites?  If they 
> have failures then we should think about whether those tests are 
> over-specific or whether we should put this under a tuning option.


LLDB test suite:
There are some specific tests that use enums and templates:

tools/lldb/packages/Python/lldbsuite/test/lang/cpp/template

but they cover only the case of scoped enums and are not affected by this 
patch. May be the LLDB test suite should be updated to cover scoped and 
unscoped enums.

I will check the GDB test suite and include the results.


https://reviews.llvm.org/D39239



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


[PATCH] D39178: [rename] support renaming class member.

2017-10-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 120216.
hokein marked 2 inline comments as done.
hokein added a comment.

- remove the code of handling template class methods as it is fixed in another 
patch.
- address review comments.


https://reviews.llvm.org/D39178

Files:
  lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
  unittests/Rename/CMakeLists.txt
  unittests/Rename/RenameMemberTest.cpp

Index: unittests/Rename/RenameMemberTest.cpp
===
--- /dev/null
+++ unittests/Rename/RenameMemberTest.cpp
@@ -0,0 +1,229 @@
+//===-- ClangMemberTests.cpp - unit tests for renaming class members --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangRenameTest.h"
+
+namespace clang {
+namespace clang_rename {
+namespace test {
+namespace {
+
+class RenameMemberTest : public ClangRenameTest {
+public:
+  RenameMemberTest() {
+AppendToHeader(R"(
+struct NA {
+  void Foo();
+  void NotFoo();
+  static void SFoo();
+  static void SNotFoo();
+  int Moo;
+};
+struct A {
+  virtual void Foo();
+  void NotFoo();
+  static void SFoo();
+  static void SNotFoo();
+  int Moo;
+  int NotMoo;
+  static int SMoo;
+};
+struct B : public A {
+  void Foo() override;
+};
+template  struct TA {
+  T* Foo();
+  T* NotFoo();
+  static T* SFoo();
+  static T* NotSFoo();
+};
+template  struct TB : public TA {};
+namespace ns {
+  template  struct TA {
+T* Foo();
+T* NotFoo();
+static T* SFoo();
+static T* NotSFoo();
+static int SMoo;
+  };
+  template  struct TB : public TA {};
+  struct A {
+void Foo();
+void NotFoo();
+static void SFoo();
+static void SNotFoo();
+  };
+  struct B : public A {};
+  struct C {
+template 
+void SFoo(const T& t) {}
+template 
+void Foo() {}
+  };
+})");
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(
+DISABLED_RenameTemplatedClassStaticVariableTest, RenameMemberTest,
+testing::ValuesIn(std::vector({
+// FIXME: support renaming static variables for template classes.
+{"void f() { ns::TA::SMoo; }",
+ "void f() { ns::TA::SMeh; }", "ns::TA::SMoo", "ns::TA::SMeh"},
+})), );
+
+INSTANTIATE_TEST_CASE_P(
+RenameMemberTest, RenameMemberTest,
+testing::ValuesIn(std::vector({
+// Normal methods and fields.
+{"void f() { A a; a.Foo(); }", "void f() { A a; a.Bar(); }", "A::Foo",
+ "A::Bar"},
+{"void f() { ns::A a; a.Foo(); }", "void f() { ns::A a; a.Bar(); }",
+ "ns::A::Foo", "ns::A::Bar"},
+{"void f() { A a; int x = a.Moo; }", "void f() { A a; int x = a.Meh; }",
+ "A::Moo", "A::Meh"},
+{"void f() { B b; b.Foo(); }", "void f() { B b; b.Bar(); }", "B::Foo",
+ "B::Bar"},
+{"void f() { ns::B b; b.Foo(); }", "void f() { ns::B b; b.Bar(); }",
+ "ns::A::Foo", "ns::A::Bar"},
+{"void f() { B b; int x = b.Moo; }", "void f() { B b; int x = b.Meh; }",
+ "A::Moo", "A::Meh"},
+
+// Static methods.
+{"void f() { A::SFoo(); }", "void f() { A::SBar(); }", "A::SFoo",
+ "A::SBar"},
+{"void f() { ns::A::SFoo(); }", "void f() { ns::A::SBar(); }",
+ "ns::A::SFoo", "ns::A::SBar"},
+{"void f() { TA::SFoo(); }", "void f() { TA::SBar(); }",
+ "TA::SFoo", "TA::SBar"},
+{"void f() { ns::TA::SFoo(); }",
+ "void f() { ns::TA::SBar(); }", "ns::TA::SFoo", "ns::TA::SBar"},
+
+// Static variables.
+{"void f() { A::SMoo; }",
+ "void f() { A::SMeh; }", "A::SMoo", "A::SMeh"},
+
+// Templated methods.
+{"void f() { TA a; a.Foo(); }", "void f() { TA a; a.Bar(); }",
+ "TA::Foo", "TA::Bar"},
+{"void f() { ns::TA a; a.Foo(); }",
+ "void f() { ns::TA a; a.Bar(); }", "ns::TA::Foo", "ns::TA::Bar"},
+{"void f() { TB b; b.Foo(); }", "void f() { TB b; b.Bar(); }",
+ "TA::Foo", "TA::Bar"},
+{"void f() { ns::TB b; b.Foo(); }",
+ "void f() { ns::TB b; b.Bar(); }", "ns::TA::Foo", "ns::TA::Bar"},
+{"void f() { ns::C c; int x; c.SFoo(x); }",
+ "void f() { ns::C c; int x; c.SBar(x); }", "ns::C::SFoo",
+ "ns::C::SBar"},
+{"void f() { ns::C c; c.Foo(); }",
+ "void f() { ns::C c; c.Bar(); }", "ns::C::Foo", "ns::C::Bar"},
+
+// Pointers to methods.
+{"void f() { auto p = &A::Foo; }", "void f(

[PATCH] D39178: [rename] support renaming class member.

2017-10-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

I have refined the patch based on the https://reviews.llvm.org/D39241. Please 
take another look.


https://reviews.llvm.org/D39178



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


[PATCH] D38629: [clangd] Added a callback-based codeComplete in clangd.

2017-10-25 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316565: [clangd] Added a callback-based codeComplete in 
clangd. (authored by ibiryukov).

Changed prior to commit:
  https://reviews.llvm.org/D38629?vs=119813&id=120218#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38629

Files:
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h

Index: clang-tools-extra/trunk/clangd/ClangdServer.h
===
--- clang-tools-extra/trunk/clangd/ClangdServer.h
+++ clang-tools-extra/trunk/clangd/ClangdServer.h
@@ -234,6 +234,9 @@
   /// and AST and rebuild them from scratch.
   std::future forceReparse(PathRef File);
 
+  /// DEPRECATED. Please use a callback-based version, this API is deprecated
+  /// and will soon be removed.
+  ///
   /// Run code completion for \p File at \p Pos.
   ///
   /// Request is processed asynchronously. You can use the returned future to
@@ -253,6 +256,14 @@
llvm::Optional OverridenContents = llvm::None,
IntrusiveRefCntPtr *UsedFS = nullptr);
 
+  /// A version of `codeComplete` that runs \p Callback on the processing thread
+  /// when codeComplete results become available.
+  void codeComplete(
+  UniqueFunction>)> Callback,
+  PathRef File, Position Pos,
+  llvm::Optional OverridenContents = llvm::None,
+  IntrusiveRefCntPtr *UsedFS = nullptr);
+
   /// Provide signature help for \p File at \p Pos. If \p OverridenContents is
   /// not None, they will used only for signature help, i.e. no diagnostics
   /// update will be scheduled and a draft for \p File will not be updated. If
Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp
@@ -198,6 +198,28 @@
 ClangdServer::codeComplete(PathRef File, Position Pos,
llvm::Optional OverridenContents,
IntrusiveRefCntPtr *UsedFS) {
+  using ResultType = Tagged>;
+
+  std::promise ResultPromise;
+
+  auto Callback = [](std::promise ResultPromise,
+ ResultType Result) -> void {
+ResultPromise.set_value(std::move(Result));
+  };
+
+  std::future ResultFuture = ResultPromise.get_future();
+  codeComplete(BindWithForward(Callback, std::move(ResultPromise)), File, Pos,
+   OverridenContents, UsedFS);
+  return ResultFuture;
+}
+
+void ClangdServer::codeComplete(
+UniqueFunction>)> Callback,
+PathRef File, Position Pos, llvm::Optional OverridenContents,
+IntrusiveRefCntPtr *UsedFS) {
+  using CallbackType =
+  UniqueFunction>)>;
+
   std::string Contents;
   if (OverridenContents) {
 Contents = *OverridenContents;
@@ -216,36 +238,32 @@
   std::shared_ptr Resources = Units.getFile(File);
   assert(Resources && "Calling completion on non-added file");
 
-  using PackagedTask =
-  std::packaged_task>()>;
-
   // Remember the current Preamble and use it when async task starts executing.
   // At the point when async task starts executing, we may have a different
   // Preamble in Resources. However, we assume the Preamble that we obtain here
   // is reusable in completion more often.
   std::shared_ptr Preamble =
   Resources->getPossiblyStalePreamble();
   // A task that will be run asynchronously.
-  PackagedTask Task([=]() mutable { // 'mutable' to reassign Preamble variable.
-if (!Preamble) {
-  // Maybe we built some preamble before processing this request.
-  Preamble = Resources->getPossiblyStalePreamble();
-}
-// FIXME(ibiryukov): even if Preamble is non-null, we may want to check
-// both the old and the new version in case only one of them matches.
+  auto Task =
+  // 'mutable' to reassign Preamble variable.
+  [=](CallbackType Callback) mutable {
+if (!Preamble) {
+  // Maybe we built some preamble before processing this request.
+  Preamble = Resources->getPossiblyStalePreamble();
+}
+// FIXME(ibiryukov): even if Preamble is non-null, we may want to check
+// both the old and the new version in case only one of them matches.
+
+std::vector Result = clangd::codeComplete(
+File, Resources->getCompileCommand(),
+Preamble ? &Preamble->Preamble : nullptr, Contents, Pos,
+TaggedFS.Value, PCHs, CodeCompleteOpts, Logger);
 
-std::vector Result = clangd::codeComplete(
-File, Resources->getCompileCommand(),
-Preamble ? &Preamble->Preamble : nullptr, Contents, Pos, TaggedFS.Value,
-PCHs, CodeCompleteOpts, Logger);
-return make_tagged(std::move(Result), std::move(TaggedFS.Tag));
-  });
+Callback(make_tagged(std::move(Result), std::move(TaggedFS.Tag)));
+  };
 
-  auto Future = Task.get_future();
-  // FIXME(ibi

[clang-tools-extra] r316565 - [clangd] Added a callback-based codeComplete in clangd.

2017-10-25 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Oct 25 02:35:10 2017
New Revision: 316565

URL: http://llvm.org/viewvc/llvm-project?rev=316565&view=rev
Log:
[clangd] Added a callback-based codeComplete in clangd.

Reviewers: klimek, bkramer, sammccall, krasimir

Reviewed By: sammccall

Subscribers: rwols, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=316565&r1=316564&r2=316565&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Oct 25 02:35:10 2017
@@ -198,6 +198,28 @@ std::future OverridenContents,
IntrusiveRefCntPtr *UsedFS) {
+  using ResultType = Tagged>;
+
+  std::promise ResultPromise;
+
+  auto Callback = [](std::promise ResultPromise,
+ ResultType Result) -> void {
+ResultPromise.set_value(std::move(Result));
+  };
+
+  std::future ResultFuture = ResultPromise.get_future();
+  codeComplete(BindWithForward(Callback, std::move(ResultPromise)), File, Pos,
+   OverridenContents, UsedFS);
+  return ResultFuture;
+}
+
+void ClangdServer::codeComplete(
+UniqueFunction>)> Callback,
+PathRef File, Position Pos, llvm::Optional OverridenContents,
+IntrusiveRefCntPtr *UsedFS) {
+  using CallbackType =
+  UniqueFunction>)>;
+
   std::string Contents;
   if (OverridenContents) {
 Contents = *OverridenContents;
@@ -216,9 +238,6 @@ ClangdServer::codeComplete(PathRef File,
   std::shared_ptr Resources = Units.getFile(File);
   assert(Resources && "Calling completion on non-added file");
 
-  using PackagedTask =
-  std::packaged_task>()>;
-
   // Remember the current Preamble and use it when async task starts executing.
   // At the point when async task starts executing, we may have a different
   // Preamble in Resources. However, we assume the Preamble that we obtain here
@@ -226,26 +245,25 @@ ClangdServer::codeComplete(PathRef File,
   std::shared_ptr Preamble =
   Resources->getPossiblyStalePreamble();
   // A task that will be run asynchronously.
-  PackagedTask Task([=]() mutable { // 'mutable' to reassign Preamble variable.
-if (!Preamble) {
-  // Maybe we built some preamble before processing this request.
-  Preamble = Resources->getPossiblyStalePreamble();
-}
-// FIXME(ibiryukov): even if Preamble is non-null, we may want to check
-// both the old and the new version in case only one of them matches.
-
-std::vector Result = clangd::codeComplete(
-File, Resources->getCompileCommand(),
-Preamble ? &Preamble->Preamble : nullptr, Contents, Pos, 
TaggedFS.Value,
-PCHs, CodeCompleteOpts, Logger);
-return make_tagged(std::move(Result), std::move(TaggedFS.Tag));
-  });
-
-  auto Future = Task.get_future();
-  // FIXME(ibiryukov): to reduce overhead for wrapping the same callable
-  // multiple times, ClangdScheduler should return future<> itself.
-  WorkScheduler.addToFront([](PackagedTask Task) { Task(); }, std::move(Task));
-  return Future;
+  auto Task =
+  // 'mutable' to reassign Preamble variable.
+  [=](CallbackType Callback) mutable {
+if (!Preamble) {
+  // Maybe we built some preamble before processing this request.
+  Preamble = Resources->getPossiblyStalePreamble();
+}
+// FIXME(ibiryukov): even if Preamble is non-null, we may want to check
+// both the old and the new version in case only one of them matches.
+
+std::vector Result = clangd::codeComplete(
+File, Resources->getCompileCommand(),
+Preamble ? &Preamble->Preamble : nullptr, Contents, Pos,
+TaggedFS.Value, PCHs, CodeCompleteOpts, Logger);
+
+Callback(make_tagged(std::move(Result), std::move(TaggedFS.Tag)));
+  };
+
+  WorkScheduler.addToFront(std::move(Task), std::move(Callback));
 }
 
 Tagged

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=316565&r1=316564&r2=316565&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Wed Oct 25 02:35:10 2017
@@ -234,6 +234,9 @@ public:
   /// and AST and rebuild them from scratch.
   std::future forceReparse(PathRef File);
 
+  /// DEPRECATED. Please use a callback-based version, this API is deprecated
+  /// and will soon be removed.
+  ///
   /// Run code completion for \p File at \p Pos.
   ///
   /// Request is processed asynchronously. You can use the returned future to
@@ -253,6 +256

[PATCH] D37187: [Analyzer] Fix Bug 25609 - Assertion UNREACHABLE: 'Unexpected ProgramPoint' with widen-loops=true

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



Comment at: lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:651-652
+  } else if (StoreSite->getLocation().getAs()) {
+os << "Reach the max loop limit.";
+os << " Assigning a conjured symbol";
+if (R->canPrintPretty()) {

zaks.anna wrote:
> xazax.hun wrote:
> > zaks.anna wrote:
> > > MTC wrote:
> > > > NoQ wrote:
> > > > > This is user-facing text, and users shouldn't know about conjured 
> > > > > symbols, and "max" shouldn't be shortened, and i'm not sure what 
> > > > > else. I'd probably suggest something along the lines of "Contents of 
> > > > > <...> are wiped", but this is still not good enough.
> > > > > 
> > > > > Also could you add a test that displays this note? I.e. with 
> > > > > `-analyzer-output=text`.
> > > > Thanks for your review. 
> > > > 
> > > > You are right, whether this information should be displayed to the user 
> > > > is a question worth discussing.
> > > I am not convinced that we need to print this information to the user. 
> > > The problem here is that it leaks internal implementation details about 
> > > the analyzer. The users should not know about "loop limits" and 
> > > "invalidation" and most of the users would not even know what this means. 
> > > I can see how this is useful to the analyzer developers for debugging the 
> > > analyzer, but not to the end user.
> > > 
> > While we might not want to expose this to the user this can be really 
> > useful to understand what the analyzer is doing when we debugging a false 
> > positive finding. Maybe it would be worth to introduce a developer mode or 
> > verbose mode for those purposes. What do you think?
> I'd be fine with that in theory, though the downside is that it would pollute 
> the code a bit. One trick that's often used to better understand a report 
> when debugging is to remove the path note pruning (by passing a flag). I am 
> not sure if that approach can be extended for this case. Ex: maybe we could 
> have special markers on the notes saying that they are for debug purposes 
> only and have the pruning remove them.
> 
> By the way, is this change related to the other change from this patch?
I agree that we should just commit this without the message to fix the assert. 
The "debug message" could be addressed in a separate patch. 


https://reviews.llvm.org/D37187



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


[PATCH] D39178: [rename] support renaming class member.

2017-10-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.

Still lgtm.


https://reviews.llvm.org/D39178



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


[PATCH] D39284: [c++2a] Decomposed _condition_

2017-10-25 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray created this revision.

This feature was discussed but not yet proposed.  It allows a structured 
binding to appear as a //condition//

  if (auto [ok, val] = f(...))

So the user can save an extra //condition// if the statement can query the 
value to-be-decomposed instead.  Formally, it makes the value of the underlying 
object of the structured binding declaration also the value of a //condition// 
that is an initialized declaration.

Considering its logicality which is entirely evident from its trivial 
implementation, I think it might be acceptable to land it as an extension for 
now before I write the paper.


https://reviews.llvm.org/D39284

Files:
  include/clang/Sema/DeclSpec.h
  lib/Parse/ParseExprCXX.cpp
  lib/Sema/SemaDeclCXX.cpp
  test/Parser/cxx2a-decomposition.cpp
  test/SemaCXX/cxx2a-decomposition.cpp

Index: test/SemaCXX/cxx2a-decomposition.cpp
===
--- /dev/null
+++ test/SemaCXX/cxx2a-decomposition.cpp
@@ -0,0 +1,96 @@
+// RUN: %clang_cc1 -std=c++2a -verify %s
+
+struct X {
+  bool flag;
+  int data;
+  constexpr explicit operator bool() const {
+return flag;
+  }
+  constexpr operator int() const {
+return data;
+  }
+};
+
+namespace CondInIf {
+constexpr int f(X x) {
+  if (auto [ok, d] = x)
+return d + int(ok);
+  else
+return d * int(ok);
+  ok = {}; // expected-error {{use of undeclared identifier 'ok'}}
+  d = {};  // expected-error {{use of undeclared identifier 'd'}}
+}
+
+static_assert(f({true, 2}) == 3);
+static_assert(f({false, 2}) == 0);
+
+constexpr char g(char const (&x)[2]) {
+  if (auto &[a, b] = x)
+return a;
+  else
+return b;
+}
+
+static_assert(g("x") == 'x');
+} // namespace CondInIf
+
+namespace CondInSwitch {
+constexpr int f(int n) {
+  switch (X s = {true, n}; auto [ok, d] = s) {
+s = {};
+  case 0:
+return int(ok);
+  case 1:
+return d * 10;
+  case 2:
+return d * 40;
+  default:
+return 0;
+  }
+  ok = {}; // expected-error {{use of undeclared identifier 'ok'}}
+  d = {};  // expected-error {{use of undeclared identifier 'd'}}
+  s = {};  // expected-error {{use of undeclared identifier 's'}}
+}
+
+static_assert(f(0) == 1);
+static_assert(f(1) == 10);
+static_assert(f(2) == 80);
+} // namespace CondInSwitch
+
+namespace CondInWhile {
+constexpr int f(int n) {
+  int m = 1;
+  while (auto [ok, d] = X{n > 1, n}) {
+m *= d;
+--n;
+  }
+  return m;
+  return ok; // expected-error {{use of undeclared identifier 'ok'}}
+}
+
+static_assert(f(0) == 1);
+static_assert(f(1) == 1);
+static_assert(f(4) == 24);
+} // namespace CondInWhile
+
+namespace CondInFor {
+constexpr int f(int n) {
+  int a = 1, b = 1;
+  for (X x = {true, n}; auto &[ok, d] = x; --d) {
+if (d < 2)
+  ok = false;
+else {
+  int x = b;
+  b += a;
+  a = x;
+}
+  }
+  return b;
+  return d; // expected-error {{use of undeclared identifier 'd'}}
+}
+
+static_assert(f(0) == 1);
+static_assert(f(1) == 1);
+static_assert(f(2) == 2);
+static_assert(f(5) == 8);
+} // namespace CondInFor
Index: test/Parser/cxx2a-decomposition.cpp
===
--- /dev/null
+++ test/Parser/cxx2a-decomposition.cpp
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -std=c++2a %s -verify
+
+struct Na {
+  bool flag;
+  float data;
+};
+
+struct Rst {
+  bool flag;
+  float data;
+  explicit operator bool() const {
+return flag;
+  }
+};
+
+Rst f();
+Na g();
+
+namespace CondInIf {
+void h() {
+  if (auto [ok, d] = f())
+;
+  if (auto [ok, d] = g()) // expected-error {{value of type 'Na' is not contextually convertible to 'bool'}}
+;
+}
+} // namespace CondInIf
+
+namespace CondInWhile {
+void h() {
+  while (auto [ok, d] = f())
+;
+  while (auto [ok, d] = g()) // expected-error {{value of type 'Na' is not contextually convertible to 'bool'}}
+;
+}
+} // namespace CondInWhile
+
+namespace CondInFor {
+void h() {
+  for (; auto [ok, d] = f();)
+;
+  for (; auto [ok, d] = g();) // expected-error {{value of type 'Na' is not contextually convertible to 'bool'}}
+;
+}
+} // namespace CondInFor
+
+struct IntegerLike {
+  bool flag;
+  float data;
+  operator int() const {
+return int(data);
+  }
+};
+
+namespace CondInSwitch {
+void h(IntegerLike x) {
+  switch (auto [ok, d] = x)
+;
+  switch (auto [ok, d] = g()) // expected-error {{statement requires expression of integer type ('Na' invalid)}}
+;
+}
+} // namespace CondInSwitch
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -692,9 +692,10 @@
   assert(D.isDecompositionDeclarator());
   const DecompositionDeclarator &Decomp = D.getDecompositionDeclarator();
 
-  // The syntax only allows a decomposition declarator as a simple-declaration
-  // or a for-range-declaration, but we parse it in more cases than that.
-  if (!D.mayHaveDecompositionDeclarat

[PATCH] D39178: [rename] support renaming class member.

2017-10-25 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316571: [rename] support renaming class member. (authored by 
hokein).

Repository:
  rL LLVM

https://reviews.llvm.org/D39178

Files:
  cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
  cfe/trunk/unittests/Rename/CMakeLists.txt
  cfe/trunk/unittests/Rename/RenameMemberTest.cpp

Index: cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
===
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
@@ -212,6 +212,41 @@
 return true;
   }
 
+  bool VisitMemberExpr(const MemberExpr *Expr) {
+const NamedDecl *Decl = Expr->getFoundDecl();
+auto StartLoc = Expr->getMemberLoc();
+auto EndLoc = Expr->getMemberLoc();
+if (isInUSRSet(Decl)) {
+  RenameInfos.push_back({StartLoc, EndLoc,
+/*FromDecl=*/nullptr,
+/*Context=*/nullptr,
+/*Specifier=*/nullptr,
+/*IgnorePrefixQualifiers=*/true});
+}
+return true;
+  }
+
+  bool VisitCXXConstructorDecl(const CXXConstructorDecl *CD) {
+// Fix the constructor initializer when renaming class members.
+for (const auto *Initializer : CD->inits()) {
+  // Ignore implicit initializers.
+  if (!Initializer->isWritten())
+continue;
+
+  if (const FieldDecl *FD = Initializer->getMember()) {
+if (isInUSRSet(FD)) {
+  auto Loc = Initializer->getSourceLocation();
+  RenameInfos.push_back({Loc, Loc,
+ /*FromDecl=*/nullptr,
+ /*Context=*/nullptr,
+ /*Specifier=*/nullptr,
+ /*IgnorePrefixQualifiers=*/true});
+}
+  }
+}
+return true;
+  }
+
   bool VisitDeclRefExpr(const DeclRefExpr *Expr) {
 const NamedDecl *Decl = Expr->getFoundDecl();
 // Get the underlying declaration of the shadow declaration introduced by a
@@ -227,6 +262,20 @@
 ? Expr->getLAngleLoc().getLocWithOffset(-1)
 : Expr->getLocEnd();
 
+if (const auto *MD = llvm::dyn_cast(Decl)) {
+  if (isInUSRSet(MD)) {
+// Handle renaming static template class methods, we only rename the
+// name without prefix qualifiers and restrict the source range to the
+// name.
+RenameInfos.push_back({EndLoc, EndLoc,
+   /*FromDecl=*/nullptr,
+   /*Context=*/nullptr,
+   /*Specifier=*/nullptr,
+   /*IgnorePrefixQualifiers=*/true});
+return true;
+  }
+}
+
 // In case of renaming an enum declaration, we have to explicitly handle
 // unscoped enum constants referenced in expressions (e.g.
 // "auto r = ns1::ns2::Green" where Green is an enum constant of an unscoped
Index: cfe/trunk/unittests/Rename/RenameMemberTest.cpp
===
--- cfe/trunk/unittests/Rename/RenameMemberTest.cpp
+++ cfe/trunk/unittests/Rename/RenameMemberTest.cpp
@@ -0,0 +1,229 @@
+//===-- ClangMemberTests.cpp - unit tests for renaming class members --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangRenameTest.h"
+
+namespace clang {
+namespace clang_rename {
+namespace test {
+namespace {
+
+class RenameMemberTest : public ClangRenameTest {
+public:
+  RenameMemberTest() {
+AppendToHeader(R"(
+struct NA {
+  void Foo();
+  void NotFoo();
+  static void SFoo();
+  static void SNotFoo();
+  int Moo;
+};
+struct A {
+  virtual void Foo();
+  void NotFoo();
+  static void SFoo();
+  static void SNotFoo();
+  int Moo;
+  int NotMoo;
+  static int SMoo;
+};
+struct B : public A {
+  void Foo() override;
+};
+template  struct TA {
+  T* Foo();
+  T* NotFoo();
+  static T* SFoo();
+  static T* NotSFoo();
+};
+template  struct TB : public TA {};
+namespace ns {
+  template  struct TA {
+T* Foo();
+T* NotFoo();
+static T* SFoo();
+static T* NotSFoo();
+static int SMoo;
+  };
+  template  struct TB : public TA {};
+  struct A {
+void Foo();
+void NotFoo();
+static void SFoo();
+static void SNotFoo();
+  };
+

r316571 - [rename] support renaming class member.

2017-10-25 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Oct 25 04:54:45 2017
New Revision: 316571

URL: http://llvm.org/viewvc/llvm-project?rev=316571&view=rev
Log:
[rename] support renaming class member.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, cfe-commits, mgorny

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

Added:
cfe/trunk/unittests/Rename/RenameMemberTest.cpp
Modified:
cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
cfe/trunk/unittests/Rename/CMakeLists.txt

Modified: cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp?rev=316571&r1=316570&r2=316571&view=diff
==
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp Wed Oct 25 
04:54:45 2017
@@ -212,6 +212,41 @@ public:
 return true;
   }
 
+  bool VisitMemberExpr(const MemberExpr *Expr) {
+const NamedDecl *Decl = Expr->getFoundDecl();
+auto StartLoc = Expr->getMemberLoc();
+auto EndLoc = Expr->getMemberLoc();
+if (isInUSRSet(Decl)) {
+  RenameInfos.push_back({StartLoc, EndLoc,
+/*FromDecl=*/nullptr,
+/*Context=*/nullptr,
+/*Specifier=*/nullptr,
+/*IgnorePrefixQualifiers=*/true});
+}
+return true;
+  }
+
+  bool VisitCXXConstructorDecl(const CXXConstructorDecl *CD) {
+// Fix the constructor initializer when renaming class members.
+for (const auto *Initializer : CD->inits()) {
+  // Ignore implicit initializers.
+  if (!Initializer->isWritten())
+continue;
+
+  if (const FieldDecl *FD = Initializer->getMember()) {
+if (isInUSRSet(FD)) {
+  auto Loc = Initializer->getSourceLocation();
+  RenameInfos.push_back({Loc, Loc,
+ /*FromDecl=*/nullptr,
+ /*Context=*/nullptr,
+ /*Specifier=*/nullptr,
+ /*IgnorePrefixQualifiers=*/true});
+}
+  }
+}
+return true;
+  }
+
   bool VisitDeclRefExpr(const DeclRefExpr *Expr) {
 const NamedDecl *Decl = Expr->getFoundDecl();
 // Get the underlying declaration of the shadow declaration introduced by a
@@ -227,6 +262,20 @@ public:
 ? Expr->getLAngleLoc().getLocWithOffset(-1)
 : Expr->getLocEnd();
 
+if (const auto *MD = llvm::dyn_cast(Decl)) {
+  if (isInUSRSet(MD)) {
+// Handle renaming static template class methods, we only rename the
+// name without prefix qualifiers and restrict the source range to the
+// name.
+RenameInfos.push_back({EndLoc, EndLoc,
+   /*FromDecl=*/nullptr,
+   /*Context=*/nullptr,
+   /*Specifier=*/nullptr,
+   /*IgnorePrefixQualifiers=*/true});
+return true;
+  }
+}
+
 // In case of renaming an enum declaration, we have to explicitly handle
 // unscoped enum constants referenced in expressions (e.g.
 // "auto r = ns1::ns2::Green" where Green is an enum constant of an 
unscoped

Modified: cfe/trunk/unittests/Rename/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Rename/CMakeLists.txt?rev=316571&r1=316570&r2=316571&view=diff
==
--- cfe/trunk/unittests/Rename/CMakeLists.txt (original)
+++ cfe/trunk/unittests/Rename/CMakeLists.txt Wed Oct 25 04:54:45 2017
@@ -9,6 +9,7 @@ add_clang_unittest(ClangRenameTests
   RenameClassTest.cpp
   RenameEnumTest.cpp
   RenameAliasTest.cpp
+  RenameMemberTest.cpp
   RenameFunctionTest.cpp
   )
 

Added: cfe/trunk/unittests/Rename/RenameMemberTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Rename/RenameMemberTest.cpp?rev=316571&view=auto
==
--- cfe/trunk/unittests/Rename/RenameMemberTest.cpp (added)
+++ cfe/trunk/unittests/Rename/RenameMemberTest.cpp Wed Oct 25 04:54:45 2017
@@ -0,0 +1,229 @@
+//===-- ClangMemberTests.cpp - unit tests for renaming class members 
--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangRenameTest.h"
+
+namespace clang {
+namespace clang_rename {
+namespace test {
+namespace {
+
+class RenameMemberTest : public ClangRenameTest {
+public:
+  RenameMemberTest() {
+AppendToHeader(R"(
+struct NA {
+  void Foo();
+ 

[PATCH] D34272: [Tooling] A new framework for executing clang frontend actions.

2017-10-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 120232.
ioeric added a comment.

- Get rid of the unused 'createExecutorByName' interface.


https://reviews.llvm.org/D34272

Files:
  include/clang/Tooling/CommonOptionsParser.h
  include/clang/Tooling/Execution.h
  include/clang/Tooling/StandaloneExecution.h
  include/clang/Tooling/ToolExecutorPluginRegistry.h
  include/clang/Tooling/Tooling.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/CommonOptionsParser.cpp
  lib/Tooling/Execution.cpp
  lib/Tooling/StandaloneExecution.cpp
  lib/Tooling/Tooling.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/ExecutionTest.cpp

Index: unittests/Tooling/ExecutionTest.cpp
===
--- /dev/null
+++ unittests/Tooling/ExecutionTest.cpp
@@ -0,0 +1,230 @@
+//===- unittest/Tooling/ExecutionTest.cpp - Tool execution tests. ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Execution.h"
+#include "clang/Tooling/StandaloneExecution.h"
+#include "clang/Tooling/ToolExecutorPluginRegistry.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+namespace clang {
+namespace tooling {
+
+namespace {
+
+// This traverses the AST and outputs function name as key and "1" as value for
+// each function declaration.
+class ASTConsumerWithResult
+: public ASTConsumer,
+  public RecursiveASTVisitor {
+public:
+  using ASTVisitor = RecursiveASTVisitor;
+
+  explicit ASTConsumerWithResult(ExecutionContext *Context) : Context(Context) {
+assert(Context != nullptr);
+  }
+
+  void HandleTranslationUnit(clang::ASTContext &Context) override {
+TraverseDecl(Context.getTranslationUnitDecl());
+  }
+
+  bool TraverseFunctionDecl(clang::FunctionDecl *Decl) {
+Context->getToolResults()->addResult(Decl->getNameAsString(), "1");
+return ASTVisitor::TraverseFunctionDecl(Decl);
+  }
+
+private:
+  ExecutionContext *const Context;
+};
+
+class ReportResultAction : public ASTFrontendAction {
+public:
+  explicit ReportResultAction(ExecutionContext *Context) : Context(Context) {
+assert(Context != nullptr);
+  }
+
+protected:
+  std::unique_ptr
+  CreateASTConsumer(clang::CompilerInstance &compiler,
+StringRef /* dummy */) override {
+std::unique_ptr ast_consumer{
+new ASTConsumerWithResult(Context)};
+return ast_consumer;
+  }
+
+private:
+  ExecutionContext *const Context;
+};
+
+class ReportResultActionFactory : public FrontendActionFactory {
+public:
+  ReportResultActionFactory(ExecutionContext *Context) : Context(Context) {}
+  FrontendAction *create() override { return new ReportResultAction(Context); }
+
+private:
+  ExecutionContext *const Context;
+};
+
+} // namespace
+
+class TestToolExecutor : public ToolExecutor {
+public:
+  static const char *ExecutorName;
+
+  TestToolExecutor(CommonOptionsParser Options)
+  : OptionsParser(std::move(Options)) {}
+
+  StringRef getExecutorName() const override { return ExecutorName; }
+
+  llvm::Error
+  execute(llvm::ArrayRef<
+  std::pair>>)
+  override {
+return llvm::Error::success();
+  }
+
+  ExecutionContext *getExecutionContext() override { return nullptr; };
+
+  llvm::ArrayRef getSourcePaths() const {
+return OptionsParser.getSourcePathList();
+  }
+
+  void mapVirtualFile(StringRef FilePath, StringRef Content) override {
+VFS[FilePath] = Content;
+  }
+
+private:
+  CommonOptionsParser OptionsParser;
+  std::string SourcePaths;
+  std::map VFS;
+};
+
+const char *TestToolExecutor::ExecutorName = "test-executor";
+
+class TestToolExecutorPlugin : public ToolExecutorPlugin {
+public:
+  llvm::Expected>
+  create(CommonOptionsParser &OptionsParser) override {
+return llvm::make_unique(std::move(OptionsParser));
+  }
+};
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the plugin.
+extern volatile int ToolExecutorPluginAnchorSource;
+
+static int LLVM_ATTRIBUTE_UNUSED TestToolExecutorPluginAnchorDest =
+ToolExecutorPluginAnchorSource;
+
+static ToolExecutorPluginRegistry::Add
+X("test-executor", "Plugin for TestToolExecutor.");
+
+llvm::cl::OptionCategory TestCategory("execution-test options");
+
+TEST(CreateToolExecutorTest, FailedCreateExecutorUndefinedFlag) {
+  std::vector argv = {"prog", "--fake_flag_no_no_no", "f"};
+  int argc = argv.size();
+  auto Executor =
+  createExecutorFromCommandLineArgs(argc, &argv[0], Tes

[PATCH] D37470: [analyzer] Handle ObjC messages conservatively in CallDescription

2017-10-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 120233.
xazax.hun added a comment.
Herald added a subscriber: szepet.

- Modify a test to trigger the assertion fail before the patch is applied.


https://reviews.llvm.org/D37470

Files:
  lib/StaticAnalyzer/Core/CallEvent.cpp
  test/Analysis/objc-message.m


Index: test/Analysis/objc-message.m
===
--- test/Analysis/objc-message.m
+++ test/Analysis/objc-message.m
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection 
-analyzer-store=region -verify -Wno-objc-root-class %s
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,alpha.unix.BlockInCriticalSection,debug.ExprInspection 
-analyzer-store=region -verify -Wno-objc-root-class %s
 
 extern void clang_analyzer_warnIfReached();
 void clang_analyzer_eval(int);
Index: lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- lib/StaticAnalyzer/Core/CallEvent.cpp
+++ lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -211,7 +211,9 @@
 }
 
 bool CallEvent::isCalled(const CallDescription &CD) const {
-  assert(getKind() != CE_ObjCMessage && "Obj-C methods are not supported");
+  // FIXME: Add ObjC Message support.
+  if (getKind() == CE_ObjCMessage)
+return false;
   if (!CD.IsLookupDone) {
 CD.IsLookupDone = true;
 CD.II = 
&getState()->getStateManager().getContext().Idents.get(CD.FuncName);


Index: test/Analysis/objc-message.m
===
--- test/Analysis/objc-message.m
+++ test/Analysis/objc-message.m
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-store=region -verify -Wno-objc-root-class %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.BlockInCriticalSection,debug.ExprInspection -analyzer-store=region -verify -Wno-objc-root-class %s
 
 extern void clang_analyzer_warnIfReached();
 void clang_analyzer_eval(int);
Index: lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- lib/StaticAnalyzer/Core/CallEvent.cpp
+++ lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -211,7 +211,9 @@
 }
 
 bool CallEvent::isCalled(const CallDescription &CD) const {
-  assert(getKind() != CE_ObjCMessage && "Obj-C methods are not supported");
+  // FIXME: Add ObjC Message support.
+  if (getKind() == CE_ObjCMessage)
+return false;
   if (!CD.IsLookupDone) {
 CD.IsLookupDone = true;
 CD.II = &getState()->getStateManager().getContext().Idents.get(CD.FuncName);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


SemaTemplateInstantiateDecl mistakenly issuing diag::warn_func_template_missing for templated deduction guides

2017-10-25 Thread Mário Feroldi via cfe-commits
Following compilation shows the issue:

$ clang++ --version
clang version 6.0.0 (trunk 316414)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-trunk/bin

$ cat a.cpp
template 
struct S
{
  template 
  S(U&&) {}
};

template 
S(T) -> S;

int main()
{
  S s(42);
}

$ clang++ -std=c++17 -Wundefined-func-template a.cpp
a.cpp:13:7: warning: instantiation of function '' required here, but no definition is available
[-Wundefined-func-template]
S s(42);
  ^
a.cpp:9:1: note: forward declaration of template entity is here
S(T) -> S;
^
a.cpp:13:7: note: add an explicit instantiation declaration to suppress
this warning if '' is explicitly instantiated
in another translation unit
S s(42);
  ^

I found out that this warning occurs at
lib/Sema/SemaTemplateInstantiateDecl.cpp:3809:

else if (TSK == TSK_ExplicitInstantiationDefinition) {
  // Try again at the end of the translation unit (at which point a
  // definition will be required).
  assert(!Recursive);
  Function->setInstantiationIsPending(true);
  PendingInstantiations.push_back(
std::make_pair(Function, PointOfInstantiation));
} else if (TSK == TSK_ImplicitInstantiation) { //< here
  if (AtEndOfTU && !getDiagnostics().hasErrorOccurred()) {
Diag(PointOfInstantiation, diag::warn_func_template_missing)
  << Function;
Diag(PatternDecl->getLocation(), diag::note_forward_template_decl);
if (getLangOpts().CPlusPlus11)
  Diag(PointOfInstantiation, diag::note_inst_declaration_hint)
<< Function;
  }
}

Shouldn't that check whether it's a deduction guide?
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39284: [c++2a] Decomposed _condition_

2017-10-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I'm not opposed to the functionality, but this isn't a part of C++2a either; I 
think we should be diagnosing this code with a warning so users don't expect it 
to work on every compiler.


https://reviews.llvm.org/D39284



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


[PATCH] D39053: [Bitfield] Add more cases to making the bitfield a separate location

2017-10-25 Thread Strahinja Petrovic via Phabricator via cfe-commits
spetrovic added a comment.

Well, basically I'm just expanding the existing algorithm, why should we split 
fields just in case when current field is integer,
I'm not resolving specific problem with unaligned loads/stores on MIPS.

In this example:

typedef struct {

  unsigned int f1 : 28;
  unsigned int f2 : 4;
  unsigned int f3 : 12;

} S5;

S5 *cmd;

void foo() {
cmd->f3 = 5;
}

With this patch there is improvement in code size not just on MIPS 
architecture, on X86 and ARM is also improved code size. If structure S5 is 
treated as i48 type there are extra instructions for reading it not just on 
MIPS. We can take results for MIPS just for example:

Output without the patch:

 :

   0:   3c01lui at,0x0
   4:   0039082ddaddu   at,at,t9
   8:   6421daddiu  at,at,0
   c:   dc21ld  at,0(at)
  10:   dc21ld  at,0(at)
  14:   6822ldl v0,0(at)
  18:   6c220007ldr v0,7(at)
  1c:   64030005daddiu  v1,zero,5
  20:   7c62fd07dinsv0,v1,0x14,0xc
  24:   b022sdl v0,0(at)
  28:   03e8jr  ra
  2c:   b4220007sdr v0,7(at)

Output with the patch:

 :

   0:   3c01lui at,0x0
   4:   0039082ddaddu   at,at,t9
   8:   6421daddiu  at,at,0
   c:   dc21ld  at,0(at)
  10:   dc21ld  at,0(at)
  14:   94220004lhu v0,4(at)
  18:   24030005li  v1,5
  1c:   7c62f904ins v0,v1,0x4,0x1c
  20:   03e8jr  ra
  24:   a4220004sh  v0,4(at)

This is simple example, in more complicated examples there is more improvement.


https://reviews.llvm.org/D39053



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


[PATCH] D38688: [clang-tidy] Misc redundant expressions checker updated for macros

2017-10-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.
This revision is now accepted and ready to land.

LGTM! But wait for @aaron.ballman, @alexfh, or @hokein for the final word.


https://reviews.llvm.org/D38688



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


[PATCH] D39015: [Analyzer] Always use non-reference types when creating expressions in BodyFarm, removes std::call_once crash

2017-10-25 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: cfe/trunk/lib/Analysis/BodyFarm.cpp:366
+M.makeLvalueToRvalue(D->getParamDecl(i),
+ /* RefersToEnclosingVariableOrCapture= */ false));
 

george.karpenkov wrote:
> alexfh wrote:
> > Remove the spaces inside the comment. `/*ParamName=*/value` is the format 
> > that is understood by clang-format and the 
> > https://clang.llvm.org/extra/clang-tidy/checks/misc-argument-comment.html 
> > clang-tidy check. Same elsewhere in this patch.
> yeah, i can do that.
> can we also consider changing `clang-tidy` to ignore those spaces?
I've just looked at the source code, and, apparently, clang-tidy already 
understands spaces in argument comments already. Sorry for misinforming you. 
However, clang-format is more strict here and there's also the consistency 
argument (see the comment on r316539), which I find to be a good motivation to 
change this (or at least to not introduce more inconsistency).


Repository:
  rL LLVM

https://reviews.llvm.org/D39015



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


[PATCH] D38126: Make TBAA information to be part of LValueBaseInfo

2017-10-25 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev abandoned this revision.
kosarev added a comment.

Indeed, if LValueBaseInfo is what we know about the very first value in a 
sequence, then TBAA info certainly should not be part of it. This also means 
whatever is specified as a direct base lvalue to the lvalue we are constructing 
should probably be passed as LValue, as suggested in 
https://reviews.llvm.org/D39177.

Thanks!


https://reviews.llvm.org/D38126



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


r316577 - Add support of the next Ubuntu (Ubuntu 18.04 - Bionic Beaver)

2017-10-25 Thread Sylvestre Ledru via cfe-commits
Author: sylvestre
Date: Wed Oct 25 07:21:33 2017
New Revision: 316577

URL: http://llvm.org/viewvc/llvm-project?rev=316577&view=rev
Log:
Add support of the next Ubuntu (Ubuntu 18.04 - Bionic Beaver)


Modified:
cfe/trunk/include/clang/Driver/Distro.h
cfe/trunk/lib/Driver/Distro.cpp

Modified: cfe/trunk/include/clang/Driver/Distro.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Distro.h?rev=316577&r1=316576&r2=316577&view=diff
==
--- cfe/trunk/include/clang/Driver/Distro.h (original)
+++ cfe/trunk/include/clang/Driver/Distro.h Wed Oct 25 07:21:33 2017
@@ -58,6 +58,7 @@ public:
 UbuntuYakkety,
 UbuntuZesty,
 UbuntuArtful,
+UbuntuBionic,
 UnknownDistro
   };
 

Modified: cfe/trunk/lib/Driver/Distro.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Distro.cpp?rev=316577&r1=316576&r2=316577&view=diff
==
--- cfe/trunk/lib/Driver/Distro.cpp (original)
+++ cfe/trunk/lib/Driver/Distro.cpp Wed Oct 25 07:21:33 2017
@@ -48,6 +48,7 @@ static Distro::DistroType DetectDistro(v
   .Case("yakkety", Distro::UbuntuYakkety)
   .Case("zesty", Distro::UbuntuZesty)
   .Case("artful", Distro::UbuntuArtful)
+  .Case("bionic", Distro::UbuntuBionic)
   .Default(Distro::UnknownDistro);
 if (Version != Distro::UnknownDistro)
   return Version;


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


r316578 - Also update IsUbuntu() with Ubuntu Bionic

2017-10-25 Thread Sylvestre Ledru via cfe-commits
Author: sylvestre
Date: Wed Oct 25 07:23:27 2017
New Revision: 316578

URL: http://llvm.org/viewvc/llvm-project?rev=316578&view=rev
Log:
Also update IsUbuntu() with Ubuntu Bionic
Follow up of r316577


Modified:
cfe/trunk/include/clang/Driver/Distro.h

Modified: cfe/trunk/include/clang/Driver/Distro.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Distro.h?rev=316578&r1=316577&r2=316578&view=diff
==
--- cfe/trunk/include/clang/Driver/Distro.h (original)
+++ cfe/trunk/include/clang/Driver/Distro.h Wed Oct 25 07:23:27 2017
@@ -112,7 +112,7 @@ public:
   }
 
   bool IsUbuntu() const {
-return DistroVal >= UbuntuHardy && DistroVal <= UbuntuArtful;
+return DistroVal >= UbuntuHardy && DistroVal <= UbuntuBionic;
   }
 
   /// @}


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


r316579 - Add support of the next Debian (Debian buster - version 10)

2017-10-25 Thread Sylvestre Ledru via cfe-commits
Author: sylvestre
Date: Wed Oct 25 07:25:28 2017
New Revision: 316579

URL: http://llvm.org/viewvc/llvm-project?rev=316579&view=rev
Log:
Add support of the next Debian (Debian buster - version 10)


Modified:
cfe/trunk/include/clang/Driver/Distro.h
cfe/trunk/lib/Driver/Distro.cpp

Modified: cfe/trunk/include/clang/Driver/Distro.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Distro.h?rev=316579&r1=316578&r2=316579&view=diff
==
--- cfe/trunk/include/clang/Driver/Distro.h (original)
+++ cfe/trunk/include/clang/Driver/Distro.h Wed Oct 25 07:25:28 2017
@@ -32,6 +32,7 @@ public:
 DebianWheezy,
 DebianJessie,
 DebianStretch,
+DebianBuster,
 Exherbo,
 RHEL5,
 RHEL6,
@@ -108,7 +109,7 @@ public:
   }
 
   bool IsDebian() const {
-return DistroVal >= DebianLenny && DistroVal <= DebianStretch;
+return DistroVal >= DebianLenny && DistroVal <= DebianBuster;
   }
 
   bool IsUbuntu() const {

Modified: cfe/trunk/lib/Driver/Distro.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Distro.cpp?rev=316579&r1=316578&r2=316579&view=diff
==
--- cfe/trunk/lib/Driver/Distro.cpp (original)
+++ cfe/trunk/lib/Driver/Distro.cpp Wed Oct 25 07:25:28 2017
@@ -89,6 +89,8 @@ static Distro::DistroType DetectDistro(v
 return Distro::DebianJessie;
   case 9:
 return Distro::DebianStretch;
+  case 10:
+return Distro::DebianBuster;
   default:
 return Distro::UnknownDistro;
   }


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


[PATCH] D39239: [AST] Incorrectly qualified unscoped enumeration as template actual parameter.

2017-10-25 Thread Carlos Alberto Enciso via Phabricator via cfe-commits
CarlosAlbertoEnciso added a comment.

In https://reviews.llvm.org/D39239#905641, @probinson wrote:

> Have you tried this change against the GDB and LLDB test suites?  If they 
> have failures then we should think about whether those tests are 
> over-specific or whether we should put this under a tuning option.


I double check the LLDB test suite and there are 3 cases that fail with this 
patch. But the DWARF generated is correct, as the template name is encoded 
correctly:

  DW_TAG_compile_unit "main.cpp"
DW_AT_producer "clang version 6.0.0 (trunk 316571)"
DW_AT_comp_dir 
"/home/carlos/llvm-root/llvm/tools/lldb/packages/Python/lldbsuite/test/lang/cpp/template"
...
DW_TAG_enumeration_type "EnumType"
  DW_AT_enum_class DW_FORM_flag_present
  DW_TAG_enumerator "Member"
  DW_TAG_enumerator "Subclass"
  ...
DW_TAG_class_type "EnumTemplate"
  ...
DW_TAG_class_type "EnumTemplate"
  ...

I will investigate the issue, as the test case should pass as it does not use 
unscope enums, which is what the patch should affect.


https://reviews.llvm.org/D39239



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


[PATCH] D34158: For Linux/gnu compatibility, preinclude if the file is available

2017-10-25 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

In https://reviews.llvm.org/D34158#905637, @mibintc wrote:

> In https://reviews.llvm.org/D34158#905596, @jyknight wrote:
>
> > I'd still _very_ much like a solution that is acceptable for all libc to 
> > use, and have that on by default.
> >
> > However, I guess this is fine.
> >
> > Only concern I have is that it seems odd that so many test-cases needed to 
> > be changed. What fails without those test changes?
>
>
> Those tests fail because they generate preprocessed output and then check 
> carefully for precise results. Since the preprocessed output is different, 
> the comparison fails. I "fixed" the tests by adding the freestanding option 
> which inhibits the new behavior.  I'll have to check out and rebuild 
> everything so I can show you exactly the failure mode, I expect I can post 
> details tomorrow.


I created a fresh workspace and applied the patch, then I make "check-clang". I 
saw one test fail. The test that failed is Driver/crash-report.c. (BTW I need 
to recheck all the tests and make sure the test modifications are still needed, 
and likewise in the "extra" tests directory which is in the separate patch 
file).  This is the failure mode for the Driver crash report.  Is this 
sufficient detail to understand the test issue? If not what else can I provide?
llvm/tools/clang/test/Driver/crash-report.c
Exit Code: 1

Command Output (stderr):


/site/spt/usr20/mblower/sptel9-ws/llorg/llvm/tools/clang/test/Driver/crash-report.c:20:11:
 error: expected string not found in input
// CHECK: Preprocessed source(s) and associated run script(s) are located at:

  ^

:1:1: note: scanning from here
:1:10: fatal error: '-fobjc-runtime=gcc' file not found
^

If I make this change, adding the freestanding option, and rebuild 
"check-clang", then no tests are failing:
diff --git a/test/Driver/crash-report.c b/test/Driver/crash-report.c
index a3f1f9e..526e4dd 100644

- a/test/Driver/crash-report.c

+++ b/test/Driver/crash-report.c
@@ -2,7 +2,7 @@
 // RUN: mkdir %t
 // RUN: not env TMPDIR=%t TEMP=%t TMP=%t RC_DEBUG_OPTIONS=1  \
 // RUN:  CC_PRINT_HEADERS=1 CC_LOG_DIAGNOSTICS=1 \
-// RUN:  %clang -fsyntax-only %s \
+// RUN:  %clang -fsyntax-only -ffreestanding %s
 // RUN:  -F/tmp/ -I /tmp/ -idirafter /tmp/ -iquote /tmp/ -isystem /tmp/  \
 // RUN:  -iprefix /the/prefix -iwithprefix /tmp -iwithprefixbefore /tmp/ \
 // RUN:  -Xclang -internal-isystem -Xclang /tmp/ \


https://reviews.llvm.org/D34158



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


[PATCH] D34272: [Tooling] A new framework for executing clang frontend actions.

2017-10-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 120250.
ioeric added a comment.

- Only expose result reporting interface from ExecutionContext so that 
callbacks don't have access to results.


https://reviews.llvm.org/D34272

Files:
  include/clang/Tooling/CommonOptionsParser.h
  include/clang/Tooling/Execution.h
  include/clang/Tooling/StandaloneExecution.h
  include/clang/Tooling/ToolExecutorPluginRegistry.h
  include/clang/Tooling/Tooling.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/CommonOptionsParser.cpp
  lib/Tooling/Execution.cpp
  lib/Tooling/StandaloneExecution.cpp
  lib/Tooling/Tooling.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/ExecutionTest.cpp

Index: unittests/Tooling/ExecutionTest.cpp
===
--- /dev/null
+++ unittests/Tooling/ExecutionTest.cpp
@@ -0,0 +1,228 @@
+//===- unittest/Tooling/ExecutionTest.cpp - Tool execution tests. ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Execution.h"
+#include "clang/Tooling/StandaloneExecution.h"
+#include "clang/Tooling/ToolExecutorPluginRegistry.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+namespace clang {
+namespace tooling {
+
+namespace {
+
+// This traverses the AST and outputs function name as key and "1" as value for
+// each function declaration.
+class ASTConsumerWithResult
+: public ASTConsumer,
+  public RecursiveASTVisitor {
+public:
+  using ASTVisitor = RecursiveASTVisitor;
+
+  explicit ASTConsumerWithResult(ExecutionContext *Context) : Context(Context) {
+assert(Context != nullptr);
+  }
+
+  void HandleTranslationUnit(clang::ASTContext &Context) override {
+TraverseDecl(Context.getTranslationUnitDecl());
+  }
+
+  bool TraverseFunctionDecl(clang::FunctionDecl *Decl) {
+Context->reportResult(Decl->getNameAsString(), "1");
+return ASTVisitor::TraverseFunctionDecl(Decl);
+  }
+
+private:
+  ExecutionContext *const Context;
+};
+
+class ReportResultAction : public ASTFrontendAction {
+public:
+  explicit ReportResultAction(ExecutionContext *Context) : Context(Context) {
+assert(Context != nullptr);
+  }
+
+protected:
+  std::unique_ptr
+  CreateASTConsumer(clang::CompilerInstance &compiler,
+StringRef /* dummy */) override {
+std::unique_ptr ast_consumer{
+new ASTConsumerWithResult(Context)};
+return ast_consumer;
+  }
+
+private:
+  ExecutionContext *const Context;
+};
+
+class ReportResultActionFactory : public FrontendActionFactory {
+public:
+  ReportResultActionFactory(ExecutionContext *Context) : Context(Context) {}
+  FrontendAction *create() override { return new ReportResultAction(Context); }
+
+private:
+  ExecutionContext *const Context;
+};
+
+} // namespace
+
+class TestToolExecutor : public ToolExecutor {
+public:
+  static const char *ExecutorName;
+
+  TestToolExecutor(CommonOptionsParser Options)
+  : OptionsParser(std::move(Options)) {}
+
+  StringRef getExecutorName() const override { return ExecutorName; }
+
+  llvm::Error
+  execute(llvm::ArrayRef<
+  std::pair>>)
+  override {
+return llvm::Error::success();
+  }
+
+  ExecutionContext *getExecutionContext() override { return nullptr; };
+
+  ToolResults *getToolResults() override { return nullptr; }
+
+  llvm::ArrayRef getSourcePaths() const {
+return OptionsParser.getSourcePathList();
+  }
+
+  void mapVirtualFile(StringRef FilePath, StringRef Content) override {
+VFS[FilePath] = Content;
+  }
+
+private:
+  CommonOptionsParser OptionsParser;
+  std::string SourcePaths;
+  std::map VFS;
+};
+
+const char *TestToolExecutor::ExecutorName = "test-executor";
+
+class TestToolExecutorPlugin : public ToolExecutorPlugin {
+public:
+  llvm::Expected>
+  create(CommonOptionsParser &OptionsParser) override {
+return llvm::make_unique(std::move(OptionsParser));
+  }
+};
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the plugin.
+extern volatile int ToolExecutorPluginAnchorSource;
+
+static int LLVM_ATTRIBUTE_UNUSED TestToolExecutorPluginAnchorDest =
+ToolExecutorPluginAnchorSource;
+
+static ToolExecutorPluginRegistry::Add
+X("test-executor", "Plugin for TestToolExecutor.");
+
+llvm::cl::OptionCategory TestCategory("execution-test options");
+
+TEST(CreateToolExecutorTest, FailedCreateExecutorUndefinedFlag) {
+  std::vector argv = {"prog", "--fake_flag_no_no_no", "f"};
+  

[PATCH] D37808: [clang-tidy] Add new hicpp-multiway-paths-covered check for missing branches

2017-10-25 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

simplified the if-else stuff


https://reviews.llvm.org/D37808



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


[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.

2017-10-25 Thread kchoi via Phabricator via cfe-commits
choikwa updated this revision to Diff 120252.
choikwa added a comment.

rebase to trunk


https://reviews.llvm.org/D37624

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/instrument-functions.c
  test/CodeGenCXX/instrument-functions.cpp

Index: test/CodeGenCXX/instrument-functions.cpp
===
--- test/CodeGenCXX/instrument-functions.cpp
+++ test/CodeGenCXX/instrument-functions.cpp
@@ -1,10 +1,32 @@
 // RUN: %clang_cc1 -S -emit-llvm -triple %itanium_abi_triple -o - %s -finstrument-functions | FileCheck %s
 
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s
+// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR
+
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC
+
+// Below would see if mangled name partially matches. exclude-function-list matches demangled names, thus we expect to see instrument calls in test3.
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test3 | FileCheck %s --check-prefix=NOFUNC2
+
+
 // CHECK: @_Z5test1i
+// NOINSTR: @_Z5test1i
+// NOFILE: @_Z5test1i
+// NOFUNC: @_Z5test1i
 int test1(int x) {
 // CHECK: __cyg_profile_func_enter
 // CHECK: __cyg_profile_func_exit
 // CHECK: ret
+// NOINSTR-NOT: __cyg_profile_func_enter
+// NOINSTR-NOT: __cyg_profile_func_exit
+// NOINSTR: ret
+// NOFILE-NOT: __cyg_profile_func_enter
+// NOFILE-NOT: __cyg_profile_func_exit
+// NOFILE: ret
+// NOFUNC: __cyg_profile_func_enter
+// NOFUNC: __cyg_profile_func_exit
+// NOFUNC: ret
   return x;
 }
 
@@ -17,6 +39,93 @@
   return x;
 }
 
+// CHECK: @_Z5test3i
+// NOINSTR: @_Z5test3i
+// NOFILE: @_Z5test3i
+// NOFUNC: @_Z5test3i
+// NOFUNC2: @_Z5test3i
+int test3(int x) {
+// CHECK: __cyg_profile_func_enter
+// CHECK: __cyg_profile_func_exit
+// CHECK: ret
+// NOINSTR-NOT: __cyg_profile_func_enter
+// NOINSTR-NOT: __cyg_profile_func_exit
+// NOINSTR: ret
+// NOFILE-NOT: __cyg_profile_func_enter
+// NOFILE-NOT: __cyg_profile_func_exit
+// NOFILE: ret
+// NOFUNC-NOT: __cyg_profile_func_enter
+// NOFUNC-NOT: __cyg_profile_func_exit
+// NOFUNC: ret
+// NOFUNC2: __cyg_profile_func_enter
+// NOFUNC2: __cyg_profile_func_exit
+// NOFUNC2: ret
+  return x;
+}
+
+// Check function overload
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=OVERLOAD
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test3v | FileCheck %s --check-prefix=OVERLOAD1
+
+// OVERLOAD: @_Z5test3v
+// OVERLOAD1: @_Z5test3v
+int test3() {
+// OVERLOAD-NOT: __cyg_profile_func_enter
+// OVERLOAD-NOT: __cyg_profile_func_exit
+// OVERLOAD: ret
+// OVERLOAD1: __cyg_profile_func_enter
+// OVERLOAD1: __cyg_profile_func_exit
+// OVERLOAD1: ret
+  return 1;
+}
+
+template 
+T test4(T a) {
+  return a;
+}
+
+// Check function with template specialization
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test4 | FileCheck %s --check-prefix=TPL
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test4Ii | FileCheck %s --check-prefix=TPL1
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test4Is | FileCheck %s --check-prefix=TPL2
+
+// TPL: @_Z5test4IiET_S0_
+// TPL1: @_Z5test4IiET_S0_
+template<>
+int test4(int a) {
+// TPL-NOT: __cyg_profile_func_enter
+// TPL-NOT: __cyg_profile_func_exit
+// TPL: ret
+// TPL1: __cyg_profile_func_enter
+// TPL1: __cyg_profile_func_exit
+// TPL1: ret
+  return a;
+}
+
+// TPL: @_Z5test4IsET_S0_
+// TPL2: @_Z5test4IsET_S0_
+template<>
+short test4(short a) {
+// TPL-NOT: __cyg_profile_func_enter
+// TPL-NOT: __cyg_profile_func_exit
+// TPL: ret
+// TPL2: __cyg_profile_func_enter
+// TPL2: __cyg_profile_func_exit
+// TPL2: ret
+  return a;
+}
+
+// Check whitespace
+// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list='int test5 (float f, int a, int *p)' | FileCheck %s --check-prefix=WSTEST
+// WSTEST: @_Z5test5fiPi
+int test5 (float f, int a, int *p) {
+// WSTEST-NOT: __cyg_profile_func_enter
+// WSTEST-NOT: __cyg_profile_func_exit
+// WSTEST-NOT: ret
+  *p = (int)f + a;
+  return *p;
+}
+
 // This test case previously crashed code generation.  It exists solely
 // to test -finstrum

[PATCH] D37808: [clang-tidy] Add new hicpp-multiway-paths-covered check for missing branches

2017-10-25 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 120251.
JonasToth marked 8 inline comments as done.
JonasToth added a comment.

- Merge 'master'
- address review comments


https://reviews.llvm.org/D37808

Files:
  clang-tidy/hicpp/CMakeLists.txt
  clang-tidy/hicpp/HICPPTidyModule.cpp
  clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
  clang-tidy/hicpp/MultiwayPathsCoveredCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/hicpp-multiway-paths-covered.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/hicpp-multiway-paths-covered-else.cpp
  test/clang-tidy/hicpp-multiway-paths-covered.cpp

Index: test/clang-tidy/hicpp-multiway-paths-covered.cpp
===
--- /dev/null
+++ test/clang-tidy/hicpp-multiway-paths-covered.cpp
@@ -0,0 +1,445 @@
+// RUN: %check_clang_tidy %s hicpp-multiway-paths-covered %t
+
+enum OS { Mac,
+  Windows,
+  Linux };
+
+struct Bitfields {
+  unsigned UInt : 3;
+  int SInt : 1;
+};
+
+int return_integer() { return 42; }
+
+void bad_switch(int i) {
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch with only one case; use if statement
+  case 0:
+break;
+  }
+  // No default in this switch
+  switch (i) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered codepath; add a default case
+  case 0:
+break;
+  case 1:
+break;
+  case 2:
+break;
+  }
+
+  // degenerate, maybe even warning
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: degenerated switch without labels
+  }
+
+  switch (int j = return_integer()) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered codepath; add a default case
+  case 0:
+  case 1:
+  case 2:
+break;
+  }
+
+  // Degenerated, only default case.
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: degenerated switch with default label only
+  default:
+break;
+  }
+
+  // Degenerated, only one case label and default case -> Better as if-stmt.
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch could be better written as if/else statement
+  case 0:
+break;
+  default:
+break;
+  }
+
+  unsigned long long BigNumber = 0;
+  switch (BigNumber) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered codepath; add a default case
+  case 0:
+  case 1:
+break;
+  }
+
+  const int &IntRef = i;
+  switch (IntRef) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered codepath; add a default case
+  case 0:
+  case 1:
+break;
+  }
+
+  char C = 'A';
+  switch (C) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered codepath; add a default case
+  case 'A':
+break;
+  case 'B':
+break;
+  }
+
+  Bitfields Bf;
+  // UInt has 3 bits size.
+  switch (Bf.UInt) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered codepath; add a default case
+  case 0:
+  case 1:
+break;
+  }
+  // All paths explicitly covered.
+  switch (Bf.UInt) {
+  case 0:
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+  case 5:
+  case 6:
+  case 7:
+break;
+  }
+  // SInt has 1 bit size, so this is somewhat degenerated.
+  switch (Bf.SInt) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch with only one case; use if statement
+  case 0:
+break;
+  }
+  // All paths explicitly covered.
+  switch (Bf.SInt) {
+  case 0:
+  case 1:
+break;
+  }
+}
+
+void unproblematic_switch(unsigned char c) {
+  switch (c) {
+  case 0:
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+  case 5:
+  case 6:
+  case 7:
+  case 8:
+  case 9:
+  case 10:
+  case 11:
+  case 12:
+  case 13:
+  case 14:
+  case 15:
+  case 16:
+  case 17:
+  case 18:
+  case 19:
+  case 20:
+  case 21:
+  case 22:
+  case 23:
+  case 24:
+  case 25:
+  case 26:
+  case 27:
+  case 28:
+  case 29:
+  case 30:
+  case 31:
+  case 32:
+  case 33:
+  case 34:
+  case 35:
+  case 36:
+  case 37:
+  case 38:
+  case 39:
+  case 40:
+  case 41:
+  case 42:
+  case 43:
+  case 44:
+  case 45:
+  case 46:
+  case 47:
+  case 48:
+  case 49:
+  case 50:
+  case 51:
+  case 52:
+  case 53:
+  case 54:
+  case 55:
+  case 56:
+  case 57:
+  case 58:
+  case 59:
+  case 60:
+  case 61:
+  case 62:
+  case 63:
+  case 64:
+  case 65:
+  case 66:
+  case 67:
+  case 68:
+  case 69:
+  case 70:
+  case 71:
+  case 72:
+  case 73:
+  case 74:
+  case 75:
+  case 76:
+  case 77:
+  case 78:
+  case 79:
+  case 80:
+  case 81:
+  case 82:
+  case 83:
+  case 84:
+  case 85:
+  case 86:
+  case 87:
+  case 88:
+  case 89:
+  case 90:
+  case 91:
+  case 92:
+  case 93:
+  case 94:
+  case 95:
+  case 96:
+  case 97:
+  case 98:
+  case 99:
+  case 100:
+  case 101:
+  case 102:
+  case 103:
+  case 104:
+  case 105:
+  case 106:
+  case 107:
+  case 108:
+  case 109:
+  case 110:
+  case 111:
+  case 112:
+  case 113:
+  case 114:
+  case 115:
+  case 116:
+  case 117:
+  case 118:
+  case 119:
+  case 120:
+  case 121:
+  case 122:
+  case 123:
+  case 124:
+  case 125:
+  case 

[PATCH] D34272: [Tooling] A new framework for executing clang frontend actions.

2017-10-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 120254.
ioeric added a comment.

- Minor comment update.


https://reviews.llvm.org/D34272

Files:
  include/clang/Tooling/CommonOptionsParser.h
  include/clang/Tooling/Execution.h
  include/clang/Tooling/StandaloneExecution.h
  include/clang/Tooling/ToolExecutorPluginRegistry.h
  include/clang/Tooling/Tooling.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/CommonOptionsParser.cpp
  lib/Tooling/Execution.cpp
  lib/Tooling/StandaloneExecution.cpp
  lib/Tooling/Tooling.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/ExecutionTest.cpp

Index: unittests/Tooling/ExecutionTest.cpp
===
--- /dev/null
+++ unittests/Tooling/ExecutionTest.cpp
@@ -0,0 +1,228 @@
+//===- unittest/Tooling/ExecutionTest.cpp - Tool execution tests. ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Execution.h"
+#include "clang/Tooling/StandaloneExecution.h"
+#include "clang/Tooling/ToolExecutorPluginRegistry.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+namespace clang {
+namespace tooling {
+
+namespace {
+
+// This traverses the AST and outputs function name as key and "1" as value for
+// each function declaration.
+class ASTConsumerWithResult
+: public ASTConsumer,
+  public RecursiveASTVisitor {
+public:
+  using ASTVisitor = RecursiveASTVisitor;
+
+  explicit ASTConsumerWithResult(ExecutionContext *Context) : Context(Context) {
+assert(Context != nullptr);
+  }
+
+  void HandleTranslationUnit(clang::ASTContext &Context) override {
+TraverseDecl(Context.getTranslationUnitDecl());
+  }
+
+  bool TraverseFunctionDecl(clang::FunctionDecl *Decl) {
+Context->reportResult(Decl->getNameAsString(), "1");
+return ASTVisitor::TraverseFunctionDecl(Decl);
+  }
+
+private:
+  ExecutionContext *const Context;
+};
+
+class ReportResultAction : public ASTFrontendAction {
+public:
+  explicit ReportResultAction(ExecutionContext *Context) : Context(Context) {
+assert(Context != nullptr);
+  }
+
+protected:
+  std::unique_ptr
+  CreateASTConsumer(clang::CompilerInstance &compiler,
+StringRef /* dummy */) override {
+std::unique_ptr ast_consumer{
+new ASTConsumerWithResult(Context)};
+return ast_consumer;
+  }
+
+private:
+  ExecutionContext *const Context;
+};
+
+class ReportResultActionFactory : public FrontendActionFactory {
+public:
+  ReportResultActionFactory(ExecutionContext *Context) : Context(Context) {}
+  FrontendAction *create() override { return new ReportResultAction(Context); }
+
+private:
+  ExecutionContext *const Context;
+};
+
+} // namespace
+
+class TestToolExecutor : public ToolExecutor {
+public:
+  static const char *ExecutorName;
+
+  TestToolExecutor(CommonOptionsParser Options)
+  : OptionsParser(std::move(Options)) {}
+
+  StringRef getExecutorName() const override { return ExecutorName; }
+
+  llvm::Error
+  execute(llvm::ArrayRef<
+  std::pair>>)
+  override {
+return llvm::Error::success();
+  }
+
+  ExecutionContext *getExecutionContext() override { return nullptr; };
+
+  ToolResults *getToolResults() override { return nullptr; }
+
+  llvm::ArrayRef getSourcePaths() const {
+return OptionsParser.getSourcePathList();
+  }
+
+  void mapVirtualFile(StringRef FilePath, StringRef Content) override {
+VFS[FilePath] = Content;
+  }
+
+private:
+  CommonOptionsParser OptionsParser;
+  std::string SourcePaths;
+  std::map VFS;
+};
+
+const char *TestToolExecutor::ExecutorName = "test-executor";
+
+class TestToolExecutorPlugin : public ToolExecutorPlugin {
+public:
+  llvm::Expected>
+  create(CommonOptionsParser &OptionsParser) override {
+return llvm::make_unique(std::move(OptionsParser));
+  }
+};
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the plugin.
+extern volatile int ToolExecutorPluginAnchorSource;
+
+static int LLVM_ATTRIBUTE_UNUSED TestToolExecutorPluginAnchorDest =
+ToolExecutorPluginAnchorSource;
+
+static ToolExecutorPluginRegistry::Add
+X("test-executor", "Plugin for TestToolExecutor.");
+
+llvm::cl::OptionCategory TestCategory("execution-test options");
+
+TEST(CreateToolExecutorTest, FailedCreateExecutorUndefinedFlag) {
+  std::vector argv = {"prog", "--fake_flag_no_no_no", "f"};
+  int argc = argv.size();
+  auto Executor =
+  createExecutorFromCommandLineArgs(argc

[PATCH] D34272: [Tooling] A new framework for executing clang frontend actions.

2017-10-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: include/clang/Tooling/Execution.h:51-53
+  virtual std::vector> AllKVResults() = 0;
+  virtual void forEachResult(
+  llvm::function_ref Callback) = 0;

ioeric wrote:
> klimek wrote:
> > Why do we need to get the results via the interface? For example, in a 
> > map/reduce style setup getting the results is infeasible.
> This would enable tools to access results regardless of the underlying 
> representation of the results.
> 
> In a map/reduce style execution, we could have an implementation that deals 
> with fetching and reading remote files; information about remote files can be 
> fed into the implementation from the executor that performs such execution. 
> It might make sense to add an interface that returns the metadata about the 
> underlying data though (e.g. URI for remote files). WDYT?
After offline discussion, I now understand the concern about having tool 
callbacks be able to access results.

I've changed the `ExecutionContext` to only expose a result reporting interface 
instead of returning a reference of `ToolResults` - callbacks are expected to 
only have access to `ExecutionContext`. The `ToolResults` would only be 
available from the executor itself.


https://reviews.llvm.org/D34272



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


[PATCH] D39138: [CodeGen] Generate TBAA info for 'this' pointers

2017-10-25 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev added a comment.

Hmm, according to our research such loads constitute about 18% of all loads 
under ##-O -Xclang -disable-llvm-passes## on the LLVM code base. I wonder, do 
you think it would be nice to not generate them at all? I mean, provided that 
necessary changes do not add too much special-case code.


Repository:
  rL LLVM

https://reviews.llvm.org/D39138



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


[PATCH] D34158: For Linux/gnu compatibility, preinclude if the file is available

2017-10-25 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

I pulled out all the test changes and the only one that is needed presently is 
Clang :: Driver/crash-report.c; huh, that's different than what I encountered 
earlier in the summer.  Now I'll recheck those extra tests.


https://reviews.llvm.org/D34158



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


[PATCH] D34272: [Tooling] A new framework for executing clang frontend actions.

2017-10-25 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: include/clang/Tooling/Execution.h:76
+
+  void appendArgumentsAdjuster(ArgumentsAdjuster Adjuster);
+

I think the argument adjuster adjustment shouldn't be part of this interface, 
as the argument adjusters cannot be changed in the phase in which we want the 
ExecutionContext to be used.

I'd just make the argument adjusters a parameter on the constructor here (or 
alternatively, do not couple them in here, and just hand them around as a 
separate entity).



Comment at: include/clang/Tooling/Execution.h:130-131
+  /// context.
+  llvm::Error execute(ArgumentsAdjuster Adjuster,
+  std::unique_ptr Action);
+

I'd put the ArgumentAdjust second (as the action is the primary thing being 
acted on).



https://reviews.llvm.org/D34272



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


[PATCH] D39290: [rename] Use SymbolOccurrence in RenameLocFinder.

2017-10-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
Herald added a subscriber: klimek.

This is first step to integrate qualified rename into clang-refactor.

Also a few changes to SymbolOccurrence:

- add more information to SymbolOccurrence
- remove the way of using SourceLocation as the array size


https://reviews.llvm.org/D39290

Files:
  include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
  lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
  lib/Tooling/Refactoring/Rename/USRLocFinder.cpp

Index: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
===
--- lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
@@ -158,27 +158,6 @@
   RenameLocFinder(llvm::ArrayRef USRs, ASTContext &Context)
   : USRSet(USRs.begin(), USRs.end()), Context(Context) {}
 
-  // A structure records all information of a symbol reference being renamed.
-  // We try to add as few prefix qualifiers as possible.
-  struct RenameInfo {
-// The begin location of a symbol being renamed.
-SourceLocation Begin;
-// The end location of a symbol being renamed.
-SourceLocation End;
-// The declaration of a symbol being renamed (can be nullptr).
-const NamedDecl *FromDecl;
-// The declaration in which the nested name is contained (can be nullptr).
-const Decl *Context;
-// The nested name being replaced (can be nullptr).
-const NestedNameSpecifier *Specifier;
-// Determine whether the prefix qualifiers of the NewName should be ignored.
-// Normally, we set it to true for the symbol declaration and definition to
-// avoid adding prefix qualifiers.
-// For example, if it is true and NewName is "a::b::foo", then the symbol
-// occurrence which the RenameInfo points to will be renamed to "foo".
-bool IgnorePrefixQualifers;
-  };
-
   bool VisitNamedDecl(const NamedDecl *Decl) {
 // UsingDecl has been handled in other place.
 if (llvm::isa(Decl))
@@ -200,13 +179,7 @@
   auto StartLoc = Decl->getLocation();
   auto EndLoc = StartLoc;
   if (IsValidEditLoc(Context.getSourceManager(), StartLoc)) {
-RenameInfo Info = {StartLoc,
-   EndLoc,
-   /*FromDecl=*/nullptr,
-   /*Context=*/nullptr,
-   /*Specifier=*/nullptr,
-   /*IgnorePrefixQualifers=*/true};
-RenameInfos.push_back(Info);
+addSymbolOccurence(StartLoc, EndLoc);
   }
 }
 return true;
@@ -217,11 +190,7 @@
 auto StartLoc = Expr->getMemberLoc();
 auto EndLoc = Expr->getMemberLoc();
 if (isInUSRSet(Decl)) {
-  RenameInfos.push_back({StartLoc, EndLoc,
-/*FromDecl=*/nullptr,
-/*Context=*/nullptr,
-/*Specifier=*/nullptr,
-/*IgnorePrefixQualifiers=*/true});
+  addSymbolOccurence(StartLoc, EndLoc);
 }
 return true;
   }
@@ -236,11 +205,7 @@
   if (const FieldDecl *FD = Initializer->getMember()) {
 if (isInUSRSet(FD)) {
   auto Loc = Initializer->getSourceLocation();
-  RenameInfos.push_back({Loc, Loc,
- /*FromDecl=*/nullptr,
- /*Context=*/nullptr,
- /*Specifier=*/nullptr,
- /*IgnorePrefixQualifiers=*/true});
+  addSymbolOccurence(Loc, Loc);
 }
   }
 }
@@ -267,11 +232,7 @@
 // Handle renaming static template class methods, we only rename the
 // name without prefix qualifiers and restrict the source range to the
 // name.
-RenameInfos.push_back({EndLoc, EndLoc,
-   /*FromDecl=*/nullptr,
-   /*Context=*/nullptr,
-   /*Specifier=*/nullptr,
-   /*IgnorePrefixQualifiers=*/true});
+addSymbolOccurence(EndLoc, EndLoc);
 return true;
   }
 }
@@ -309,13 +270,12 @@
 }
 if (isInUSRSet(Decl) &&
 IsValidEditLoc(Context.getSourceManager(), StartLoc)) {
-  RenameInfo Info = {StartLoc,
+  addSymbolOccurence(StartLoc,
  EndLoc,
  Decl,
  getClosestAncestorDecl(*Expr),
  Expr->getQualifier(),
- /*IgnorePrefixQualifers=*/false};
-  RenameInfos.push_back(Info);
+ /*IgnorePrefixQualifers=*/false);
 }
 
 return true;
@@ -338,13 +298,11 @@
 if (const auto *TargetDecl =
 getSupportedDeclFromTypeLoc(NestedLoc.getTypeLoc())) {
   if (isInUSRSet(TargetDecl)) {
-RenameInfo Info = {NestedLoc.getBeginLoc(),
+addSymbolOccurence(NestedLoc.getBeginLoc(),
EndLocationForType(NestedL

[PATCH] D38985: [refactor] Add support for editor commands that connect IDEs/editors to the refactoring actions

2017-10-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: include/clang/Tooling/Refactoring/RefactoringActionRule.h:60
+  /// associated with this rule.
+  virtual Optional> getEditorCommandInfo() {
+return None;

I think `getEditorCommandInfo` might be a wrong name here.

IMO, all end rules (i.e. editor-facing rules) should have name information. It 
might make sense to introduce a structure that holds all metadata about a rule 
as well as an interface that returns such a structure. With that, we also don't 
need to update the API when more rule information is added in the future. 

I also think the interface should be pure virtual, and all end rules should 
implement this interface since they should have names or metadata of some sort. 


Repository:
  rL LLVM

https://reviews.llvm.org/D38985



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


[PATCH] D39220: [Analyzer] Store BodyFarm in std::unique_ptr

2017-10-25 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: include/clang/Analysis/AnalysisDeclContext.h:424
   /// methods during the analysis.
-  BodyFarm *BdyFrm = nullptr;
+  std::unique_ptr BdyFrm;
 

george.karpenkov wrote:
> alexfh wrote:
> > BdyFrm is somewhat cryptic. Maybe Farm, Bodies or something else that  is 
> > not so weirdly abbreviated?
> But that's just forced on us by the naming convention, isn't it? I think 
> other names are worse though: they don't tell us which class we can look at 
> to figure out what is it doing.
LLVM Coding Standards doesn't endorse this kind of an abbreviation, on the 
opposite:
"We cannot stress enough how important it is to use descriptive names. ... 
Avoid abbreviations unless they are well known." 
(http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly).
 Neither "Bdy" nor "Frm" are well known or otherwise clear to the reader. "Frm" 
could also stand for "Form" or "Frame", but in these cases it would also be 
confusing.

If you consider shorter names ("Bodies" or "Farm") non-informative, we can go 
the other direction, e.g. "FunctionBodyFarm".


Repository:
  rL LLVM

https://reviews.llvm.org/D39220



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


r316584 - [OPENMP] Constify function parameters, NFC.

2017-10-25 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Oct 25 08:44:52 2017
New Revision: 316584

URL: http://llvm.org/viewvc/llvm-project?rev=316584&view=rev
Log:
[OPENMP] Constify function parameters, NFC.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=316584&r1=316583&r2=316584&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Wed Oct 25 08:44:52 2017
@@ -4322,7 +4322,7 @@ static bool FitsInto(unsigned Bits, bool
 
 /// Build preinits statement for the given declarations.
 static Stmt *buildPreInits(ASTContext &Context,
-   SmallVectorImpl &PreInits) {
+   MutableArrayRef PreInits) {
   if (!PreInits.empty()) {
 return new (Context) DeclStmt(
 DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()),
@@ -4332,8 +4332,9 @@ static Stmt *buildPreInits(ASTContext &C
 }
 
 /// Build preinits statement for the given declarations.
-static Stmt *buildPreInits(ASTContext &Context,
-   llvm::MapVector &Captures) {
+static Stmt *
+buildPreInits(ASTContext &Context,
+  const llvm::MapVector &Captures) {
   if (!Captures.empty()) {
 SmallVector PreInits;
 for (auto &Pair : Captures)


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


[PATCH] D37187: [Analyzer] Fix Bug 25609 - Assertion UNREACHABLE: 'Unexpected ProgramPoint' with widen-loops=true

2017-10-25 Thread Henry Wong via Phabricator via cfe-commits
MTC updated this revision to Diff 120265.
MTC marked 3 inline comments as done.
MTC added a comment.

The message about invalidate variable values is temporarily not printed. This 
work can be done with separate patch.


https://reviews.llvm.org/D37187

Files:
  lib/StaticAnalyzer/Core/PathDiagnostic.cpp
  test/Analysis/loop-widening-notes.c


Index: test/Analysis/loop-widening-notes.c
===
--- /dev/null
+++ test/Analysis/loop-widening-notes.c
@@ -0,0 +1,55 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha -analyzer-max-loop 2 
-analyzer-config widen-loops=true -analyzer-output=text -verify %s
+
+int *p_a;
+int bar();
+int flag_a;
+int test_for_bug_25609() {
+  if (p_a == 0) // expected-note {{Assuming 'p_a' is equal to null}} 
expected-note {{Taking true branch}}
+bar();
+  for (int i = 0; i < flag_a; ++i) {} // expected-note {{Loop condition is 
true.  Entering loop body}} expected-note {{Value assigned to 'p_a'}} 
expected-note {{Loop condition is false. Execution continues on line 10}}
+  *p_a = 25609; // no-crash expected-note {{Dereference of null pointer 
(loaded from variable 'p_a')}} expected-warning {{Dereference of null pointer 
(loaded from variable 'p_a')}}
+  return *p_a;
+}
+
+int flag_b;
+int while_analyzer_output() {
+  flag_b = 100;
+  int num = 10;
+  while (flag_b-- > 0) { // expected-note {{Loop condition is true.  Entering 
loop body}} expected-note {{Value assigned to 'num'}} expected-note {{Loop 
condition is false. Execution continues on line 21}}
+num = flag_b;
+  }
+  if (num < 0) // expected-note {{Assuming 'num' is >= 0}} expected-note 
{{Taking false branch}}
+flag_b = 0;
+  else if (num >= 1) // expected-note {{Assuming 'num' is < 1}} expected-note 
{{Taking false branch}}
+flag_b = 50;
+  else
+flag_b = 100;
+  return flag_b / num; // no-crash expected-warning {{Division by zero}} 
expected-note {{Division by zero}}
+}
+
+int flag_c;
+int do_while_analyzer_output() {
+  int num = 10;
+  do { // expected-note {{Loop condition is true. Execution continues on line 
34}} expected-note {{Loop condition is false.  Exiting loop}}
+num--;
+  } while (flag_c-- > 0); //expected-note {{Value assigned to 'num'}}
+  int local = 0;
+  if (num == 0)   // expected-note{{Assuming 'num' is equal to 0}} 
expected-note{{Taking true branch}}
+local = 10 / num; // no-crash expected-note {{Division by zero}} 
expected-warning {{Division by zero}}
+  return local;
+}
+
+int flag_d;
+int test_for_loop() {
+  int num = 10;
+  int tmp = 0;
+  for (int i = 0; // expected-note {{Loop condition is true.  Entering loop 
body}} expected-note {{Loop condition is false. Execution continues on line 52}}
+   ++tmp,  // expected-note {{Value assigned to 'num'}}
+   i < flag_d;
+   ++i) {
+++num;
+  }
+  if (num == 0) // expected-note {{Assuming 'num' is equal to 0}} 
expected-note {{Taking true branch}}
+flag_d += tmp;
+  return flag_d / num; // no-crash expected-warning {{Division by zero}} 
expected-note {{Division by zero}}
+}
Index: lib/StaticAnalyzer/Core/PathDiagnostic.cpp
===
--- lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -690,6 +690,8 @@
 return getLocationForCaller(CEE->getCalleeContext(),
 CEE->getLocationContext(),
 SMng);
+  } else if (Optional BE = P.getAs()) {
+S = BE->getBlock()->getTerminatorCondition();
   } else {
 llvm_unreachable("Unexpected ProgramPoint");
   }


Index: test/Analysis/loop-widening-notes.c
===
--- /dev/null
+++ test/Analysis/loop-widening-notes.c
@@ -0,0 +1,55 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha -analyzer-max-loop 2 -analyzer-config widen-loops=true -analyzer-output=text -verify %s
+
+int *p_a;
+int bar();
+int flag_a;
+int test_for_bug_25609() {
+  if (p_a == 0) // expected-note {{Assuming 'p_a' is equal to null}} expected-note {{Taking true branch}}
+bar();
+  for (int i = 0; i < flag_a; ++i) {} // expected-note {{Loop condition is true.  Entering loop body}} expected-note {{Value assigned to 'p_a'}} expected-note {{Loop condition is false. Execution continues on line 10}}
+  *p_a = 25609; // no-crash expected-note {{Dereference of null pointer (loaded from variable 'p_a')}} expected-warning {{Dereference of null pointer (loaded from variable 'p_a')}}
+  return *p_a;
+}
+
+int flag_b;
+int while_analyzer_output() {
+  flag_b = 100;
+  int num = 10;
+  while (flag_b-- > 0) { // expected-note {{Loop condition is true.  Entering loop body}} expected-note {{Value assigned to 'num'}} expected-note {{Loop condition is false. Execution continues on line 21}}
+num = flag_b;
+  }
+  if (num < 0) // expected-note {{Assuming 'num' is >= 0}} expected-note {{Taking false branch}}
+ 

r316585 - [OPENMP] Improve debug info for taskgroup implicitly generated

2017-10-25 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Oct 25 08:54:04 2017
New Revision: 316585

URL: http://llvm.org/viewvc/llvm-project?rev=316585&view=rev
Log:
[OPENMP] Improve debug info for taskgroup implicitly generated
expressions.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/taskgroup_task_reduction_codegen.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=316585&r1=316584&r2=316585&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Wed Oct 25 08:54:04 2017
@@ -835,10 +835,10 @@ void DSAStackTy::addTaskgroupReductionDa
   Expr *&TaskgroupReductionRef =
   Stack.back().first.back().TaskgroupReductionRef;
   if (!TaskgroupReductionRef) {
-auto *VD = buildVarDecl(SemaRef, SourceLocation(),
+auto *VD = buildVarDecl(SemaRef, SR.getBegin(),
 SemaRef.Context.VoidPtrTy, ".task_red.");
-TaskgroupReductionRef = buildDeclRefExpr(
-SemaRef, VD, SemaRef.Context.VoidPtrTy, SourceLocation());
+TaskgroupReductionRef =
+buildDeclRefExpr(SemaRef, VD, SemaRef.Context.VoidPtrTy, 
SR.getBegin());
   }
 }
 
@@ -858,10 +858,10 @@ void DSAStackTy::addTaskgroupReductionDa
   Expr *&TaskgroupReductionRef =
   Stack.back().first.back().TaskgroupReductionRef;
   if (!TaskgroupReductionRef) {
-auto *VD = buildVarDecl(SemaRef, SourceLocation(),
-SemaRef.Context.VoidPtrTy, ".task_red.");
-TaskgroupReductionRef = buildDeclRefExpr(
-SemaRef, VD, SemaRef.Context.VoidPtrTy, SourceLocation());
+auto *VD = buildVarDecl(SemaRef, SR.getBegin(), SemaRef.Context.VoidPtrTy,
+".task_red.");
+TaskgroupReductionRef =
+buildDeclRefExpr(SemaRef, VD, SemaRef.Context.VoidPtrTy, 
SR.getBegin());
   }
 }
 
@@ -9720,8 +9720,7 @@ static bool ActOnOMPReductionKindClause(
   // (type of the variable or single array element).
   PrivateTy = Context.getVariableArrayType(
   Type,
-  new (Context) OpaqueValueExpr(SourceLocation(), 
Context.getSizeType(),
-VK_RValue),
+  new (Context) OpaqueValueExpr(ELoc, Context.getSizeType(), 
VK_RValue),
   ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange());
 } else if (!ASE && !OASE &&
Context.getAsArrayType(D->getType().getNonReferenceType()))
@@ -9803,8 +9802,7 @@ static bool ActOnOMPReductionKindClause(
   if (Type->isPointerType()) {
 // Cast to pointer type.
 auto CastExpr = S.BuildCStyleCastExpr(
-SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc),
-SourceLocation(), Init);
+ELoc, Context.getTrivialTypeSourceInfo(Type, ELoc), ELoc, 
Init);
 if (CastExpr.isInvalid())
   continue;
 Init = CastExpr.get();
@@ -9898,9 +9896,9 @@ static bool ActOnOMPReductionKindClause(
   S.BuildBinOp(Stack->getCurScope(), ReductionId.getLocStart(),
BO_Assign, LHSDRE, ReductionOp.get());
 } else {
-  auto *ConditionalOp = new (Context) ConditionalOperator(
-  ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(),
-  RHSDRE, Type, VK_LValue, OK_Ordinary);
+  auto *ConditionalOp = new (Context)
+  ConditionalOperator(ReductionOp.get(), ELoc, LHSDRE, ELoc, 
RHSDRE,
+  Type, VK_LValue, OK_Ordinary);
   ReductionOp =
   S.BuildBinOp(Stack->getCurScope(), ReductionId.getLocStart(),
BO_Assign, LHSDRE, ConditionalOp);
@@ -10782,7 +10780,7 @@ Sema::ActOnOpenMPDependClause(OpenMPDepe
 }
 bool Suppress = getDiagnostics().getSuppressAllDiagnostics();
 getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true);
-ExprResult Res = CreateBuiltinUnaryOp(SourceLocation(), UO_AddrOf,
+ExprResult Res = CreateBuiltinUnaryOp(ELoc, UO_AddrOf,
   RefExpr->IgnoreParenImpCasts());
 getDiagnostics().setSuppressAllDiagnostics(Suppress);
 if (!Res.isUsable() && !isa(SimpleExpr)) {

Modified: cfe/trunk/test/OpenMP/taskgroup_task_reduction_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/taskgroup_task_reduction_codegen.cpp?rev=316585&r1=316584&r2=316585&view=diff
==
--- cfe/trunk/test/OpenMP/taskgroup_task_reduction_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/taskgroup_task_reduction_codegen.cpp Wed Oct 25 
08:54:04 2017
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -x c++ 
-emit-llvm %s -o - | FileCheck %s
 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64

[PATCH] D37470: [analyzer] Handle ObjC messages conservatively in CallDescription

2017-10-25 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin added a comment.

I think it would be better to add a new 
"test/Analysis/block-in-critical-section.m" file rather than enabling a random 
alpha checker in a file that tests the analyzer core.


https://reviews.llvm.org/D37470



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


[PATCH] D39008: [CodeGen] Propagate may-alias'ness of lvalues with TBAA info

2017-10-25 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev added a comment.

Now that https://reviews.llvm.org/D38796 is comitted and added the 
tbaa-cast.cpp test case to the mainline, we fail on it with this patch applied. 
The reason is that we have no special TBAA type node for may-alias accesses, so 
everything that ever been a potential access to a character type turns into a 
may-alias access and propagates as such.

The test case reads:

  struct V {
unsigned n;
  };
  
  struct S {
char bytes[4];
  };
  
  void foo(S *p) {
((V*)p->bytes)->n = 5;
  }

Here, p->bytes decays to a pointer to char, meaning the pointee object is 
considered may-alias and so it is after the explicit cast.

This arises an interesting question: should we introduce a special 
representation for may-alias accesses to distinct them from character-typed 
accesses? Or, maybe explicit casts should not derive their may-alias'ness from 
their source operands? Or, maybe we want to consider all explicit casts of the 
form ##(T*)E## where ##T*## and ##typeof(E)## point to different types as 
pointers to may-alias objects?


Repository:
  rL LLVM

https://reviews.llvm.org/D39008



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


[PATCH] D39293: Add objcCategoryImplDecl matcher

2017-10-25 Thread Dave Lee via Phabricator via cfe-commits
kastiglione created this revision.
Herald added a subscriber: klimek.

Add `objcCategoryImplDecl` which matches ObjC category definitions
(`@implementation`). This matcher complements `objcCategoryDecl` (`@interface`)
which was added in https://reviews.llvm.org/D30854.


https://reviews.llvm.org/D39293

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1590,7 +1590,7 @@
 )));
 }
 
-TEST(ObjCDeclMacher, CoreDecls) {
+TEST(ObjCDeclMatcher, CoreDecls) {
   std::string ObjCString =
 "@protocol Proto "
 "- (void)protoDidThing; "
@@ -1605,6 +1605,9 @@
 "{ id _ivar; } "
 "- (void)anything {} "
 "@end "
+"@implementation Thing (ABC) "
+"- (void)abc_doThing {} "
+"@end "
 ;
 
   EXPECT_TRUE(matchesObjC(
@@ -1616,6 +1619,9 @@
   EXPECT_TRUE(matchesObjC(
 ObjCString,
 objcCategoryDecl(hasName("ABC";
+  EXPECT_TRUE(matchesObjC(
+ObjCString,
+objcCategoryImplDecl(hasName("ABC";
   EXPECT_TRUE(matchesObjC(
 ObjCString,
 objcMethodDecl(hasName("protoDidThing";
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -374,6 +374,7 @@
   REGISTER_MATCHER(numSelectorArgs);
   REGISTER_MATCHER(ofClass);
   REGISTER_MATCHER(objcCategoryDecl);
+  REGISTER_MATCHER(objcCategoryImplDecl);
   REGISTER_MATCHER(objcImplementationDecl);
   REGISTER_MATCHER(objcInterfaceDecl);
   REGISTER_MATCHER(objcIvarDecl);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -1178,6 +1178,17 @@
   Decl,
   ObjCCategoryDecl> objcCategoryDecl;
 
+/// \brief Matches Objective-C category definitions.
+///
+/// Example matches Foo (Additions)
+/// \code
+///   @implementation Foo (Additions)
+///   @end
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<
+  Decl,
+  ObjCCategoryImplDecl> objcCategoryImplDecl;
+
 /// \brief Matches Objective-C method declarations.
 ///
 /// Example matches both declaration and definition of -[Foo method]
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -346,6 +346,15 @@
 
 
 
+MatcherDecl>objcCategoryImplDeclMatcherObjCCategoryImplDecl>...
+Matches 
Objective-C category definitions.
+
+Example matches Foo (Additions)
+  @implementation Foo (Additions)
+  @end
+
+
+
 MatcherDecl>objcImplementationDeclMatcherObjCImplementationDecl>...
 Matches 
Objective-C implementation declarations.
 


Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1590,7 +1590,7 @@
 )));
 }
 
-TEST(ObjCDeclMacher, CoreDecls) {
+TEST(ObjCDeclMatcher, CoreDecls) {
   std::string ObjCString =
 "@protocol Proto "
 "- (void)protoDidThing; "
@@ -1605,6 +1605,9 @@
 "{ id _ivar; } "
 "- (void)anything {} "
 "@end "
+"@implementation Thing (ABC) "
+"- (void)abc_doThing {} "
+"@end "
 ;
 
   EXPECT_TRUE(matchesObjC(
@@ -1616,6 +1619,9 @@
   EXPECT_TRUE(matchesObjC(
 ObjCString,
 objcCategoryDecl(hasName("ABC";
+  EXPECT_TRUE(matchesObjC(
+ObjCString,
+objcCategoryImplDecl(hasName("ABC";
   EXPECT_TRUE(matchesObjC(
 ObjCString,
 objcMethodDecl(hasName("protoDidThing";
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -374,6 +374,7 @@
   REGISTER_MATCHER(numSelectorArgs);
   REGISTER_MATCHER(ofClass);
   REGISTER_MATCHER(objcCategoryDecl);
+  REGISTER_MATCHER(objcCategoryImplDecl);
   REGISTER_MATCHER(objcImplementationDecl);
   REGISTER_MATCHER(objcInterfaceDecl);
   REGISTER_MATCHER(objcIvarDecl);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -1178,6 +1178,17 @@
   Decl,
   ObjCCategoryDecl> objcCategoryD

[PATCH] D39293: Add objcCategoryImplDecl matcher

2017-10-25 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!


https://reviews.llvm.org/D39293



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


[PATCH] D39290: [rename] Use SymbolOccurrence in RenameLocFinder.

2017-10-25 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Could you elaborate on the intention of this change? Is the intention of having 
more information in `SymbolOccurrence` to benefit users of the rename library 
or to simplify the internal implementation?




Comment at: include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h:74
+// The declaration in which the nested name is contained (can be nullptr).
+const Decl *Context;
+// The nested name being replaced (can be nullptr).

A `SymbolOccurrence` is likely to out-live an AST (e.g. when used in 
clang-refactor or serialized to files), so it might not be safe to store 
references to ASTs here. If we really want AST information in the 
`SymbolOccurrence`, we could probably derive from it and use only internally. 
But it doesn't make sense to pass AST references out to users.


https://reviews.llvm.org/D39290



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


[libclc] r316588 - math: Implement native_log10

2017-10-25 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Wed Oct 25 09:49:22 2017
New Revision: 316588

URL: http://llvm.org/viewvc/llvm-project?rev=316588&view=rev
Log:
math: Implement native_log10

Use llvm instrinsic by default
Provide amdgpu workaround

v2: drop old amd copyrights

Reviewer: Aaron Watry
Reviewed-by: Vedran Miletić 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/amdgpu/lib/math/native_log10.cl
libclc/trunk/amdgpu/lib/math/native_log10.inc
libclc/trunk/generic/include/clc/math/native_log10.h
libclc/trunk/generic/include/clc/math/native_log10.inc
libclc/trunk/generic/lib/math/native_log10.cl
libclc/trunk/generic/lib/math/native_log10.inc
Modified:
libclc/trunk/amdgpu/lib/SOURCES
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/amdgpu/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgpu/lib/SOURCES?rev=316588&r1=316587&r2=316588&view=diff
==
--- libclc/trunk/amdgpu/lib/SOURCES (original)
+++ libclc/trunk/amdgpu/lib/SOURCES Wed Oct 25 09:49:22 2017
@@ -1,3 +1,4 @@
 math/native_log.cl
+math/native_log10.cl
 math/nextafter.cl
 math/sqrt.cl

Added: libclc/trunk/amdgpu/lib/math/native_log10.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgpu/lib/math/native_log10.cl?rev=316588&view=auto
==
--- libclc/trunk/amdgpu/lib/math/native_log10.cl (added)
+++ libclc/trunk/amdgpu/lib/math/native_log10.cl Wed Oct 25 09:49:22 2017
@@ -0,0 +1,5 @@
+#include 
+
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 

Added: libclc/trunk/amdgpu/lib/math/native_log10.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgpu/lib/math/native_log10.inc?rev=316588&view=auto
==
--- libclc/trunk/amdgpu/lib/math/native_log10.inc (added)
+++ libclc/trunk/amdgpu/lib/math/native_log10.inc Wed Oct 25 09:49:22 2017
@@ -0,0 +1,3 @@
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_log10(__CLC_GENTYPE val) {
+  return native_log2(val) * (M_LN2_F / M_LN10_F);
+}

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=316588&r1=316587&r2=316588&view=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Wed Oct 25 09:49:22 2017
@@ -104,6 +104,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/native_log10.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/native_log10.h?rev=316588&view=auto
==
--- libclc/trunk/generic/include/clc/math/native_log10.h (added)
+++ libclc/trunk/generic/include/clc/math/native_log10.h Wed Oct 25 09:49:22 
2017
@@ -0,0 +1,5 @@
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 
+#undef __CLC_BODY
+#undef __FLOAT_ONLY

Added: libclc/trunk/generic/include/clc/math/native_log10.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/native_log10.inc?rev=316588&view=auto
==
--- libclc/trunk/generic/include/clc/math/native_log10.inc (added)
+++ libclc/trunk/generic/include/clc/math/native_log10.inc Wed Oct 25 09:49:22 
2017
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE native_log10(__CLC_GENTYPE a);

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=316588&r1=316587&r2=316588&view=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Wed Oct 25 09:49:22 2017
@@ -120,6 +120,7 @@ math/logb.cl
 math/mad.cl
 math/modf.cl
 math/native_log.cl
+math/native_log10.cl
 math/native_log2.cl
 math/tables.cl
 math/clc_nextafter.cl

Added: libclc/trunk/generic/lib/math/native_log10.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/native_log10.cl?rev=316588&view=auto
==
--- libclc/trunk/generic/lib/math/native_log10.cl (added)
+++ libclc/trunk/generic/lib/math/native_log10.cl Wed Oct 25 09:49:22 2017
@@ -0,0 +1,10 @@
+#include 
+
+#define __CLC_FUNCTION __clc_native_log10
+#define __CLC_INTRINSIC "llvm.log10"
+#undef cl_khr_fp64
+#include 
+
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 

Added: libclc/trunk/generic/lib/math/native_log10.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/native_log10.inc?rev=316588&view=auto
==
--- 

[libclc] r316587 - amdgpu/math: Don't use llvm instrinsic for native_log

2017-10-25 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Wed Oct 25 09:49:17 2017
New Revision: 316587

URL: http://llvm.org/viewvc/llvm-project?rev=316587&view=rev
Log:
amdgpu/math: Don't use llvm instrinsic for native_log

AMDGPU targets don't have insturction for it,
so it'll be expanded to C * log2 anyway.

v2: use native_log2 instead of the more precise sw implementation
v3: move to amdgpu
v4: drop old AMD copyright

Reviewer: Aaron Watry
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/amdgpu/lib/math/native_log.cl
libclc/trunk/amdgpu/lib/math/native_log.inc
Modified:
libclc/trunk/amdgpu/lib/SOURCES

Modified: libclc/trunk/amdgpu/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgpu/lib/SOURCES?rev=316587&r1=316586&r2=316587&view=diff
==
--- libclc/trunk/amdgpu/lib/SOURCES (original)
+++ libclc/trunk/amdgpu/lib/SOURCES Wed Oct 25 09:49:17 2017
@@ -1,2 +1,3 @@
+math/native_log.cl
 math/nextafter.cl
 math/sqrt.cl

Added: libclc/trunk/amdgpu/lib/math/native_log.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgpu/lib/math/native_log.cl?rev=316587&view=auto
==
--- libclc/trunk/amdgpu/lib/math/native_log.cl (added)
+++ libclc/trunk/amdgpu/lib/math/native_log.cl Wed Oct 25 09:49:17 2017
@@ -0,0 +1,5 @@
+#include 
+
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 

Added: libclc/trunk/amdgpu/lib/math/native_log.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgpu/lib/math/native_log.inc?rev=316587&view=auto
==
--- libclc/trunk/amdgpu/lib/math/native_log.inc (added)
+++ libclc/trunk/amdgpu/lib/math/native_log.inc Wed Oct 25 09:49:17 2017
@@ -0,0 +1,3 @@
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_log(__CLC_GENTYPE val) {
+  return native_log2(val) * (1.0f / M_LOG2E_F);
+}


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


[PATCH] D38596: Implement attribute target multiversioning

2017-10-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 120278.
erichkeane added a comment.

Just a quick rebase, there were a few changes in the area.


https://reviews.llvm.org/D38596

Files:
  include/clang/AST/Decl.h
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Sema/Sema.h
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Sema/SemaDecl.cpp

Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -285,6 +285,49 @@
   }
 }
 
+void CodeGenModule::EmitMultiVersionResolver(StringRef MangledName,
+ const FunctionDecl *FD) {
+  llvm::Function *ResolverFunc =
+  cast(GetGlobalValue((MangledName + ".resolver").str()));
+  SmallVector ResolverOptions;
+  for (FunctionDecl *CurFD : FD->redecls()) {
+std::string FuncName = MakeMultiVersionName(MangledName, CurFD);
+llvm::Constant *Func = GetGlobalValue(FuncName);
+if (!Func) {
+  GlobalDecl GD{CurFD};
+  if (CurFD->isThisDeclarationADefinition()) {
+// If the function is defined, make sure we emit it.
+EmitGlobalDefinition(GD);
+Func = GetGlobalValue(FuncName);
+  } else {
+// We still need to create declarations, since the resolver needs them.
+const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
+llvm::FunctionType *Ty = getTypes().GetFunctionType(FI);
+Func = GetAddrOfFunction(GD, Ty, /*ForVTable=*/false,
+ /*DontDefer=*/false, ForDefinition);
+  }
+  assert(Func && "This should have just been created");
+}
+
+ResolverOptions.emplace_back(CurFD->getAttr()->parse(),
+ cast(Func));
+  }
+
+  // Sort resolver options.
+  auto *TargetInfo = &Context.getTargetInfo();
+  auto CmpFunc = [TargetInfo](StringRef LHS, StringRef RHS) {
+return TargetInfo->compareCpusAndFeatures(LHS, RHS);
+  };
+  std::sort(std::begin(ResolverOptions), std::end(ResolverOptions),
+[CmpFunc](const CodeGenFunction::ResolverOption &LHS,
+  const CodeGenFunction::ResolverOption &RHS) {
+  return CmpFunc(LHS.AttrInfo.getHighestPriority(CmpFunc),
+ RHS.AttrInfo.getHighestPriority(CmpFunc));
+});
+  CodeGenFunction CGF(*this);
+  CGF.EmitMultiVersionResolver(ResolverFunc, ResolverOptions);
+}
+
 void CodeGenModule::checkAliases() {
   // Check if the constructed aliases are well formed. It is really unfortunate
   // that we have to do this in CodeGen, but we only construct mangled names
@@ -362,6 +405,40 @@
   }
 }
 
+void CodeGenModule::checkMultiversions() {
+  // Cleanup the IFuncs calls for multiversioning.
+  for (const GlobalDecl &GD : MultiVersionFuncs) {
+bool DefaultFound = false;
+for (auto *Decl : GD.getDecl()->getMostRecentDecl()->redecls())
+  if (Decl->getAttr()->getFeaturesStr() == "default")
+DefaultFound = true;
+
+StringRef MangledName = getMangledName(GD);
+llvm::GlobalValue *BaseFunc = GetGlobalValue(MangledName);
+llvm::GlobalValue *IFunc = GetGlobalValue((MangledName + ".ifunc").str());
+assert(IFunc && "Multiversioning not legal without an IFunc");
+if (!DefaultFound && cast(GD.getDecl())->isDefined()) {
+  Diags.Report(
+  cast(GD.getDecl())->getFirstDecl()->getLocation(),
+  diag::err_target_without_default);
+  // In the error case, replace all uses with an undef.
+  if (BaseFunc) {
+BaseFunc->replaceAllUsesWith(
+llvm::UndefValue::get(BaseFunc->getType()));
+BaseFunc->eraseFromParent();
+  }
+  continue;
+}
+
+if (cast(GD.getDecl())->isDefined())
+  EmitMultiVersionResolver(
+  MangledName, cast(GD.getDecl()->getMostRecentDecl()));
+if (BaseFunc)
+  BaseFunc->replaceAllUsesWith(
+  llvm::ConstantExpr::getBitCast(IFunc, BaseFunc->getType()));
+  }
+}
+
 void CodeGenModule::clear() {
   DeferredDeclsToEmit.clear();
   if (OpenMPRuntime)
@@ -391,6 +468,7 @@
   applyGlobalValReplacements();
   applyReplacements();
   checkAliases();
+  checkMultiversions();
   EmitCXXGlobalInitFunc();
   EmitCXXGlobalDtorFunc();
   EmitCXXThreadLocalInitFunc();
@@ -2045,6 +2123,73 @@
 static void ReplaceUsesOfNonProtoTypeWithRealFunction(llvm::GlobalValue *Old,
   llvm::Function *NewFn);
 
+std::string CodeGenModule::MakeMultiVersionName(StringRef MangledName,
+const Decl *D) {
+  assert(D && "Decl cannot be null");
+  const auto *TA = D->getAttr();
+  assert(TA && "Decl must have a Target Attribute");
+ 

[PATCH] D39224: Moved QualTypeNames.h from Tooling to AST.

2017-10-25 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In https://reviews.llvm.org/D39224#906225, @ilya-biryukov wrote:

> In https://reviews.llvm.org/D39224#905431, @rnk wrote:
>
> > Can you remind me why `NamedDecl::printQualifiedName` is not appropriate 
> > for your needs?
>
>
> The use-case in code completion (see https://reviews.llvm.org/D38538,  the 
> interesting bit is in `SemaCodeComplete.cpp`) creates a `QualType` that is 
> being pretty-printed later on.
>  There does not seem to be a way to rewrite it to use `printQualifiedName`for 
> that particular case without messing up the code. I was initially planning to 
> simply create `ElaborateType` with proper `NestedNameSpecifier`, but that's 
> essentially what the code in `QualTypeNames`  does already (it has logic to 
> create both the `NestedNameSpecifier` and `ElaboratedType` out of it), so we 
> should definitely reuse it.


Got it, thanks. If we're moving this into AST, I suspect ASTContext would be a 
better home for it. That's where the rest of our random type manipulation code 
lives, anyway. :)


https://reviews.llvm.org/D39224



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


r316593 - [X86] Add avx512vpopcntdq to Knights Mill

2017-10-25 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Wed Oct 25 10:10:58 2017
New Revision: 316593

URL: http://llvm.org/viewvc/llvm-project?rev=316593&view=rev
Log:
[X86] Add avx512vpopcntdq to Knights Mill

As indicated by Table 1-1 in Intel Architecture Instruction Set Extensions and 
Future Features Programming Reference from October 2017.

Modified:
cfe/trunk/lib/Basic/Targets/X86.cpp
cfe/trunk/test/Preprocessor/predefined-arch-macros.c

Modified: cfe/trunk/lib/Basic/Targets/X86.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.cpp?rev=316593&r1=316592&r2=316593&view=diff
==
--- cfe/trunk/lib/Basic/Targets/X86.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/X86.cpp Wed Oct 25 10:10:58 2017
@@ -231,6 +231,8 @@ bool X86TargetInfo::initFeatureMap(
 
   case CK_KNM:
 // TODO: Add avx5124fmaps/avx5124vnniw.
+setFeatureEnabledImpl(Features, "avx512vpopcntdq", true);
+LLVM_FALLTHROUGH;
   case CK_KNL:
 setFeatureEnabledImpl(Features, "avx512f", true);
 setFeatureEnabledImpl(Features, "avx512cd", true);

Modified: cfe/trunk/test/Preprocessor/predefined-arch-macros.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/predefined-arch-macros.c?rev=316593&r1=316592&r2=316593&view=diff
==
--- cfe/trunk/test/Preprocessor/predefined-arch-macros.c (original)
+++ cfe/trunk/test/Preprocessor/predefined-arch-macros.c Wed Oct 25 10:10:58 
2017
@@ -793,6 +793,7 @@
 // CHECK_KNM_M32: #define __AVX512ER__ 1
 // CHECK_KNM_M32: #define __AVX512F__ 1
 // CHECK_KNM_M32: #define __AVX512PF__ 1
+// CHECK_KNM_M32: #define __AVX512VPOPCNTDQ__ 1
 // CHECK_KNM_M32: #define __AVX__ 1
 // CHECK_KNM_M32: #define __BMI2__ 1
 // CHECK_KNM_M32: #define __BMI__ 1
@@ -826,6 +827,7 @@
 // CHECK_KNM_M64: #define __AVX512ER__ 1
 // CHECK_KNM_M64: #define __AVX512F__ 1
 // CHECK_KNM_M64: #define __AVX512PF__ 1
+// CHECK_KNM_M64: #define __AVX512VPOPCNTDQ__ 1
 // CHECK_KNM_M64: #define __AVX__ 1
 // CHECK_KNM_M64: #define __BMI2__ 1
 // CHECK_KNM_M64: #define __BMI__ 1


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


[PATCH] D39224: Moved QualTypeNames.h from Tooling to AST.

2017-10-25 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

Looks good


https://reviews.llvm.org/D39224



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


[PATCH] D39284: [c++2a] Decomposed _condition_

2017-10-25 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray added a comment.

In https://reviews.llvm.org/D39284#906450, @aaron.ballman wrote:

> I'm not opposed to the functionality, but this isn't a part of C++2a either; 
> I think we should be diagnosing this code with a warning so users don't 
> expect it to work on every compiler.


C++2a the standard itself is under development, so the users can't expect any 
feature to work on every compiler already.


https://reviews.llvm.org/D39284



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


Re: r315126 - Driver: hoist the `wchar_t` handling to the driver

2017-10-25 Thread Friedman, Eli via cfe-commits

On 10/6/2017 4:09 PM, Saleem Abdulrasool via cfe-commits wrote:

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=315126&r1=315125&r2=315126&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Oct  6 16:09:55 2017
@@ -2601,6 +2601,33 @@ static void RenderModulesOptions(Compila
Args.AddLastArg(CmdArgs, 
options::OPT_fmodules_disable_diagnostic_validation);
  }
  
+static void RenderCharacterOptions(const ArgList &Args, const llvm::Triple &T,

+   ArgStringList &CmdArgs) {
+  // -fsigned-char is default.
+  if (const Arg *A = Args.getLastArg(options::OPT_fsigned_char,
+ options::OPT_fno_signed_char,
+ options::OPT_funsigned_char,
+ options::OPT_fno_unsigned_char)) {
+if (A->getOption().matches(options::OPT_funsigned_char) ||
+A->getOption().matches(options::OPT_fno_signed_char)) {
+  CmdArgs.push_back("-fno-signed-char");
+}
+  } else if (!isSignedCharDefault(T)) {
+CmdArgs.push_back("-fno-signed-char");
+  }
+
+  if (const Arg *A = Args.getLastArg(options::OPT_fshort_wchar,
+ options::OPT_fno_short_wchar)) {
+if (A->getOption().matches(options::OPT_fshort_wchar)) {
+  CmdArgs.push_back("-fwchar-type=short");
+  CmdArgs.push_back("-fno-signed-wchar");
+} else {
+  CmdArgs.push_back("-fwchar-type=int");
+  CmdArgs.push_back("-fsigned-wchar");
+}
+  }
+}


It looks like this changes the behavior of "-fno-short-wchar". 
Specifically, on targets where the default wchar_t type is "unsigned 
int" (like ARM AAPCS), "-fno-short-wchar" used to be a no-op, but now it 
changes the sign of wchar_t.  Why are we overriding the default here?


-Eli

--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux 
Foundation Collaborative Project

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


r316599 - CodeGen: fix PPC Darwin variadics

2017-10-25 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Wed Oct 25 10:56:50 2017
New Revision: 316599

URL: http://llvm.org/viewvc/llvm-project?rev=316599&view=rev
Log:
CodeGen: fix PPC Darwin variadics

Darwin uses char * for the variadic list type (va_list).  We use the PPC
SVR4 ABI for PPC, which uses a structure type for the va_list.  When
constructing the GEP, we would fail due to the incorrect handling for
the va_list.  Correct this to use the right type.

Added:
cfe/trunk/test/CodeGen/darwin-ppc-varargs.c
Modified:
cfe/trunk/lib/CodeGen/TargetInfo.cpp

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=316599&r1=316598&r2=316599&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Wed Oct 25 10:56:50 2017
@@ -4036,7 +4036,10 @@ Address WinX86_64ABIInfo::EmitVAArg(Code
 namespace {
 /// PPC32_SVR4_ABIInfo - The 32-bit PowerPC ELF (SVR4) ABI information.
 class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
-bool IsSoftFloatABI;
+  bool IsSoftFloatABI;
+
+  CharUnits getParamTypeAlignment(QualType Ty) const;
+
 public:
   PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, bool SoftFloatABI)
   : DefaultABIInfo(CGT), IsSoftFloatABI(SoftFloatABI) {}
@@ -4058,13 +4061,46 @@ public:
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
llvm::Value *Address) const override;
 };
+}
 
+CharUnits PPC32_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
+  // Complex types are passed just like their elements
+  if (const ComplexType *CTy = Ty->getAs())
+Ty = CTy->getElementType();
+
+  if (Ty->isVectorType())
+return CharUnits::fromQuantity(getContext().getTypeSize(Ty) == 128 ? 16
+   : 4);
+
+  // For single-element float/vector structs, we consider the whole type
+  // to have the same alignment requirements as its single element.
+  const Type *AlignTy = nullptr;
+  if (const Type *EltType = isSingleElementStruct(Ty, getContext())) {
+const BuiltinType *BT = EltType->getAs();
+if ((EltType->isVectorType() && getContext().getTypeSize(EltType) == 128) 
||
+(BT && BT->isFloatingPoint()))
+  AlignTy = EltType;
+  }
+
+  if (AlignTy)
+return CharUnits::fromQuantity(AlignTy->isVectorType() ? 16 : 4);
+  return CharUnits::fromQuantity(4);
 }
 
 // TODO: this implementation is now likely redundant with
 // DefaultABIInfo::EmitVAArg.
 Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAList,
   QualType Ty) const {
+  if (getTarget().getTriple().isOSDarwin()) {
+auto TI = getContext().getTypeInfoInChars(Ty);
+TI.second = getParamTypeAlignment(Ty);
+
+CharUnits SlotSize = CharUnits::fromQuantity(4);
+return emitVoidPtrVAArg(CGF, VAList, Ty,
+classifyArgumentType(Ty).isIndirect(), TI, 
SlotSize,
+/*AllowHigherAlign=*/true);
+  }
+
   const unsigned OverflowLimit = 8;
   if (const ComplexType *CTy = Ty->getAs()) {
 // TODO: Implement this. For now ignore.

Added: cfe/trunk/test/CodeGen/darwin-ppc-varargs.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/darwin-ppc-varargs.c?rev=316599&view=auto
==
--- cfe/trunk/test/CodeGen/darwin-ppc-varargs.c (added)
+++ cfe/trunk/test/CodeGen/darwin-ppc-varargs.c Wed Oct 25 10:56:50 2017
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple powerpc-apple-macosx10.5.0 -target-feature +altivec 
-Os -emit-llvm -o - %s | FileCheck %s
+
+int f(__builtin_va_list args) { return __builtin_va_arg(args, int); }
+
+// CHECK: @f(i8* {{.*}}[[PARAM:%[a-zA-Z0-9]+]])
+// CHECK: [[BITCAST:%[0-9]+]] = bitcast i8* [[PARAM]] to i32*
+// CHECK: [[VALUE:%[0-9]+]] = load i32, i32* [[BITCAST]], align 4
+// CHECK: ret i32 [[VALUE]]
+
+void h(vector int);
+int g(__builtin_va_list args) {
+  int i = __builtin_va_arg(args, int);
+  h(__builtin_va_arg(args, vector int));
+  int j = __builtin_va_arg(args, int);
+  return i + j;
+}
+
+// CHECK: @g(i8* {{.*}}[[PARAM:%[a-zA-Z0-9]+]])
+// CHECK: [[NEXT:%[-_.a-zA-Z0-9]+]] = getelementptr inbounds i8, i8* 
[[PARAM]], i32 4
+// CHECK: [[BITCAST:%[0-9]+]] = bitcast i8* [[PARAM]] to i32*
+// CHECK: [[LOAD:%[0-9]+]] = load i32, i32* [[BITCAST]], align 4
+// CHECK: [[PTRTOINT:%[0-9]+]] = ptrtoint i8* [[NEXT]] to i32
+// CHECK: [[ADD:%[0-9]+]] = add i32 [[PTRTOINT]], 15
+// CHECK: [[AND:%[0-9]+]] = and i32 [[ADD]], -16
+// CHECK: [[INTTOPTR:%[0-9]+]] = inttoptr i32 [[AND]] to <4 x i32>*
+// CHECK: [[ARG:%[0-9]]] = load <4 x i32>, <4 x i32>* [[INTTOPTR]], align 16
+// CHECK: call void @h(<4 x i32> [[ARG]]
+


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

[PATCH] D39210: Add default calling convention support for regcall.

2017-10-25 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 120284.
eandrews added a comment.

Updated patch to set default calling convention for main() in CheckMain()


https://reviews.llvm.org/D39210

Files:
  include/clang/Basic/LangOptions.h
  include/clang/Driver/CC1Options.td
  include/clang/Driver/CLCompatOptions.td
  lib/AST/ASTContext.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDecl.cpp
  test/CodeGenCXX/default_calling_conv.cpp
  test/Driver/cl-cc-flags.c

Index: test/Driver/cl-cc-flags.c
===
--- test/Driver/cl-cc-flags.c
+++ test/Driver/cl-cc-flags.c
@@ -13,6 +13,9 @@
 // RUN: %clang_cl --target=i686-windows-msvc /Gv -### -- %s 2>&1 | FileCheck --check-prefix=VECTORCALL %s
 // VECTORCALL: -fdefault-calling-conv=vectorcall
 
+// RUN: %clang_cl --target=i686-windows-msvc /Gregcall -### -- %s 2>&1 | FileCheck --check-prefix=REGCALL %s
+// REGCALL: -fdefault-calling-conv=regcall
+
 // Last one should win:
 
 // RUN: %clang_cl --target=i686-windows-msvc /Gd /Gv -### -- %s 2>&1 | FileCheck --check-prefix=LASTWINS_VECTOR %s
Index: test/CodeGenCXX/default_calling_conv.cpp
===
--- test/CodeGenCXX/default_calling_conv.cpp
+++ test/CodeGenCXX/default_calling_conv.cpp
@@ -3,18 +3,21 @@
 // RUN: %clang_cc1 -triple i486-unknown-linux-gnu -fdefault-calling-conv=stdcall -emit-llvm -o - %s | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
 // RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
 // RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=vectorcall -emit-llvm -o - %s | FileCheck %s --check-prefix=VECTORCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i986-unknown-linux-gnu -fdefault-calling-conv=regcall -emit-llvm -o - %s | FileCheck %s --check-prefix=REGCALL --check-prefix=ALL
 
 // CDECL: define void @_Z5test1v
 // FASTCALL: define x86_fastcallcc void @_Z5test1v
 // STDCALL: define x86_stdcallcc void @_Z5test1v
 // VECTORCALL: define x86_vectorcallcc void @_Z5test1v
+// REGCALL: define x86_regcallcc void @_Z17__regcall3__test1v
 void test1() {}
 
-// fastcall, stdcall, and vectorcall all do not support variadic functions.
+// fastcall, stdcall, vectorcall and regcall do not support variadic functions.
 // CDECL: define void @_Z12testVariadicz
 // FASTCALL: define void @_Z12testVariadicz
 // STDCALL: define void @_Z12testVariadicz
 // VECTORCALL: define void @_Z12testVariadicz
+// REGCALL: define void @_Z12testVariadicz
 void testVariadic(...){}
 
 // ALL: define void @_Z5test2v
@@ -29,6 +32,9 @@
 // ALL: define  x86_vectorcallcc void @_Z5test5v
 void __attribute__((vectorcall)) test5() {}
 
+// ALL: define x86_regcallcc void @_Z17__regcall3__test6v
+void __attribute__((regcall)) test6() {}
+
 // ALL: define linkonce_odr void @_ZN1A11test_memberEv
 class A {
 public:
@@ -39,3 +45,8 @@
   A a;
   a.test_member();
 }
+
+// ALL: define i32 @main
+int main() {
+  return 1;
+}
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -9673,6 +9673,13 @@
   assert(T->isFunctionType() && "function decl is not of function type");
   const FunctionType* FT = T->castAs();
 
+  // Set default calling convention for main()
+  if (FT->getCallConv() != CC_C) {
+FT = Context.adjustFunctionType(FT, FT->getExtInfo().withCallingConv(CC_C));
+FD->setType(QualType(FT, 0));
+T = Context.getCanonicalType(FD->getType());
+  }
+
   if (getLangOpts().GNUMode && !getLangOpts().CPlusPlus) {
 // In C with GNU extensions we allow main() to have non-integer return
 // type, but we should warn about the extension, and we disable the
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2308,12 +2308,12 @@
   // Check for MS default calling conventions being specified.
   if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
 LangOptions::DefaultCallingConvention DefaultCC =
-llvm::StringSwitch(
-A->getValue())
+llvm::StringSwitch(A->getValue())
 .Case("cdecl", LangOptions::DCC_CDecl)
 .Case("fastcall", LangOptions::DCC_FastCall)
 .Case("stdcall", LangOptions::DCC_StdCall)
 .Case("vectorcall", LangOptions::DCC_VectorCall)
+.Case("regcall", LangOptions::DCC_RegCall)
 .Default(LangOptions::DCC_None);
 if (DefaultCC == LangOptions::DCC_None)
   Diags.Report(diag::err_drv_invalid_value)
@@ -2324,7 +2324,8 @@
 bool emitError = (DefaultCC == LangOptions::DCC_FastCall ||
   DefaultCC == LangOptions::DCC_StdCall) &&
  Arch != llvm::Triple::x86;
-emitError |= DefaultCC =

[PATCH] D39210: Add default calling convention support for regcall.

2017-10-25 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added inline comments.



Comment at: lib/Sema/SemaType.cpp:3269-3273
+  bool IsMain = false;
+  if (D.getIdentifier() && D.getIdentifier()->isStr("main") &&
+  S.CurContext->getRedeclContext()->isTranslationUnit() &&
+  !S.getLangOpts().Freestanding)
+IsMain = true;

erichkeane wrote:
> rnk wrote:
> > erichkeane wrote:
> > > rnk wrote:
> > > > I highly doubt this is correct. I have a feeling there are all kinds of 
> > > > ways you can get this to fire on things that aren't a function 
> > > > declaration. It's also inefficient to check the identifier string every 
> > > > time we make a function type. Please find somewhere else to add this. 
> > > > I'd suggest adjusting the function type in CheckMain, or some time 
> > > > before then, whereever we make main implicitly extern "C".
> > > I believe the logic here was pulled from FunctionDecl's "isMain" 
> > > function: 
> > > https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html#aa2b31caf653741632b16cce1ae2061cc
> > > 
> > > As this is so early in the process (at Declarator), I didn't see a good 
> > > place to recommend extracting this, besides pulling it into the 
> > > Declarator.  
> > > 
> > > CheckMain is also run at the Decl stage, isn't it?  Is your suggestion be 
> > > to simply let this go through with the wrong calling-convention here, 
> > > then revert it it in "CheckMain"?
> > Yep. You can look at how we use FunctionTypeUnwrapper and 
> > ASTContext::adjustFunctionType in various places to fix up function types 
> > that were built with the wrong calling convention without losing type 
> > source info.
> Perfect, thanks for the examples!  I am sure @eandrews can use those to track 
> down the right place to fix this up.
Thanks for the review! I've updated the patch. Please take a look.


https://reviews.llvm.org/D39210



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


[PATCH] D38954: [Sema] -Wzero-as-null-pointer-constant: don't warn for system macros other than NULL.

2017-10-25 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 120285.
lebedev.ri added a comment.

- Rebased
- Handle `-Wsystem-headers` properly, as per irc disscussion.

It was suggested that `findMacroSpelling()` might be slow, and 
`isNullPointerConstant()` should be used, but i'm not sure any of the 
`NullPointerConstantKind`'s can replace direct check for `NULL` specifically...


Repository:
  rL LLVM

https://reviews.llvm.org/D38954

Files:
  docs/ReleaseNotes.rst
  lib/Sema/Sema.cpp
  test/SemaCXX/Inputs/warn-zero-nullptr.h
  test/SemaCXX/warn-zero-nullptr.cpp

Index: test/SemaCXX/warn-zero-nullptr.cpp
===
--- test/SemaCXX/warn-zero-nullptr.cpp
+++ test/SemaCXX/warn-zero-nullptr.cpp
@@ -1,4 +1,10 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -Wzero-as-null-pointer-constant -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -verify %s -isystem %S/Inputs -Wzero-as-null-pointer-constant -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -verify %s -isystem %S/Inputs -DSYSTEM_WARNINGS -Wzero-as-null-pointer-constant -Wsystem-headers -std=c++11
+
+#include 
+
+#define MACRO (0)
+#define MCRO(x) (x)
 
 struct S {};
 
@@ -15,13 +21,65 @@
 void (*fp2)() = __null; // expected-warning{{zero as null pointer constant}}
 int (S::*mp2) = __null; // expected-warning{{zero as null pointer constant}}
 
-void f0(void* v = 0); // expected-warning{{zero as null pointer constant}}
-void f1(void* v);
+void f0(void* v = MACRO); // expected-warning{{zero as null pointer constant}}
+void f1(void* v = NULL); // expected-warning{{zero as null pointer constant}}
+void f2(void* v = MCRO(0)); // expected-warning{{zero as null pointer constant}}
+void f3(void* v = MCRO(NULL)); // expected-warning{{zero as null pointer constant}}
+void f4(void* v = 0); // expected-warning{{zero as null pointer constant}}
+void f5(void* v);
 
 void g() {
   f1(0); // expected-warning{{zero as null pointer constant}}
 }
 
 // Warn on these too. Matches gcc and arguably makes sense.
 void* pp = (decltype(nullptr))0; // expected-warning{{zero as null pointer constant}}
 void* pp2 = static_cast(0); // expected-warning{{zero as null pointer constant}}
+
+template  void TmplFunc0(T var) {}
+void Func0Test() {
+  TmplFunc0(0);
+  TmplFunc0(0); // expected-warning {{zero as null pointer constant}}
+  TmplFunc0(0); // expected-warning {{zero as null pointer constant}}
+}
+
+// FIXME: this one should *NOT* warn.
+template  void TmplFunc1(int a, T default_value = 0) {} // expected-warning{{zero as null pointer constant}} expected-warning{{zero as null pointer constant}}
+void FuncTest() {
+  TmplFunc1(0);
+  TmplFunc1(0); // expected-note {{in instantiation of default function argument expression for 'TmplFunc1' required here}}
+  TmplFunc1(0);  // expected-note {{in instantiation of default function argument expression for 'TmplFunc1' required here}}
+}
+
+template
+class TemplateClass0 {
+ public:
+  explicit TemplateClass0(T var) {}
+};
+void TemplateClass0Test() {
+  TemplateClass0 a(0);
+  TemplateClass0 b(0); // expected-warning {{zero as null pointer constant}}
+  TemplateClass0 c(0); // expected-warning {{zero as null pointer constant}}
+}
+
+template
+class TemplateClass1 {
+ public:
+// FIXME: this one should *NOT* warn.
+  explicit TemplateClass1(int a, T default_value = 0) {} // expected-warning{{zero as null pointer constant}} expected-warning{{zero as null pointer constant}}
+};
+void IgnoreSubstTemplateType1() {
+  TemplateClass1 a(1);
+  TemplateClass1 b(1); // expected-note {{in instantiation of default function argument expression for 'TemplateClass1' required here}}
+  TemplateClass1 c(1); // expected-note {{in instantiation of default function argument expression for 'TemplateClass1' required here}}
+}
+
+#ifndef SYSTEM_WARNINGS
+// Do not warn on *any* other macros from system headers, even if they
+// expand to/their expansion contains NULL.
+void* sys_init = SYSTEM_MACRO;
+void* sys_init2 = OTHER_SYSTEM_MACRO;
+#else
+void* sys_init = SYSTEM_MACRO; // expected-warning {{zero as null pointer constant}}
+void* sys_init2 = OTHER_SYSTEM_MACRO; // expected-warning {{zero as null pointer constant}}
+#endif
Index: test/SemaCXX/Inputs/warn-zero-nullptr.h
===
--- /dev/null
+++ test/SemaCXX/Inputs/warn-zero-nullptr.h
@@ -0,0 +1,3 @@
+#define NULL (0)
+#define SYSTEM_MACRO (0)
+#define OTHER_SYSTEM_MACRO (NULL)
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -440,6 +440,15 @@
 return;
   if (E->getType()->isNullPtrType())
 return;
+
+  // If it is a macro from system header, and if the macro name is not "NULL",
+  // do not warn.
+  SourceLocation MaybeMacroLoc = E->getLocStart();
+  if (Diags.getSuppressSystemWarnings() &&
+  SourceMgr.isInSystemMacro(MaybeMacroLoc) &&
+  !findMacroSpelling(MaybeMacroLoc, "NULL"))
+return;
+
   // nullptr o

[PATCH] D39284: [c++2a] Decomposed _condition_

2017-10-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D39284#906800, @lichray wrote:

> In https://reviews.llvm.org/D39284#906450, @aaron.ballman wrote:
>
> > I'm not opposed to the functionality, but this isn't a part of C++2a 
> > either; I think we should be diagnosing this code with a warning so users 
> > don't expect it to work on every compiler.
>
>
> C++2a the standard itself is under development, so the users can't expect any 
> feature to work on every compiler already.


I'm aware, but I was unaware that we've accepted this functionality in C++2a 
yet within WG21. Did we vote this in and I simply didn't remember it?


https://reviews.llvm.org/D39284



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


[PATCH] D39301: Ignore implicity casts for zero-as-null-pointer-constant warning

2017-10-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.

The repro in https://bugs.llvm.org/show_bug.cgi?id=34362
caused the left nullptr to be cast to a int* implicitly, which
resulted diagnosing this falsely.


https://reviews.llvm.org/D39301

Files:
  lib/Sema/Sema.cpp
  test/SemaCXX/warn-zero-nullptr.cpp


Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -438,7 +438,7 @@
 void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
   if (Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
 return;
-  if (E->getType()->isNullPtrType())
+  if (E->IgnoreImpCasts()->getType()->isNullPtrType())
 return;
   // nullptr only exists from C++11 on, so don't warn on its absence earlier.
   if (!getLangOpts().CPlusPlus11)
Index: test/SemaCXX/warn-zero-nullptr.cpp
===
--- test/SemaCXX/warn-zero-nullptr.cpp
+++ test/SemaCXX/warn-zero-nullptr.cpp
@@ -25,3 +25,7 @@
 // Warn on these too. Matches gcc and arguably makes sense.
 void* pp = (decltype(nullptr))0; // expected-warning{{zero as null pointer 
constant}}
 void* pp2 = static_cast(0); // expected-warning{{zero as 
null pointer constant}}
+
+// Shouldn't warn.
+struct pr34362 { operator int*() { return nullptr; } };
+void pr34362_func() { if (nullptr == pr34362()) {} }


Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -438,7 +438,7 @@
 void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
   if (Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
 return;
-  if (E->getType()->isNullPtrType())
+  if (E->IgnoreImpCasts()->getType()->isNullPtrType())
 return;
   // nullptr only exists from C++11 on, so don't warn on its absence earlier.
   if (!getLangOpts().CPlusPlus11)
Index: test/SemaCXX/warn-zero-nullptr.cpp
===
--- test/SemaCXX/warn-zero-nullptr.cpp
+++ test/SemaCXX/warn-zero-nullptr.cpp
@@ -25,3 +25,7 @@
 // Warn on these too. Matches gcc and arguably makes sense.
 void* pp = (decltype(nullptr))0; // expected-warning{{zero as null pointer constant}}
 void* pp2 = static_cast(0); // expected-warning{{zero as null pointer constant}}
+
+// Shouldn't warn.
+struct pr34362 { operator int*() { return nullptr; } };
+void pr34362_func() { if (nullptr == pr34362()) {} }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39301: Ignore implicity casts for zero-as-null-pointer-constant warning

2017-10-25 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: test/SemaCXX/warn-zero-nullptr.cpp:29
+
+// Shouldn't warn.
+struct pr34362 { operator int*() { return nullptr; } };

Maybe wrap into a `namespace PR34362 {}`


https://reviews.llvm.org/D39301



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


[PATCH] D38824: [X86] Synchronize the existing CPU predefined macros with the cases that gcc defines them

2017-10-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Ping


https://reviews.llvm.org/D38824



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


[PATCH] D39301: Ignore implicity casts for zero-as-null-pointer-constant warning

2017-10-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 120288.
erichkeane marked an inline comment as done.
erichkeane added a comment.

Response to Roman's comment.


https://reviews.llvm.org/D39301

Files:
  lib/Sema/Sema.cpp
  test/SemaCXX/warn-zero-nullptr.cpp


Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -438,7 +438,7 @@
 void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
   if (Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
 return;
-  if (E->getType()->isNullPtrType())
+  if (E->IgnoreImpCasts()->getType()->isNullPtrType())
 return;
   // nullptr only exists from C++11 on, so don't warn on its absence earlier.
   if (!getLangOpts().CPlusPlus11)
Index: test/SemaCXX/warn-zero-nullptr.cpp
===
--- test/SemaCXX/warn-zero-nullptr.cpp
+++ test/SemaCXX/warn-zero-nullptr.cpp
@@ -25,3 +25,9 @@
 // Warn on these too. Matches gcc and arguably makes sense.
 void* pp = (decltype(nullptr))0; // expected-warning{{zero as null pointer 
constant}}
 void* pp2 = static_cast(0); // expected-warning{{zero as 
null pointer constant}}
+
+// Shouldn't warn.
+namespace pr34362 {
+struct A { operator int*() { return nullptr; } };
+void func () { if (nullptr == A()) {} }
+}


Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -438,7 +438,7 @@
 void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
   if (Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
 return;
-  if (E->getType()->isNullPtrType())
+  if (E->IgnoreImpCasts()->getType()->isNullPtrType())
 return;
   // nullptr only exists from C++11 on, so don't warn on its absence earlier.
   if (!getLangOpts().CPlusPlus11)
Index: test/SemaCXX/warn-zero-nullptr.cpp
===
--- test/SemaCXX/warn-zero-nullptr.cpp
+++ test/SemaCXX/warn-zero-nullptr.cpp
@@ -25,3 +25,9 @@
 // Warn on these too. Matches gcc and arguably makes sense.
 void* pp = (decltype(nullptr))0; // expected-warning{{zero as null pointer constant}}
 void* pp2 = static_cast(0); // expected-warning{{zero as null pointer constant}}
+
+// Shouldn't warn.
+namespace pr34362 {
+struct A { operator int*() { return nullptr; } };
+void func () { if (nullptr == A()) {} }
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39138: [CodeGen] Generate TBAA info for 'this' pointers

2017-10-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D39138#906623, @kosarev wrote:

> Hmm, according to our research such loads constitute about 18% of all loads 
> under ##-O -Xclang -disable-llvm-passes## on the LLVM code base. I wonder, do 
> you think it would be nice to not generate them at all? I mean, provided that 
> necessary changes do not add too much special-case code.


It would be straightforward to not generate them, but it would create longer 
live ranges at -O0 and allow 'this' to disappear in debug info, both of which 
are undesirable.


Repository:
  rL LLVM

https://reviews.llvm.org/D39138



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


[PATCH] D38796: [CodeGen] EmitPointerWithAlignment() to generate TBAA info along with LValue base info

2017-10-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I think probably the best solution is to track may-alias-ness explicitly in the 
TBAAAccessInfo instead of relying in the frontend on being able to distinguish 
things in the LLVM metadata.


Repository:
  rL LLVM

https://reviews.llvm.org/D38796



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


[PATCH] D39301: Ignore implicity casts for zero-as-null-pointer-constant warning

2017-10-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/Sema/Sema.cpp:441
 return;
-  if (E->getType()->isNullPtrType())
+  if (E->IgnoreImpCasts()->getType()->isNullPtrType())
 return;

Do we also want to ignore parens here as well with 
`Expr::IgnoreParenImpCasts()`?


https://reviews.llvm.org/D39301



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


[PATCH] D39284: [c++2a] Decomposed _condition_

2017-10-25 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray added a comment.

In https://reviews.llvm.org/D39284#906860, @aaron.ballman wrote:

> I'm aware, but I was unaware that we've accepted this functionality in C++2a 
> yet within WG21. Did we vote this in and I simply didn't remember it?


No.  In the first line of the Summary I said this hasn't even been proposed.  
But on the reflectors it received positive feedback.  While I was trying to 
implement it in order to find out corner cases which I haven't thought of, I 
found that the implementation is astonishingly simple, defending the change by 
showing that not introducing the change to the language is merely complicating 
the language, so I decided to seeking for a possibility to land it first.


https://reviews.llvm.org/D39284



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


[PATCH] D39301: Ignore implicity casts for zero-as-null-pointer-constant warning

2017-10-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: lib/Sema/Sema.cpp:441
 return;
-  if (E->getType()->isNullPtrType())
+  if (E->IgnoreImpCasts()->getType()->isNullPtrType())
 return;

aaron.ballman wrote:
> Do we also want to ignore parens here as well with 
> `Expr::IgnoreParenImpCasts()`?
I don't see a reason why not!  Patch incoming.


https://reviews.llvm.org/D39301



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


[PATCH] D39301: Ignore implicity casts for zero-as-null-pointer-constant warning

2017-10-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 120289.
erichkeane added a comment.

Lets ignore parens too!


https://reviews.llvm.org/D39301

Files:
  lib/Sema/Sema.cpp
  test/SemaCXX/warn-zero-nullptr.cpp


Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -438,7 +438,7 @@
 void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
   if (Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
 return;
-  if (E->getType()->isNullPtrType())
+  if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
 return;
   // nullptr only exists from C++11 on, so don't warn on its absence earlier.
   if (!getLangOpts().CPlusPlus11)
Index: test/SemaCXX/warn-zero-nullptr.cpp
===
--- test/SemaCXX/warn-zero-nullptr.cpp
+++ test/SemaCXX/warn-zero-nullptr.cpp
@@ -25,3 +25,9 @@
 // Warn on these too. Matches gcc and arguably makes sense.
 void* pp = (decltype(nullptr))0; // expected-warning{{zero as null pointer 
constant}}
 void* pp2 = static_cast(0); // expected-warning{{zero as 
null pointer constant}}
+
+// Shouldn't warn.
+namespace pr34362 {
+struct A { operator int*() { return nullptr; } };
+void func () { if (nullptr == A()) {} }
+}


Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -438,7 +438,7 @@
 void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr* E) {
   if (Kind != CK_NullToPointer && Kind != CK_NullToMemberPointer)
 return;
-  if (E->getType()->isNullPtrType())
+  if (E->IgnoreParenImpCasts()->getType()->isNullPtrType())
 return;
   // nullptr only exists from C++11 on, so don't warn on its absence earlier.
   if (!getLangOpts().CPlusPlus11)
Index: test/SemaCXX/warn-zero-nullptr.cpp
===
--- test/SemaCXX/warn-zero-nullptr.cpp
+++ test/SemaCXX/warn-zero-nullptr.cpp
@@ -25,3 +25,9 @@
 // Warn on these too. Matches gcc and arguably makes sense.
 void* pp = (decltype(nullptr))0; // expected-warning{{zero as null pointer constant}}
 void* pp2 = static_cast(0); // expected-warning{{zero as null pointer constant}}
+
+// Shouldn't warn.
+namespace pr34362 {
+struct A { operator int*() { return nullptr; } };
+void func () { if (nullptr == A()) {} }
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38985: [refactor] Add support for editor commands that connect IDEs/editors to the refactoring actions

2017-10-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks, this looks a bunch simpler.

I have a question about the direction here: AFAICS there's various efforts in 
the refactoring infrastructure to allow consumers of the Refactor libs (e.g. 
clang-refactor, clangd, XCode?) to operate without knowing the details of the 
refactorings.

One example is the treating the identifying `Name` of a rule as data, instead 
of referring to a subclass directly. Another is the way options are 
communicated via `OptionsVisitor` and `Requirement`s etc, where they could be 
more directly expressed as members of a `Rule`-specific struct or parameters to 
a function.

An interface that truly decouples N refactorings from M consumers has 
scalability advantages, but there are some things that cut against it:

- It tends to add complexity/indirection, which can slow down contributors, 
mask bugs, and makes certain features (ones that don't fit into the existing 
framework) hard to add.
- If the generic interfaces aren't enough we pierce them, resulting in both 
coupling *and* complexity. e.g. Clangd really needs control over how 
refactorings are exposed: which ones are visible under what names, how the 
JSON-RPC messages are structured. (Because its protocol isn't really an 
implementation detail under our control, we need to be able to adapt 
to/influence editors and evolution of the LSP standard).

What's the biggest value we get out of the generic interface? Whose life would 
get harder if refactorings had this strawman interface/concept?

  template
  class Refactoring {
 bool available(RefactoringContext&, const Options&) = 0;
 Error invoke(RefactoringContext&, const Options&, RefactoringConsumer&) = 
0;
  }

@klimek may have thoughts here.




Comment at: include/clang/Tooling/Refactoring/RefactoringActionRule.h:60
+  /// associated with this rule.
+  virtual Optional> getEditorCommandInfo() {
+return None;

ioeric wrote:
> I think `getEditorCommandInfo` might be a wrong name here.
> 
> IMO, all end rules (i.e. editor-facing rules) should have name information. 
> It might make sense to introduce a structure that holds all metadata about a 
> rule as well as an interface that returns such a structure. With that, we 
> also don't need to update the API when more rule information is added in the 
> future. 
> 
> I also think the interface should be pure virtual, and all end rules should 
> implement this interface since they should have names or metadata of some 
> sort. 
I like the idea of to moving metadata like Title to the RefactoringActionRule 
through a method like getEditorCommandInfo(), though as Eric says a struct 
would be clearer.

Is there any reason to make it optional and rebindable? Surely we can come up 
with a reasonable name for each rule, and if the editor wants to use a 
different name for some purpose, it can do so without help from the framework 
(e.g. put the RefactoringActionRule in a struct).



Repository:
  rL LLVM

https://reviews.llvm.org/D38985



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


[PATCH] D39220: [Analyzer] Store BodyFarm in std::unique_ptr

2017-10-25 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added inline comments.



Comment at: include/clang/Analysis/AnalysisDeclContext.h:424
   /// methods during the analysis.
-  BodyFarm *BdyFrm = nullptr;
+  std::unique_ptr BdyFrm;
 

alexfh wrote:
> george.karpenkov wrote:
> > alexfh wrote:
> > > BdyFrm is somewhat cryptic. Maybe Farm, Bodies or something else that  is 
> > > not so weirdly abbreviated?
> > But that's just forced on us by the naming convention, isn't it? I think 
> > other names are worse though: they don't tell us which class we can look at 
> > to figure out what is it doing.
> LLVM Coding Standards doesn't endorse this kind of an abbreviation, on the 
> opposite:
> "We cannot stress enough how important it is to use descriptive names. ... 
> Avoid abbreviations unless they are well known." 
> (http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly).
>  Neither "Bdy" nor "Frm" are well known or otherwise clear to the reader. 
> "Frm" could also stand for "Form" or "Frame", but in these cases it would 
> also be confusing.
> 
> If you consider shorter names ("Bodies" or "Farm") non-informative, we can go 
> the other direction, e.g. "FunctionBodyFarm".
What I've meant to say is that I think a good way to write it would be to use 
`unique_ptr bodyFarm`, or even better `unique_ptr 
m_bodyFarm`, which is sadly not allowed. We already have a good informative 
name: the name of the class, and due to the convention we have to modify it :(


Repository:
  rL LLVM

https://reviews.llvm.org/D39220



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


[PATCH] D39301: Ignore implicity casts for zero-as-null-pointer-constant warning

2017-10-25 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: lib/Sema/Sema.cpp:441
 return;
-  if (E->getType()->isNullPtrType())
+  if (E->IgnoreImpCasts()->getType()->isNullPtrType())
 return;

erichkeane wrote:
> aaron.ballman wrote:
> > Do we also want to ignore parens here as well with 
> > `Expr::IgnoreParenImpCasts()`?
> I don't see a reason why not!  Patch incoming.
Probably needs a test too :)


https://reviews.llvm.org/D39301



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


[PATCH] D39284: [c++2a] Decomposed _condition_

2017-10-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D39284#906889, @lichray wrote:

> In https://reviews.llvm.org/D39284#906860, @aaron.ballman wrote:
>
> > I'm aware, but I was unaware that we've accepted this functionality in 
> > C++2a yet within WG21. Did we vote this in and I simply didn't remember it?
>
>
> No.  In the first line of the Summary I said this hasn't even been proposed.  
> But on the reflectors it received positive feedback.  While I was trying to 
> implement it in order to find out corner cases which I haven't thought of, I 
> found that the implementation is astonishingly simple, defending the change 
> by showing that not introducing the change to the language is merely 
> complicating the language, so I decided to seeking for a possibility to land 
> it first.


Okay, then I didn't misunderstand you and we're on the same page.

We typically diagnose vendor extensions to the language, and I think we should 
apply that consistently. Otherwise, your code will compile fine in Clang with 
warning levels cranked all the way up and then fail to compile on every other 
compiler, which does not do our users any good. I'll let Richard have the final 
say for this, but my preference is that this is diagnosed as an extension (at 
least in pedantic mode).


https://reviews.llvm.org/D39284



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


[PATCH] D38954: [Sema] -Wzero-as-null-pointer-constant: don't warn for system macros other than NULL.

2017-10-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Can you build some large-ish codebase (say, LLVM) with and without this patch 
and make sure that this doesn't measurably add to build perf? (With the warning 
turned on, obviously.)

Other than that, this looks good to me.




Comment at: test/SemaCXX/warn-zero-nullptr.cpp:68
+ public:
+// FIXME: this one should *NOT* warn.
+  explicit TemplateClass1(int a, T default_value = 0) {} // 
expected-warning{{zero as null pointer constant}} expected-warning{{zero as 
null pointer constant}}

Did you mean to fix this before commit?


Repository:
  rL LLVM

https://reviews.llvm.org/D38954



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


[PATCH] D39301: Ignore implicity casts for zero-as-null-pointer-constant warning

2017-10-25 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!


https://reviews.llvm.org/D39301



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


[PATCH] D39301: Ignore implicity casts for zero-as-null-pointer-constant warning

2017-10-25 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.

Awesome, thanks much! Like lebedev.ri says, adding a test for the "Parens" part 
would be good.


https://reviews.llvm.org/D39301



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


[PATCH] D39301: Ignore implicity casts for zero-as-null-pointer-constant warning

2017-10-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

They've got me presenting in the next meeting, but i'll add said test and 
commit after.  Thanks for the reviews guys!


https://reviews.llvm.org/D39301



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


Re: r315126 - Driver: hoist the `wchar_t` handling to the driver

2017-10-25 Thread Reid Kleckner via cfe-commits
On Wed, Oct 25, 2017 at 10:56 AM, Friedman, Eli 
wrote:

> On 10/6/2017 4:09 PM, Saleem Abdulrasool via cfe-commits wrote:
>
>> Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Too
>> lChains/Clang.cpp?rev=315126&r1=315125&r2=315126&view=diff
>> 
>> ==
>> --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
>> +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Oct  6 16:09:55 2017
>> @@ -2601,6 +2601,33 @@ static void RenderModulesOptions(Compila
>> Args.AddLastArg(CmdArgs, options::OPT_fmodules_disable_
>> diagnostic_validation);
>>   }
>>   +static void RenderCharacterOptions(const ArgList &Args, const
>> llvm::Triple &T,
>> +   ArgStringList &CmdArgs) {
>> +  // -fsigned-char is default.
>> +  if (const Arg *A = Args.getLastArg(options::OPT_fsigned_char,
>> + options::OPT_fno_signed_char,
>> + options::OPT_funsigned_char,
>> + options::OPT_fno_unsigned_char)) {
>> +if (A->getOption().matches(options::OPT_funsigned_char) ||
>> +A->getOption().matches(options::OPT_fno_signed_char)) {
>> +  CmdArgs.push_back("-fno-signed-char");
>> +}
>> +  } else if (!isSignedCharDefault(T)) {
>> +CmdArgs.push_back("-fno-signed-char");
>> +  }
>> +
>> +  if (const Arg *A = Args.getLastArg(options::OPT_fshort_wchar,
>> + options::OPT_fno_short_wchar)) {
>> +if (A->getOption().matches(options::OPT_fshort_wchar)) {
>> +  CmdArgs.push_back("-fwchar-type=short");
>> +  CmdArgs.push_back("-fno-signed-wchar");
>> +} else {
>> +  CmdArgs.push_back("-fwchar-type=int");
>> +  CmdArgs.push_back("-fsigned-wchar");
>> +}
>> +  }
>> +}
>>
>
> It looks like this changes the behavior of "-fno-short-wchar".
> Specifically, on targets where the default wchar_t type is "unsigned int"
> (like ARM AAPCS), "-fno-short-wchar" used to be a no-op, but now it changes
> the sign of wchar_t.  Why are we overriding the default here?


Overriding the default was more or less the intention, but it was for
bitwidth, not signedness. The idea was that if you pass -fno-short-wchar,
then you want the 4 byte one.

Users probably don't care about signedness when using 4 byte wchars, so we
could probably remove the -fsigned-wchar flag from the else block and take
the original sign of wchar_t when overriding the width in Basic. They
probably want an 'unsigned short' when -fshort-wchar is passed, though.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39301: Ignore implicity casts for zero-as-null-pointer-constant warning

2017-10-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D39301#906911, @thakis wrote:

> Awesome, thanks much! Like lebedev.ri says, adding a test for the "Parens" 
> part would be good.


I agree. I should have been more explicit with my LGTM, but I presumed you knew 
to add the tests already. ;-)


https://reviews.llvm.org/D39301



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


[PATCH] D38954: [Sema] -Wzero-as-null-pointer-constant: don't warn for system macros other than NULL.

2017-10-25 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D38954#906900, @thakis wrote:

> Can you build some large-ish codebase (say, LLVM) with and without this patch 
> and make sure that this doesn't measurably add to build perf? (With the 
> warning turned on, obviously.)
>
> Other than that, this looks good to me.


Very contrived example:

  $ head -n 3 test.cpp 
  #include 
  
  int main(int argc, char* argv[]) {
  $ perl -e 'print "if(argv == NULL) return 1;\n"x100; print "\n"' >> 
test.cpp
  $ tail -n 2 test.cpp 
  }

So this is a file with 1 million comparisons of pointer with `NULL`.

  $ time clang -fsyntax-only -Wzero-as-null-pointer-constant -std=c++11 
test.cpp -w
  
  real0m8.197s
  user0m8.071s
  sys 0m0.124s
  $ time clang -fsyntax-only -Wzero-as-null-pointer-constant -std=c++11 
test.cpp -w
  
  real0m7.881s
  user0m7.728s
  sys 0m0.152s
  $ time clang -fsyntax-only -Wzero-as-null-pointer-constant -std=c++11 
test.cpp -w
  
  real0m7.212s
  user0m7.063s
  sys 0m0.148s
  $ time /build/llvm-build-Clang-release/bin/clang -fsyntax-only 
-Wzero-as-null-pointer-constant -std=c++11 test.cpp -w
  
  real0m11.200s
  user0m11.070s
  sys 0m0.128s
  $ time /build/llvm-build-Clang-release/bin/clang -fsyntax-only 
-Wzero-as-null-pointer-constant -std=c++11 test.cpp -w
  
  real0m11.141s
  user0m11.019s
  sys 0m0.121s
  $ time /build/llvm-build-Clang-release/bin/clang -fsyntax-only 
-Wzero-as-null-pointer-constant -std=c++11 test.cpp -w
  
  real0m11.254s
  user0m11.127s
  sys 0m0.126s

So there absolutely is some penalty, but it does not appear to be huge, at 
least on this contrived example.
I *could* try benchmark-building llvm, but i'm still sporadically experiencing 
a crash , so the timings will not 
be comparable.




Comment at: test/SemaCXX/warn-zero-nullptr.cpp:68
+ public:
+// FIXME: this one should *NOT* warn.
+  explicit TemplateClass1(int a, T default_value = 0) {} // 
expected-warning{{zero as null pointer constant}} expected-warning{{zero as 
null pointer constant}}

thakis wrote:
> Did you mean to fix this before commit?
Eh, i'm conflicted about this one.
This is more of "for future consideration"


Repository:
  rL LLVM

https://reviews.llvm.org/D38954



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


  1   2   >