[PATCH] D66951: [ASTImporter] Add comprehensive tests for ODR violation handling strategies

2019-09-16 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/unittests/AST/ASTImporterODRStrategiesTest.cpp:274
+// There may be a hidden fwd spec decl before a function spec decl.
+if (auto *PrevF = dyn_cast(ImportedD)) {
+  if (PrevF->getTemplatedKind() ==

This should be called `ImportedF` instead of `PrevF`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66951/new/

https://reviews.llvm.org/D66951



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


[PATCH] D67541: [ClangFormat] Future-proof Standard option, allow floating or pinning to arbitrary lang version

2019-09-16 Thread Manuel Klimek via Phabricator via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67541/new/

https://reviews.llvm.org/D67541



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


[PATCH] D67606: Change signature of __builtin_rotateright64 back to unsigned

2019-09-16 Thread Karl-Johan Karlsson via Phabricator via cfe-commits
Ka-Ka created this revision.
Ka-Ka added a reviewer: efriedma.
Herald added a subscriber: kristina.
Herald added a project: clang.

The signature of __builtin_rotateright64 was by misstake changed from
unsigned to signed in r360863, this patch will change it back to
unsigned as intended.

This fixes pr43309


Repository:
  rC Clang

https://reviews.llvm.org/D67606

Files:
  include/clang/Basic/Builtins.def
  test/AST/builtins.c


Index: test/AST/builtins.c
===
--- /dev/null
+++ test/AST/builtins.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s | FileCheck %s
+
+unsigned char rotright8(unsigned char x, unsigned char y) {
+return __builtin_rotateright8(x, y);
+}
+// CHECK: __builtin_rotateright8 'unsigned char (unsigned char, unsigned char)'
+
+unsigned int rotright16(unsigned int x, unsigned int y) {
+return __builtin_rotateright16(x, y);
+}
+// CHECK: __builtin_rotateright16 'unsigned short (unsigned short, unsigned 
short)'
+
+unsigned long rotright32(unsigned long x, unsigned long y) {
+return __builtin_rotateright32(x, y);
+}
+// CHECK: __builtin_rotateright32 'unsigned int (unsigned int, unsigned int)'
+
+unsigned long long rotright64(unsigned long long x, unsigned long long y) {
+return __builtin_rotateright64(x, y);
+}
+// This verifies pr43309
+// CHECK: __builtin_rotateright64 'unsigned long (unsigned long, unsigned 
long)'
Index: include/clang/Basic/Builtins.def
===
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -461,7 +461,7 @@
 BUILTIN(__builtin_rotateright8, "UcUcUc", "nc")
 BUILTIN(__builtin_rotateright16, "UsUsUs", "nc")
 BUILTIN(__builtin_rotateright32, "UZiUZiUZi", "nc")
-BUILTIN(__builtin_rotateright64, "UWiUWiWi", "nc")
+BUILTIN(__builtin_rotateright64, "UWiUWiUWi", "nc")
 
 // Random GCC builtins
 BUILTIN(__builtin_constant_p, "i.", "nctu")


Index: test/AST/builtins.c
===
--- /dev/null
+++ test/AST/builtins.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s | FileCheck %s
+
+unsigned char rotright8(unsigned char x, unsigned char y) {
+return __builtin_rotateright8(x, y);
+}
+// CHECK: __builtin_rotateright8 'unsigned char (unsigned char, unsigned char)'
+
+unsigned int rotright16(unsigned int x, unsigned int y) {
+return __builtin_rotateright16(x, y);
+}
+// CHECK: __builtin_rotateright16 'unsigned short (unsigned short, unsigned short)'
+
+unsigned long rotright32(unsigned long x, unsigned long y) {
+return __builtin_rotateright32(x, y);
+}
+// CHECK: __builtin_rotateright32 'unsigned int (unsigned int, unsigned int)'
+
+unsigned long long rotright64(unsigned long long x, unsigned long long y) {
+return __builtin_rotateright64(x, y);
+}
+// This verifies pr43309
+// CHECK: __builtin_rotateright64 'unsigned long (unsigned long, unsigned long)'
Index: include/clang/Basic/Builtins.def
===
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -461,7 +461,7 @@
 BUILTIN(__builtin_rotateright8, "UcUcUc", "nc")
 BUILTIN(__builtin_rotateright16, "UsUsUs", "nc")
 BUILTIN(__builtin_rotateright32, "UZiUZiUZi", "nc")
-BUILTIN(__builtin_rotateright64, "UWiUWiWi", "nc")
+BUILTIN(__builtin_rotateright64, "UWiUWiUWi", "nc")
 
 // Random GCC builtins
 BUILTIN(__builtin_constant_p, "i.", "nctu")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67341: [clangd] Simplify semantic highlighting visitor

2019-09-16 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

@hokein, do you want to do another round or is this good to go?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67341/new/

https://reviews.llvm.org/D67341



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


[PATCH] D67606: Change signature of __builtin_rotateright64 back to unsigned

2019-09-16 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

A simpler way to test this might be to check for conversion warnings in the 
existing clang/test/CodeGen/avr-builtins.c test, for example like as above. I 
think that's better since it covers more of the signatures, e.g. the rotateleft 
ones too.

  diff --git a/clang/test/CodeGen/avr-builtins.c 
b/clang/test/CodeGen/avr-builtins.c
  index cbba6b2f2a2..0d9ce91ad69 100644
  --- a/clang/test/CodeGen/avr-builtins.c
  +++ b/clang/test/CodeGen/avr-builtins.c
  @@ -1,5 +1,9 @@
   // RUN: %clang_cc1 -triple avr-unknown-unknown -emit-llvm -o - %s | 
FileCheck %s
   
  +// Check that the parameter types match.
  +// RUN: %clang_cc1 -triple avr-unknown-unknown -Wconversion -verify %s
  +// expected-no-diagnostics
  +
   unsigned char bitrev8(unsigned char data) {
   return __builtin_bitreverse8(data);
   }


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67606/new/

https://reviews.llvm.org/D67606



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


[PATCH] D67607: [clangd] Fix a crash when renaming operator.

2019-09-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 220289.
hokein added a comment.

Fix an accident change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67607/new/

https://reviews.llvm.org/D67607

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h


Index: clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
===
--- clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
+++ clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
@@ -122,8 +122,7 @@
 ND, SourceRange(BeginLoc, EndLoc));
   }
   bool visit(const NamedDecl *ND, SourceLocation Loc) {
-return visit(ND, Loc,
- Loc.getLocWithOffset(ND->getNameAsString().length() - 1));
+return visit(ND, Loc, Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts));
   }
 };
 
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -136,6 +136,13 @@
)cpp",
   "not a supported kind", HeaderFile},
 
+  {
+
+  R"cpp(
+struct X { X operator++(int) {} };
+void f(X x) {x+^+;})cpp",
+  "not a supported kind", HeaderFile},
+
   {R"cpp(// foo is declared outside the file.
 void fo^o() {}
   )cpp", "used outside main file", !HeaderFile/*cc file*/},
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -74,6 +74,10 @@
const SymbolIndex *Index) {
   if (llvm::isa(&RenameDecl))
 return ReasonToReject::UnsupportedSymbol;
+  if (const auto *FD = llvm::dyn_cast(&RenameDecl)) {
+if (FD->isOverloadedOperator())
+  return ReasonToReject::UnsupportedSymbol;
+  }
   auto &ASTCtx = RenameDecl.getASTContext();
   const auto &SM = ASTCtx.getSourceManager();
   bool MainFileIsHeader = ASTCtx.getLangOpts().IsHeaderFile;


Index: clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
===
--- clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
+++ clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
@@ -122,8 +122,7 @@
 ND, SourceRange(BeginLoc, EndLoc));
   }
   bool visit(const NamedDecl *ND, SourceLocation Loc) {
-return visit(ND, Loc,
- Loc.getLocWithOffset(ND->getNameAsString().length() - 1));
+return visit(ND, Loc, Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts));
   }
 };
 
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -136,6 +136,13 @@
)cpp",
   "not a supported kind", HeaderFile},
 
+  {
+
+  R"cpp(
+struct X { X operator++(int) {} };
+void f(X x) {x+^+;})cpp",
+  "not a supported kind", HeaderFile},
+
   {R"cpp(// foo is declared outside the file.
 void fo^o() {}
   )cpp", "used outside main file", !HeaderFile/*cc file*/},
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -74,6 +74,10 @@
const SymbolIndex *Index) {
   if (llvm::isa(&RenameDecl))
 return ReasonToReject::UnsupportedSymbol;
+  if (const auto *FD = llvm::dyn_cast(&RenameDecl)) {
+if (FD->isOverloadedOperator())
+  return ReasonToReject::UnsupportedSymbol;
+  }
   auto &ASTCtx = RenameDecl.getASTContext();
   const auto &SM = ASTCtx.getSourceManager();
   bool MainFileIsHeader = ASTCtx.getLangOpts().IsHeaderFile;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67607: [clangd] Fix a crash when renaming operator.

2019-09-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.
hokein retitled this revision from "clangd] Fix a crash when renaming 
operator." to "[clangd] Fix a crash when renaming operator.".
hokein updated this revision to Diff 220289.
hokein added a comment.

Fix an accident change.


The renamelib uses a tricky way to calculate the end location by relying
on decl name, this is incorrect for the overloaded operator (the name is
"operator++" instead of "++"), which will cause out-of-file offset.

We also disable renaming operator symbol, this case is tricky, and
renamelib doesnt handle it properly..


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67607

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h


Index: clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
===
--- clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
+++ clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
@@ -122,8 +122,7 @@
 ND, SourceRange(BeginLoc, EndLoc));
   }
   bool visit(const NamedDecl *ND, SourceLocation Loc) {
-return visit(ND, Loc,
- Loc.getLocWithOffset(ND->getNameAsString().length() - 1));
+return visit(ND, Loc, Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts));
   }
 };
 
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -136,6 +136,13 @@
)cpp",
   "not a supported kind", HeaderFile},
 
+  {
+
+  R"cpp(
+struct X { X operator++(int) {} };
+void f(X x) {x+^+;})cpp",
+  "not a supported kind", HeaderFile},
+
   {R"cpp(// foo is declared outside the file.
 void fo^o() {}
   )cpp", "used outside main file", !HeaderFile/*cc file*/},
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -74,6 +74,10 @@
const SymbolIndex *Index) {
   if (llvm::isa(&RenameDecl))
 return ReasonToReject::UnsupportedSymbol;
+  if (const auto *FD = llvm::dyn_cast(&RenameDecl)) {
+if (FD->isOverloadedOperator())
+  return ReasonToReject::UnsupportedSymbol;
+  }
   auto &ASTCtx = RenameDecl.getASTContext();
   const auto &SM = ASTCtx.getSourceManager();
   bool MainFileIsHeader = ASTCtx.getLangOpts().IsHeaderFile;


Index: clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
===
--- clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
+++ clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
@@ -122,8 +122,7 @@
 ND, SourceRange(BeginLoc, EndLoc));
   }
   bool visit(const NamedDecl *ND, SourceLocation Loc) {
-return visit(ND, Loc,
- Loc.getLocWithOffset(ND->getNameAsString().length() - 1));
+return visit(ND, Loc, Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts));
   }
 };
 
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -136,6 +136,13 @@
)cpp",
   "not a supported kind", HeaderFile},
 
+  {
+
+  R"cpp(
+struct X { X operator++(int) {} };
+void f(X x) {x+^+;})cpp",
+  "not a supported kind", HeaderFile},
+
   {R"cpp(// foo is declared outside the file.
 void fo^o() {}
   )cpp", "used outside main file", !HeaderFile/*cc file*/},
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -74,6 +74,10 @@
const SymbolIndex *Index) {
   if (llvm::isa(&RenameDecl))
 return ReasonToReject::UnsupportedSymbol;
+  if (const auto *FD = llvm::dyn_cast(&RenameDecl)) {
+if (FD->isOverloadedOperator())
+  return ReasonToReject::UnsupportedSymbol;
+  }
   auto &ASTCtx = RenameDecl.getASTContext();
   const auto &SM = ASTCtx.getSourceManager();
   bool MainFileIsHeader = ASTCtx.getLangOpts().IsHeaderFile;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67135: [clang-tidy] performance-inefficient-vector-operation: Support proto repeated field

2019-09-16 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL371963: [clang-tidy] 
performance-inefficient-vector-operation: Support proto repeated… (authored by 
hokein, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67135?vs=219988&id=220290#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67135/new/

https://reviews.llvm.org/D67135

Files:
  
clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp
  
clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.h
  
clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
  
clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-vector-operation.cpp

Index: clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-vector-operation.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-vector-operation.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-vector-operation.cpp
@@ -1,4 +1,7 @@
-// RUN: %check_clang_tidy %s performance-inefficient-vector-operation %t -- -format-style=llvm
+// RUN: %check_clang_tidy %s performance-inefficient-vector-operation %t -- \
+// RUN: -format-style=llvm \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: performance-inefficient-vector-operation.EnableProto, value: 1}]}'
 
 namespace std {
 
@@ -62,13 +65,35 @@
 
 int Op(int);
 
+namespace proto2 {
+class MessageLite {};
+class Message : public MessageLite {};
+} // namespace proto2
+
+class FooProto : public proto2::Message {
+ public:
+  int *add_x();  // repeated int x;
+  void add_x(int x);
+  void mutable_x();
+  void mutable_y();
+  int add_z() const; // optional int add_z;
+};
+
+class BarProto : public proto2::Message {
+ public:
+  int *add_x();
+  void add_x(int x);
+  void mutable_x();
+  void mutable_y();
+};
+
 void f(std::vector& t) {
   {
 std::vector v0;
 // CHECK-FIXES: v0.reserve(10);
 for (int i = 0; i < 10; ++i)
   v0.push_back(i);
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called inside a loop; consider pre-allocating the vector capacity before the loop
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop
   }
   {
 std::vector v1;
@@ -162,6 +187,15 @@
 }
   }
 
+  {
+FooProto foo;
+// CHECK-FIXES: foo.mutable_x()->Reserve(5);
+for (int i = 0; i < 5; i++) {
+  foo.add_x(i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'add_x' is called inside a loop; consider pre-allocating the container capacity before the loop
+}
+  }
+
   //  Non-fixed Cases 
   {
 std::vector z0;
@@ -274,4 +308,54 @@
   z12.push_back(e);
 }
   }
+
+  {
+FooProto foo;
+foo.mutable_x();
+// CHECK-FIXES-NOT: foo.mutable_x()->Reserve(5);
+for (int i = 0; i < 5; i++) {
+  foo.add_x(i);
+}
+  }
+  {
+FooProto foo;
+// CHECK-FIXES-NOT: foo.mutable_x()->Reserve(5);
+for (int i = 0; i < 5; i++) {
+  foo.add_x(i);
+  foo.add_x(i);
+}
+  }
+  {
+FooProto foo;
+// CHECK-FIXES-NOT: foo.mutable_x()->Reserve(5);
+foo.add_x(-1);
+for (int i = 0; i < 5; i++) {
+  foo.add_x(i);
+}
+  }
+  {
+FooProto foo;
+BarProto bar;
+bar.mutable_x();
+// CHECK-FIXES-NOT: foo.mutable_x()->Reserve(5);
+for (int i = 0; i < 5; i++) {
+  foo.add_x();
+  bar.add_x();
+}
+  }
+  {
+FooProto foo;
+foo.mutable_y();
+// CHECK-FIXES-NOT: foo.mutable_x()->Reserve(5);
+for (int i = 0; i < 5; i++) {
+  foo.add_x(i);
+}
+  }
+  {
+FooProto foo;
+// CHECK-FIXES-NOT: foo.mutable_z()->Reserve(5);
+for (int i = 0; i < 5; i++) {
+  foo.add_z();
+}
+  }
 }
Index: clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.h
+++ clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.h
@@ -18,6 +18,9 @@
 /// Finds possible inefficient `std::vector` operations (e.g. `push_back`) in
 /// for loops that may cause unnecessary memory reallocations.
 ///
+/// When EnableProto, also finds calls that add element to protobuf repeated
+/// field without calling Reserve() first.
+///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/performance-inefficient-vector-operation.html
 class InefficientVectorOperationCheck : public ClangTidyCheck {
@@ -28,7 +31,14 @@
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
 
 private:
+  void AddMatcher(const ast_matchers::DeclarationMatcher &TargetRecordDecl,
+   

[clang-tools-extra] r371963 - [clang-tidy] performance-inefficient-vector-operation: Support proto repeated field

2019-09-16 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Sep 16 01:54:10 2019
New Revision: 371963

URL: http://llvm.org/viewvc/llvm-project?rev=371963&view=rev
Log:
[clang-tidy] performance-inefficient-vector-operation: Support proto repeated 
field

Summary:
Finds calls that add element to protobuf repeated field in a loop
without calling Reserve() before the loop. Calling Reserve() first can avoid
unnecessary memory reallocations.

A new option EnableProto is added to guard this feature.

Patch by Cong Liu!

Reviewers: gribozavr, alexfh, hokein, aaron.ballman

Reviewed By: hokein

Subscribers: lebedev.ri, xazax.hun, Eugene.Zelenko, cfe-commits

Tags: #clang, #clang-tools-extra

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

Modified:

clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp

clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-vector-operation.rst

clang-tools-extra/trunk/test/clang-tidy/performance-inefficient-vector-operation.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp?rev=371963&r1=371962&r2=371963&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp
 Mon Sep 16 01:54:10 2019
@@ -29,26 +29,37 @@ namespace {
 //   for (int i = 0; i < 10 + 1; ++i) {
 // v.push_back(i);
 //   }
+//
+//   SomeProto p;
+//   for (int i = 0; i < 10 + 1; ++i) {
+// p.add_xxx(i);
+//   }
 // }
 // \endcode
 //
 // The matcher names are bound to following parts of the AST:
 //   - LoopCounterName: The entire for loop (as ForStmt).
 //   - LoopParentName: The body of function f (as CompoundStmt).
-//   - VectorVarDeclName: 'v' in  (as VarDecl).
+//   - VectorVarDeclName: 'v' (as VarDecl).
 //   - VectorVarDeclStmatName: The entire 'std::vector v;' statement (as
 // DeclStmt).
 //   - PushBackOrEmplaceBackCallName: 'v.push_back(i)' (as cxxMemberCallExpr).
 //   - LoopInitVarName: 'i' (as VarDecl).
 //   - LoopEndExpr: '10+1' (as Expr).
+// If EnableProto, the proto related names are bound to the following parts:
+//   - ProtoVarDeclName: 'p' (as VarDecl).
+//   - ProtoVarDeclStmtName: The entire 'SomeProto p;' statement (as DeclStmt).
+//   - ProtoAddFieldCallName: 'p.add_xxx(i)' (as cxxMemberCallExpr).
 static const char LoopCounterName[] = "for_loop_counter";
 static const char LoopParentName[] = "loop_parent";
 static const char VectorVarDeclName[] = "vector_var_decl";
 static const char VectorVarDeclStmtName[] = "vector_var_decl_stmt";
 static const char PushBackOrEmplaceBackCallName[] = "append_call";
+static const char ProtoVarDeclName[] = "proto_var_decl";
+static const char ProtoVarDeclStmtName[] = "proto_var_decl_stmt";
+static const char ProtoAddFieldCallName[] = "proto_add_field";
 static const char LoopInitVarName[] = "loop_init_var";
 static const char LoopEndExprName[] = "loop_end_expr";
-
 static const char RangeLoopName[] = "for_range_loop";
 
 ast_matchers::internal::Matcher supportedContainerTypesMatcher() {
@@ -63,34 +74,35 @@ InefficientVectorOperationCheck::Ineffic
 StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   VectorLikeClasses(utils::options::parseStringList(
-  Options.get("VectorLikeClasses", "::std::vector"))) {}
+  Options.get("VectorLikeClasses", "::std::vector"))),
+  EnableProto(Options.getLocalOrGlobal("EnableProto", false)) {}
 
 void InefficientVectorOperationCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "VectorLikeClasses",
 utils::options::serializeStringList(VectorLikeClasses));
+  Options.store(Opts, "EnableProto", EnableProto);
 }
 
-void InefficientVectorOperationCheck::registerMatchers(MatchFinder *Finder) {
-  const auto VectorDecl = cxxRecordDecl(hasAnyName(SmallVector(
-  VectorLikeClasses.begin(), VectorLikeClasses.end(;
-  const auto VectorDefaultConstructorCall = cxxConstructExpr(
-  hasType(VectorDecl),
+void InefficientVectorOperationCheck::AddMatcher(
+const DeclarationMatcher &TargetRecordDecl, StringRef VarDeclName,
+StringRef VarDeclStmtName, const DeclarationMatcher &AppendMethodDecl,
+StringRef AppendCallName, MatchFinder *Finder) {
+  const auto DefaultConstructorCall = cxxConstructExpr(
+  hasType(TargetRecordDecl),
   hasDeclaration(cxxConstructorDecl(isDefaultConstructor(;
-  const auto VectorVarDecl =
-  varDecl(hasInitializer(VectorDefaultConstructorCall))
-  .bind(VectorVarDeclName);
-  const auto VectorAppendCallExpr =
-  cxxMemberCallExpr(
-  cal

[PATCH] D67358: [clangd] Implement semantic selections.

2019-09-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D67358#1670810 , @nridge wrote:

> Which LSP feature is this related to?


selectionRange:

- 
https://github.com/microsoft/vscode-languageserver-node/blob/master/protocol/src/protocol.selectionRange.ts
- https://github.com/microsoft/language-server-protocol/issues/613

It hasn't been published/released yet, but AIUI it will be soon. (Thus no 
mention of it being an extension everywhere).
I think @usaxena95 is working on a followup to add the LSP bindings.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67358/new/

https://reviews.llvm.org/D67358



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


[PATCH] D67135: [clang-tidy] performance-inefficient-vector-operation: Support proto repeated field

2019-09-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D67135#1669836 , @congliu wrote:

> Could someone commit this for me? I failed to commit this change...


Committed in rL371963 , just curious why you 
failed to commit? if you are using llvm git monorepo, 
`./llvm/utils/git-svn/git-llvm push` should work.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67135/new/

https://reviews.llvm.org/D67135



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


[PATCH] D67607: [clangd] Fix a crash when renaming operator.

2019-09-16 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

LGTM to fix the crash. See the comment about more cases that could potentially 
break, though. Do we handle them gracefully now?




Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:77
 return ReasonToReject::UnsupportedSymbol;
+  if (const auto *FD = llvm::dyn_cast(&RenameDecl)) {
+if (FD->isOverloadedOperator())

Should we more generally disable renaming all non-identifier names? Each of 
them seems to require special treatment.

A few examples that come to mind:
- conversion operators, e.g. `operator int()`;
- user-defined literals, e.g. `std::chrono::seconds operator ""s(int seconds)`;
- destructors;


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67607/new/

https://reviews.llvm.org/D67607



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


[PATCH] D67608: [ARM] Preserve fpu behaviour for '-crypto'

2019-09-16 Thread Diogo N. Sampaio via Phabricator via cfe-commits
dnsampaio created this revision.
dnsampaio added reviewers: peter.smith, labrinea.
Herald added subscribers: cfe-commits, dmgreen, kristof.beyls.
Herald added a project: clang.

This patch restores the behaviour that -fpu overwrites the
architecture obtained from -march or -mcpu flags, not enforcing to
disable 'crypto' if march=armv7 and mfpu=neon-fp-armv8.
However, it does warn that 'crypto' is ignored when passing
mfpu=crypto-neon-fp-armv8.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67608

Files:
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/test/Driver/arm-features.c


Index: clang/test/Driver/arm-features.c
===
--- clang/test/Driver/arm-features.c
+++ clang/test/Driver/arm-features.c
@@ -79,3 +79,18 @@
 // RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-m23+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO5 %s
 // CHECK-NOCRYPTO5: warning: ignoring extension 'crypto' because the {{.*}} 
architecture does not support it
 // CHECK-NOCRYPTO5-NOT: "-target-feature" "+crypto"{{.*}} "-target-feature" 
"+sha2" "-target-feature" "+aes"
+//
+// Check +crypto does not affect -march=armv7a -mfpu=crypto-neon-fp-armv8, but 
it does warn that +crypto has no effect
+// RUN: %clang -target arm-arm-none-eabi -march=armv7a 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefixes=CHECK-WARNONLY,ALL %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7a+aes 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefixes=CHECK-WARNONLY,ALL,CHECK-HASAES %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7a+sha2 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefixes=CHECK-WARNONLY,ALL,CHECK-HASSHA %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7a+sha2+aes 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefixes=CHECK-WARNONLY,ALL,CHECK-HASSHA,CHECK-HASAES %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7a+aes -mfpu=neon-fp-armv8 
-### -c %s 2>&1 | FileCheck -check-prefixes=ALL,CHECK-HASAES %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7a+sha2 
-mfpu=neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefixes=ALL,CHECK-HASSHA %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7a+sha2+aes 
-mfpu=neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefixes=ALL,CHECK-HASSHA,CHECK-HASAES %s
+// CHECK-WARNONLY: warning: ignoring extension 'crypto' because the 'armv7-a' 
architecture does not support it
+// ALL: "-target-feature"
+// CHECK-WARNONLY-NOT: "-target-feature" "-crypto"
+// CHECK-HASSHA-SAME:  "-target-feature" "+sha2"
+// CHECK-HASAES-SAME:  "-target-feature" "+aes"
+//
Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp
===
--- clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -496,7 +496,12 @@
 } else {
   D.Diag(clang::diag::warn_target_unsupported_extension)
 << "crypto" << 
llvm::ARM::getArchName(llvm::ARM::parseArch(ArchSuffix));
-  Features.push_back("-crypto");
+  //-mfpu=crypto-neon-fp-armv8 does allow +sha2 / +aes / +crypto features,
+  // even if compiling for an cpu armv7a, if explicitly defined by the 
user,
+  // so do not deactivate them.
+  if ((llvm::find(Features, "+fp-armv8") == Features.end()) ||
+  (llvm::find(Features, "+neon") == Features.end()))
+Features.push_back("-crypto");
 }
   }
 


Index: clang/test/Driver/arm-features.c
===
--- clang/test/Driver/arm-features.c
+++ clang/test/Driver/arm-features.c
@@ -79,3 +79,18 @@
 // RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-m23+crypto -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO5 %s
 // CHECK-NOCRYPTO5: warning: ignoring extension 'crypto' because the {{.*}} architecture does not support it
 // CHECK-NOCRYPTO5-NOT: "-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" "+aes"
+//
+// Check +crypto does not affect -march=armv7a -mfpu=crypto-neon-fp-armv8, but it does warn that +crypto has no effect
+// RUN: %clang -target arm-arm-none-eabi -march=armv7a -mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefixes=CHECK-WARNONLY,ALL %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7a+aes -mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefixes=CHECK-WARNONLY,ALL,CHECK-HASAES %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7a+sha2 -mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefixes=CHECK-WARNONLY,ALL,CHECK-HASSHA %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7a+sha2+aes -mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefixes=CHECK-WARNONLY,ALL,CHECK-HASSHA,CHECK-HASAES %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7a+aes -mfpu=neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefixes=ALL,CHECK-HASA

[PATCH] D66524: [SVE][Inline-Asm] Add constraints for SVE predicate registers

2019-09-16 Thread Diana Picus via Phabricator via cfe-commits
rovka accepted this revision.
rovka added a comment.
This revision is now accepted and ready to land.

I think all the outstanding comments have been addressed. LGTM.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66524/new/

https://reviews.llvm.org/D66524



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


[PATCH] D67606: Change signature of __builtin_rotateright64 back to unsigned

2019-09-16 Thread Karl-Johan Karlsson via Phabricator via cfe-commits
Ka-Ka updated this revision to Diff 220294.
Ka-Ka added a comment.
Herald added subscribers: Jim, dylanmckay.

Update testcases according to review comment.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67606/new/

https://reviews.llvm.org/D67606

Files:
  include/clang/Basic/Builtins.def
  test/CodeGen/avr-builtins.c


Index: test/CodeGen/avr-builtins.c
===
--- test/CodeGen/avr-builtins.c
+++ test/CodeGen/avr-builtins.c
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -triple avr-unknown-unknown -emit-llvm -o - %s | FileCheck 
%s
 
+// Check that the parameter types match.
+// RUN: %clang_cc1 -triple avr-unknown-unknown -Wconversion -verify %s
+// expected-no-diagnostics
+
 unsigned char bitrev8(unsigned char data) {
 return __builtin_bitreverse8(data);
 }
Index: include/clang/Basic/Builtins.def
===
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -461,7 +461,7 @@
 BUILTIN(__builtin_rotateright8, "UcUcUc", "nc")
 BUILTIN(__builtin_rotateright16, "UsUsUs", "nc")
 BUILTIN(__builtin_rotateright32, "UZiUZiUZi", "nc")
-BUILTIN(__builtin_rotateright64, "UWiUWiWi", "nc")
+BUILTIN(__builtin_rotateright64, "UWiUWiUWi", "nc")
 
 // Random GCC builtins
 BUILTIN(__builtin_constant_p, "i.", "nctu")


Index: test/CodeGen/avr-builtins.c
===
--- test/CodeGen/avr-builtins.c
+++ test/CodeGen/avr-builtins.c
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -triple avr-unknown-unknown -emit-llvm -o - %s | FileCheck %s
 
+// Check that the parameter types match.
+// RUN: %clang_cc1 -triple avr-unknown-unknown -Wconversion -verify %s
+// expected-no-diagnostics
+
 unsigned char bitrev8(unsigned char data) {
 return __builtin_bitreverse8(data);
 }
Index: include/clang/Basic/Builtins.def
===
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -461,7 +461,7 @@
 BUILTIN(__builtin_rotateright8, "UcUcUc", "nc")
 BUILTIN(__builtin_rotateright16, "UsUsUs", "nc")
 BUILTIN(__builtin_rotateright32, "UZiUZiUZi", "nc")
-BUILTIN(__builtin_rotateright64, "UWiUWiWi", "nc")
+BUILTIN(__builtin_rotateright64, "UWiUWiUWi", "nc")
 
 // Random GCC builtins
 BUILTIN(__builtin_constant_p, "i.", "nctu")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67467: [ARM] Update clang for removal of vfp2d16 and vfp2d16sp

2019-09-16 Thread Oliver Stannard (Linaro) via Phabricator via cfe-commits
ostannard accepted this revision.
ostannard added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: dmgreen.

LGTM


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67467/new/

https://reviews.llvm.org/D67467



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


[PATCH] D67606: Change signature of __builtin_rotateright64 back to unsigned

2019-09-16 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

Looks good to me! (with comment)




Comment at: test/CodeGen/avr-builtins.c:3
 
+// Check that the parameter types match.
+// RUN: %clang_cc1 -triple avr-unknown-unknown -Wconversion -verify %s

Sorry, I didn't put this in my example, but maybe also mention the Bug number 
here.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67606/new/

https://reviews.llvm.org/D67606



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


[PATCH] D67368: [NFCI]Create CommonAttributeInfo Type as base type of *Attr and ParsedAttr.

2019-09-16 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added a comment.

I would have definitely preferred a revert much earlier, I guess it's too late 
now, but not having a build is really inconvenient.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67368/new/

https://reviews.llvm.org/D67368



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


[clang-tools-extra] r371968 - Fix the rst doc, unbreak buildbot.

2019-09-16 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Sep 16 02:46:53 2019
New Revision: 371968

URL: http://llvm.org/viewvc/llvm-project?rev=371968&view=rev
Log:
Fix the rst doc, unbreak buildbot.

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-vector-operation.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-vector-operation.rst?rev=371968&r1=371967&r2=371968&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
 Mon Sep 16 02:46:53 2019
@@ -60,6 +60,7 @@ Options
``::std::vector`` is considered.
 
 .. option:: EnableProto
+
When non-zero, the check will also warn on inefficient operations for proto
repeated fields. Otherwise, the check only warns on inefficient vector
operations. Default is `0`.


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


[PATCH] D66524: [SVE][Inline-Asm] Add constraints for SVE predicate registers

2019-09-16 Thread Kerry McLaughlin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL371967: [SVE][Inline-Asm] Add constraints for SVE predicate 
registers (authored by kmclaughlin, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D66524?vs=219526&id=220299#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66524/new/

https://reviews.llvm.org/D66524

Files:
  llvm/trunk/docs/LangRef.rst
  llvm/trunk/lib/IR/InlineAsm.cpp
  llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp
  llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp
  llvm/trunk/test/CodeGen/AArch64/aarch64-sve-asm.ll

Index: llvm/trunk/lib/IR/InlineAsm.cpp
===
--- llvm/trunk/lib/IR/InlineAsm.cpp
+++ llvm/trunk/lib/IR/InlineAsm.cpp
@@ -181,6 +181,16 @@
   // FIXME: For now assuming these are 2-character constraints.
   pCodes->push_back(StringRef(I+1, 2));
   I += 3;
+} else if (*I == '@') {
+  // Multi-letter constraint
+  ++I;
+  unsigned char C = static_cast(*I);
+  assert(isdigit(C) && "Expected a digit!");
+  int N = C - '0';
+  assert(N > 0 && "Found a zero letter constraint!");
+  ++I;
+  pCodes->push_back(StringRef(I, N));
+  I += N;
 } else {
   // Single letter constraint.
   pCodes->push_back(StringRef(I, 1));
Index: llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp
===
--- llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -618,6 +618,8 @@
 const TargetRegisterClass *RegClass;
 if (AArch64::ZPRRegClass.contains(Reg)) {
   RegClass = &AArch64::ZPRRegClass;
+} else if (AArch64::PPRRegClass.contains(Reg)) {
+  RegClass = &AArch64::PPRRegClass;
 } else {
   RegClass = &AArch64::FPR128RegClass;
   AltName = AArch64::vreg;
Index: llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp
===
--- llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -2507,6 +2507,17 @@
 return;
   }
 
+  // Copy a Predicate register by ORRing with itself.
+  if (AArch64::PPRRegClass.contains(DestReg) &&
+  AArch64::PPRRegClass.contains(SrcReg)) {
+assert(Subtarget.hasSVE() && "Unexpected SVE register.");
+BuildMI(MBB, I, DL, get(AArch64::ORR_PPzPP), DestReg)
+  .addReg(SrcReg) // Pg
+  .addReg(SrcReg)
+  .addReg(SrcReg, getKillRegState(KillSrc));
+return;
+  }
+
   // Copy a Z register by ORRing with itself.
   if (AArch64::ZPRRegClass.contains(DestReg) &&
   AArch64::ZPRRegClass.contains(SrcReg)) {
Index: llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp
===
--- llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/trunk/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -5837,6 +5837,21 @@
   return "r";
 }
 
+enum PredicateConstraint {
+  Upl,
+  Upa,
+  Invalid
+};
+
+PredicateConstraint parsePredicateConstraint(StringRef Constraint) {
+  PredicateConstraint P = PredicateConstraint::Invalid;
+  if (Constraint == "Upa")
+P = PredicateConstraint::Upa;
+  if (Constraint == "Upl")
+P = PredicateConstraint::Upl;
+  return P;
+}
+
 /// getConstraintType - Given a constraint letter, return the type of
 /// constraint it is for this target.
 AArch64TargetLowering::ConstraintType
@@ -5866,7 +5881,9 @@
 case 'S': // A symbolic address
   return C_Other;
 }
-  }
+  } else if (parsePredicateConstraint(Constraint) !=
+ PredicateConstraint::Invalid)
+  return C_RegisterClass;
   return TargetLowering::getConstraintType(Constraint);
 }
 
@@ -5897,6 +5914,10 @@
   case 'z':
 weight = CW_Constant;
 break;
+  case 'U':
+if (parsePredicateConstraint(constraint) != PredicateConstraint::Invalid)
+  weight = CW_Register;
+break;
   }
   return weight;
 }
@@ -5941,6 +5962,14 @@
 return std::make_pair(0U, &AArch64::ZPR_3bRegClass);
   break;
 }
+  } else {
+PredicateConstraint PC = parsePredicateConstraint(Constraint);
+if (PC != PredicateConstraint::Invalid) {
+  assert(VT.isScalableVector());
+  bool restricted = (PC == PredicateConstraint::Upl);
+  return restricted ? std::make_pair(0U, &AArch64::PPR_3bRegClass)
+  : std::make_pair(0U, &AArch64::PPRRegClass);
+}
   }
   if (StringRef("{cc}").equals_lower(Constraint))
 return std::make_pair(unsigned(AArch64::NZCV), &AArch64::CCRRegClass);
Index: llvm/trunk/docs/LangRef.rst
===
--- llvm/trunk/docs/LangRef.rst
+++ llvm/trunk/docs/LangRef.rst
@@ -3825,6 +3825,8 @@
 - ``w``: A 32, 64, or 128-bit floating-point, SIMD or SVE vector registe

r371969 - Change signature of __builtin_rotateright64 back to unsigned

2019-09-16 Thread Karl-Johan Karlsson via cfe-commits
Author: karka
Date: Mon Sep 16 02:52:23 2019
New Revision: 371969

URL: http://llvm.org/viewvc/llvm-project?rev=371969&view=rev
Log:
Change signature of __builtin_rotateright64 back to unsigned

The signature of __builtin_rotateright64 was by misstake changed from
unsigned to signed in r360863, this patch will change it back to
unsigned as intended.

This fixes pr43309

Reviewers: efriedma, hans

Reviewed By: hans

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

Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/test/CodeGen/avr-builtins.c

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=371969&r1=371968&r2=371969&view=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Mon Sep 16 02:52:23 2019
@@ -461,7 +461,7 @@ BUILTIN(__builtin_rotateleft64, "UWiUWiU
 BUILTIN(__builtin_rotateright8, "UcUcUc", "nc")
 BUILTIN(__builtin_rotateright16, "UsUsUs", "nc")
 BUILTIN(__builtin_rotateright32, "UZiUZiUZi", "nc")
-BUILTIN(__builtin_rotateright64, "UWiUWiWi", "nc")
+BUILTIN(__builtin_rotateright64, "UWiUWiUWi", "nc")
 
 // Random GCC builtins
 BUILTIN(__builtin_constant_p, "i.", "nctu")

Modified: cfe/trunk/test/CodeGen/avr-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avr-builtins.c?rev=371969&r1=371968&r2=371969&view=diff
==
--- cfe/trunk/test/CodeGen/avr-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avr-builtins.c Mon Sep 16 02:52:23 2019
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -triple avr-unknown-unknown -emit-llvm -o - %s | FileCheck 
%s
 
+// Check that the parameter types match. This verifies pr43309.
+// RUN: %clang_cc1 -triple avr-unknown-unknown -Wconversion -verify %s
+// expected-no-diagnostics
+
 unsigned char bitrev8(unsigned char data) {
 return __builtin_bitreverse8(data);
 }


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


[PATCH] D67606: Change signature of __builtin_rotateright64 back to unsigned

2019-09-16 Thread Karl-Johan Karlsson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL371969: Change signature of __builtin_rotateright64 back to 
unsigned (authored by karka, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67606?vs=220294&id=220300#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67606/new/

https://reviews.llvm.org/D67606

Files:
  cfe/trunk/include/clang/Basic/Builtins.def
  cfe/trunk/test/CodeGen/avr-builtins.c


Index: cfe/trunk/include/clang/Basic/Builtins.def
===
--- cfe/trunk/include/clang/Basic/Builtins.def
+++ cfe/trunk/include/clang/Basic/Builtins.def
@@ -461,7 +461,7 @@
 BUILTIN(__builtin_rotateright8, "UcUcUc", "nc")
 BUILTIN(__builtin_rotateright16, "UsUsUs", "nc")
 BUILTIN(__builtin_rotateright32, "UZiUZiUZi", "nc")
-BUILTIN(__builtin_rotateright64, "UWiUWiWi", "nc")
+BUILTIN(__builtin_rotateright64, "UWiUWiUWi", "nc")
 
 // Random GCC builtins
 BUILTIN(__builtin_constant_p, "i.", "nctu")
Index: cfe/trunk/test/CodeGen/avr-builtins.c
===
--- cfe/trunk/test/CodeGen/avr-builtins.c
+++ cfe/trunk/test/CodeGen/avr-builtins.c
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -triple avr-unknown-unknown -emit-llvm -o - %s | FileCheck 
%s
 
+// Check that the parameter types match. This verifies pr43309.
+// RUN: %clang_cc1 -triple avr-unknown-unknown -Wconversion -verify %s
+// expected-no-diagnostics
+
 unsigned char bitrev8(unsigned char data) {
 return __builtin_bitreverse8(data);
 }


Index: cfe/trunk/include/clang/Basic/Builtins.def
===
--- cfe/trunk/include/clang/Basic/Builtins.def
+++ cfe/trunk/include/clang/Basic/Builtins.def
@@ -461,7 +461,7 @@
 BUILTIN(__builtin_rotateright8, "UcUcUc", "nc")
 BUILTIN(__builtin_rotateright16, "UsUsUs", "nc")
 BUILTIN(__builtin_rotateright32, "UZiUZiUZi", "nc")
-BUILTIN(__builtin_rotateright64, "UWiUWiWi", "nc")
+BUILTIN(__builtin_rotateright64, "UWiUWiUWi", "nc")
 
 // Random GCC builtins
 BUILTIN(__builtin_constant_p, "i.", "nctu")
Index: cfe/trunk/test/CodeGen/avr-builtins.c
===
--- cfe/trunk/test/CodeGen/avr-builtins.c
+++ cfe/trunk/test/CodeGen/avr-builtins.c
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -triple avr-unknown-unknown -emit-llvm -o - %s | FileCheck %s
 
+// Check that the parameter types match. This verifies pr43309.
+// RUN: %clang_cc1 -triple avr-unknown-unknown -Wconversion -verify %s
+// expected-no-diagnostics
+
 unsigned char bitrev8(unsigned char data) {
 return __builtin_bitreverse8(data);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67607: [clangd] Fix a crash when renaming operator.

2019-09-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein marked 2 inline comments as done.
hokein added inline comments.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:77
 return ReasonToReject::UnsupportedSymbol;
+  if (const auto *FD = llvm::dyn_cast(&RenameDecl)) {
+if (FD->isOverloadedOperator())

ilya-biryukov wrote:
> Should we more generally disable renaming all non-identifier names? Each of 
> them seems to require special treatment.
> 
> A few examples that come to mind:
> - conversion operators, e.g. `operator int()`;
> - user-defined literals, e.g. `std::chrono::seconds operator ""s(int 
> seconds)`;
> - destructors;
I think so, that would be safer (this should be done in a separate patch), it 
seems that some cases are being handled by the rename library already.

- for constructor and destructor, the renamelib handle them well;
- for `operator int()`/user-defined literals, the renamelib doesn't find a 
corresponding decl, means that we will return "no symbol found error", though 
the message is a bit confusing;


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67607/new/

https://reviews.llvm.org/D67607



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


[clang-tools-extra] r371971 - [clangd] Fix a crash when renaming operator.

2019-09-16 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Sep 16 03:16:56 2019
New Revision: 371971

URL: http://llvm.org/viewvc/llvm-project?rev=371971&view=rev
Log:
[clangd] Fix a crash when renaming operator.

Summary:
The renamelib uses a tricky way to calculate the end location by relying
on decl name, this is incorrect for the overloaded operator (the name is
"operator++" instead of "++"), which will cause out-of-file offset.

We also disable renaming operator symbol, this case is tricky, and
renamelib doesnt handle it properly.

Reviewers: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/refactor/Rename.cpp
clang-tools-extra/trunk/clangd/unittests/RenameTests.cpp

Modified: clang-tools-extra/trunk/clangd/refactor/Rename.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/refactor/Rename.cpp?rev=371971&r1=371970&r2=371971&view=diff
==
--- clang-tools-extra/trunk/clangd/refactor/Rename.cpp (original)
+++ clang-tools-extra/trunk/clangd/refactor/Rename.cpp Mon Sep 16 03:16:56 2019
@@ -74,6 +74,10 @@ llvm::Optional renamable
const SymbolIndex *Index) {
   if (llvm::isa(&RenameDecl))
 return ReasonToReject::UnsupportedSymbol;
+  if (const auto *FD = llvm::dyn_cast(&RenameDecl)) {
+if (FD->isOverloadedOperator())
+  return ReasonToReject::UnsupportedSymbol;
+  }
   auto &ASTCtx = RenameDecl.getASTContext();
   const auto &SM = ASTCtx.getSourceManager();
   bool MainFileIsHeader = ASTCtx.getLangOpts().IsHeaderFile;

Modified: clang-tools-extra/trunk/clangd/unittests/RenameTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/RenameTests.cpp?rev=371971&r1=371970&r2=371971&view=diff
==
--- clang-tools-extra/trunk/clangd/unittests/RenameTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/RenameTests.cpp Mon Sep 16 
03:16:56 2019
@@ -136,6 +136,13 @@ TEST(RenameTest, Renameable) {
)cpp",
   "not a supported kind", HeaderFile},
 
+  {
+
+  R"cpp(
+struct X { X operator++(int) {} };
+void f(X x) {x+^+;})cpp",
+  "not a supported kind", HeaderFile},
+
   {R"cpp(// foo is declared outside the file.
 void fo^o() {}
   )cpp", "used outside main file", !HeaderFile/*cc file*/},


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


r371971 - [clangd] Fix a crash when renaming operator.

2019-09-16 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Sep 16 03:16:56 2019
New Revision: 371971

URL: http://llvm.org/viewvc/llvm-project?rev=371971&view=rev
Log:
[clangd] Fix a crash when renaming operator.

Summary:
The renamelib uses a tricky way to calculate the end location by relying
on decl name, this is incorrect for the overloaded operator (the name is
"operator++" instead of "++"), which will cause out-of-file offset.

We also disable renaming operator symbol, this case is tricky, and
renamelib doesnt handle it properly.

Reviewers: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h

Modified: cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h?rev=371971&r1=371970&r2=371971&view=diff
==
--- cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h 
(original)
+++ cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h Mon 
Sep 16 03:16:56 2019
@@ -122,8 +122,7 @@ private:
 ND, SourceRange(BeginLoc, EndLoc));
   }
   bool visit(const NamedDecl *ND, SourceLocation Loc) {
-return visit(ND, Loc,
- Loc.getLocWithOffset(ND->getNameAsString().length() - 1));
+return visit(ND, Loc, Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts));
   }
 };
 


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


[PATCH] D67607: [clangd] Fix a crash when renaming operator.

2019-09-16 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rGaf28bb65023e: [clangd] Fix a crash when renaming operator. 
(authored by hokein).
Herald added a subscriber: usaxena95.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67607/new/

https://reviews.llvm.org/D67607

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h


Index: clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
===
--- clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
+++ clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
@@ -122,8 +122,7 @@
 ND, SourceRange(BeginLoc, EndLoc));
   }
   bool visit(const NamedDecl *ND, SourceLocation Loc) {
-return visit(ND, Loc,
- Loc.getLocWithOffset(ND->getNameAsString().length() - 1));
+return visit(ND, Loc, Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts));
   }
 };
 
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -136,6 +136,13 @@
)cpp",
   "not a supported kind", HeaderFile},
 
+  {
+
+  R"cpp(
+struct X { X operator++(int) {} };
+void f(X x) {x+^+;})cpp",
+  "not a supported kind", HeaderFile},
+
   {R"cpp(// foo is declared outside the file.
 void fo^o() {}
   )cpp", "used outside main file", !HeaderFile/*cc file*/},
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -74,6 +74,10 @@
const SymbolIndex *Index) {
   if (llvm::isa(&RenameDecl))
 return ReasonToReject::UnsupportedSymbol;
+  if (const auto *FD = llvm::dyn_cast(&RenameDecl)) {
+if (FD->isOverloadedOperator())
+  return ReasonToReject::UnsupportedSymbol;
+  }
   auto &ASTCtx = RenameDecl.getASTContext();
   const auto &SM = ASTCtx.getSourceManager();
   bool MainFileIsHeader = ASTCtx.getLangOpts().IsHeaderFile;


Index: clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
===
--- clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
+++ clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
@@ -122,8 +122,7 @@
 ND, SourceRange(BeginLoc, EndLoc));
   }
   bool visit(const NamedDecl *ND, SourceLocation Loc) {
-return visit(ND, Loc,
- Loc.getLocWithOffset(ND->getNameAsString().length() - 1));
+return visit(ND, Loc, Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts));
   }
 };
 
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -136,6 +136,13 @@
)cpp",
   "not a supported kind", HeaderFile},
 
+  {
+
+  R"cpp(
+struct X { X operator++(int) {} };
+void f(X x) {x+^+;})cpp",
+  "not a supported kind", HeaderFile},
+
   {R"cpp(// foo is declared outside the file.
 void fo^o() {}
   )cpp", "used outside main file", !HeaderFile/*cc file*/},
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -74,6 +74,10 @@
const SymbolIndex *Index) {
   if (llvm::isa(&RenameDecl))
 return ReasonToReject::UnsupportedSymbol;
+  if (const auto *FD = llvm::dyn_cast(&RenameDecl)) {
+if (FD->isOverloadedOperator())
+  return ReasonToReject::UnsupportedSymbol;
+  }
   auto &ASTCtx = RenameDecl.getASTContext();
   const auto &SM = ASTCtx.getSourceManager();
   bool MainFileIsHeader = ASTCtx.getLangOpts().IsHeaderFile;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67358: [clangd] Implement semantic selections.

2019-09-16 Thread UTKARSH SAXENA via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 220303.
usaxena95 marked 3 inline comments as done.
usaxena95 added a comment.

Resolved comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67358/new/

https://reviews.llvm.org/D67358

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/SemanticSelection.cpp
  clang-tools-extra/clangd/SemanticSelection.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
@@ -0,0 +1,143 @@
+//===-- SemanticSelectionTests.cpp  *- C++ -*--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Annotations.h"
+#include "Matchers.h"
+#include "Protocol.h"
+#include "SemanticSelection.h"
+#include "SourceCode.h"
+#include "TestTU.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "llvm/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+namespace clang {
+namespace clangd {
+namespace {
+using ::testing::ElementsAreArray;
+
+TEST(SemanticSelection, All) {
+  const char *Tests[] = {
+  R"cpp( // Single statement in a function body.
+[[void func() [[{
+  int v = [[1^00;]]
+}
+  )cpp",
+  R"cpp( // Expression
+[[void func() [[{
+  int a = 1;
+  // int v = (10 + 2) * (a + a);
+  int v = (10^]] + 2]])]] * (a + a);]]
+}
+  )cpp",
+  R"cpp( // Function call.
+int add(int x, int y) { return x + y; }
+[[void callee() [[{
+  // int res = add(11, 22);
+  int res = [[add([[1^1]], 22);]]
+}
+  )cpp",
+  R"cpp( // Tricky macros.
+#define MUL ) * (
+[[void func() [[{
+  // int var = (4 + 15 MUL 6 + 10);
+  int var = ([[4 + [[1^5 MUL]] 6 + 10);]]
+}
+   )cpp",
+  R"cpp( // Cursor inside a macro.
+#define HASH(x) ((x) % 10)
+[[void func() [[{
+  int a = [[HASH(2^3]] + 34]]);]]
+}
+   )cpp",
+  R"cpp( // Cursor on a macro.
+#define HASH(x) ((x) % 10)
+[[void func() [[{
+  int a = [[HA^SH(23);]]
+}
+   )cpp",
+  R"cpp( // Multiple declaration.
+[[void func() [[{
+  int var1, var^2]], var3;]]
+}
+   )cpp",
+  R"cpp( // Before comment.
+[[void func() [[{
+  int var1 = 1;
+  int var2 = var1]]^ /*some comment*/ + 41;]]
+}
+   )cpp",
+  // Empty file.
+  "^",
+  // FIXME: We should get the whole DeclStmt as a range.
+  R"cpp( // Single statement in TU.
+[[int v = [[1^00;
+  )cpp",
+  // FIXME: No node found associated to the position.
+  R"cpp( // Cursor at end of VarDecl.
+void func() {
+  int v = 100 + 100^;
+}
+  )cpp",
+  // FIXME: No node found associated to the position.
+  R"cpp( // Cursor in between spaces.
+void func() {
+  int v = 100 + ^  100;
+}
+  )cpp",
+  // Structs.
+  R"cpp(
+struct AAA { struct BBB { static int ccc(); };};
+[[void func() [[{
+  // int x = AAA::BBB::ccc();
+  int x = AAA::BBB::c^cc]]();]]
+}
+  )cpp",
+  R"cpp(
+struct AAA { struct BBB { static int ccc(); };};
+[[void func() [[{
+  // int x = AAA::BBB::ccc();
+  int x = [[AA^A]]::]]BBB::]]ccc]]();]]
+}
+  )cpp",
+  R"cpp( // Inside struct.
+struct A { static int a(); };
+[[struct B { 
+  [[static int b() [[{
+[[return 1^1]] + 2;
+  }
+}]];
+  )cpp",
+  // Namespaces.
+  R"cpp( 
+[[namespace nsa { 
+  [[namespace nsb { 
+static int ccc();
+[[void func() [[{
+  // int x = nsa::nsb::ccc();
+  int x = nsa::nsb::cc^c]]();]]
+}
+  }]]
+}]]
+  )cpp",
+
+  };
+
+  for (const char *Test : Tests) {
+auto T = Annotations(Test);
+auto AST = TestTU::withCode(T.code()).build();
+EXPECT_THAT(llvm::cantFail(getSemanticRanges(AST, T.point())),
+ElementsAreArray(T.ranges()))
+<< Test;
+  }
+}
+} // namespace
+} // namespace clangd
+} // namespace cl

[PATCH] D66716: [analyzer] PR43102: Fix an assertion and an out-of-bounds error for diagnostic location construction

2019-09-16 Thread Tom Weaver via Phabricator via cfe-commits
TWeaver added a comment.

Hi there,

just checking in, is this patch still going ahead?

thanks
Tom W


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66716/new/

https://reviews.llvm.org/D66716



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


[PATCH] D67358: [clangd] Implement semantic selections.

2019-09-16 Thread UTKARSH SAXENA via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL371976: Implement semantic selections. (authored by 
usaxena95, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67358?vs=220303&id=220307#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67358/new/

https://reviews.llvm.org/D67358

Files:
  clang-tools-extra/trunk/clangd/CMakeLists.txt
  clang-tools-extra/trunk/clangd/SemanticSelection.cpp
  clang-tools-extra/trunk/clangd/SemanticSelection.h
  clang-tools-extra/trunk/clangd/unittests/CMakeLists.txt
  clang-tools-extra/trunk/clangd/unittests/SemanticSelectionTests.cpp

Index: clang-tools-extra/trunk/clangd/CMakeLists.txt
===
--- clang-tools-extra/trunk/clangd/CMakeLists.txt
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt
@@ -66,6 +66,7 @@
   RIFF.cpp
   Selection.cpp
   SemanticHighlighting.cpp
+  SemanticSelection.cpp
   SourceCode.cpp
   QueryDriverDatabase.cpp
   Threading.cpp
Index: clang-tools-extra/trunk/clangd/SemanticSelection.cpp
===
--- clang-tools-extra/trunk/clangd/SemanticSelection.cpp
+++ clang-tools-extra/trunk/clangd/SemanticSelection.cpp
@@ -0,0 +1,64 @@
+//===--- SemanticSelection.cpp ---*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "SemanticSelection.h"
+#include "ParsedAST.h"
+#include "Protocol.h"
+#include "Selection.h"
+#include "SourceCode.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/Support/Error.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+// Adds Range \p R to the Result if it is distinct from the last added Range.
+// Assumes that only consecutive ranges can coincide.
+void addIfDistinct(const Range &R, std::vector &Result) {
+  if (Result.empty() || Result.back() != R) {
+Result.push_back(R);
+  }
+}
+} // namespace
+
+llvm::Expected> getSemanticRanges(ParsedAST &AST,
+ Position Pos) {
+  std::vector Result;
+  const auto &SM = AST.getSourceManager();
+  const auto &LangOpts = AST.getASTContext().getLangOpts();
+
+  auto FID = SM.getMainFileID();
+  auto Offset = positionToOffset(SM.getBufferData(FID), Pos);
+  if (!Offset) {
+return Offset.takeError();
+  }
+
+  // Get node under the cursor.
+  SelectionTree ST(AST.getASTContext(), AST.getTokens(), *Offset);
+  for (const auto *Node = ST.commonAncestor(); Node != nullptr;
+   Node = Node->Parent) {
+if (const Decl *D = Node->ASTNode.get()) {
+  if (llvm::isa(D)) {
+break;
+  }
+}
+
+auto SR = toHalfOpenFileRange(SM, LangOpts, Node->ASTNode.getSourceRange());
+if (!SR.hasValue() || SM.getFileID(SR->getBegin()) != SM.getMainFileID()) {
+  continue;
+}
+Range R;
+R.start = sourceLocToPosition(SM, SR->getBegin());
+R.end = sourceLocToPosition(SM, SR->getEnd());
+addIfDistinct(R, Result);
+  }
+  return Result;
+}
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/trunk/clangd/SemanticSelection.h
===
--- clang-tools-extra/trunk/clangd/SemanticSelection.h
+++ clang-tools-extra/trunk/clangd/SemanticSelection.h
@@ -0,0 +1,32 @@
+//===--- SemanticSelection.h -*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Features for giving interesting semantic ranges around the cursor.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICSELECTION_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICSELECTION_H
+#include "ParsedAST.h"
+#include "Protocol.h"
+#include "llvm/Support/Error.h"
+#include 
+namespace clang {
+namespace clangd {
+
+/// Returns the list of all interesting ranges around the Position \p Pos.
+/// The interesting ranges corresponds to the AST nodes in the SelectionTree
+/// containing \p Pos.
+/// Any range in the result strictly contains all the previous ranges in the
+/// result. front() is the inner most range. back() is the outermost range.
+llvm::Expected> getSemanticRanges(ParsedAST &AST,
+ Position Pos);
+} // namespace clangd
+} // namespace

[clang-tools-extra] r371976 - Implement semantic selections.

2019-09-16 Thread Utkarsh Saxena via cfe-commits
Author: usaxena95
Date: Mon Sep 16 04:29:35 2019
New Revision: 371976

URL: http://llvm.org/viewvc/llvm-project?rev=371976&view=rev
Log:
Implement semantic selections.

Summary:
For a given cursor position, it returns ranges that are interesting to the user.
Currently the semantic ranges correspond to the nodes of the syntax trees.

Subscribers: mgorny, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Added:
clang-tools-extra/trunk/clangd/SemanticSelection.cpp
clang-tools-extra/trunk/clangd/SemanticSelection.h
clang-tools-extra/trunk/clangd/unittests/SemanticSelectionTests.cpp
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/unittests/CMakeLists.txt

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=371976&r1=371975&r2=371976&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Mon Sep 16 04:29:35 2019
@@ -66,6 +66,7 @@ add_clang_library(clangDaemon
   RIFF.cpp
   Selection.cpp
   SemanticHighlighting.cpp
+  SemanticSelection.cpp
   SourceCode.cpp
   QueryDriverDatabase.cpp
   Threading.cpp

Added: clang-tools-extra/trunk/clangd/SemanticSelection.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticSelection.cpp?rev=371976&view=auto
==
--- clang-tools-extra/trunk/clangd/SemanticSelection.cpp (added)
+++ clang-tools-extra/trunk/clangd/SemanticSelection.cpp Mon Sep 16 04:29:35 
2019
@@ -0,0 +1,64 @@
+//===--- SemanticSelection.cpp ---*- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "SemanticSelection.h"
+#include "ParsedAST.h"
+#include "Protocol.h"
+#include "Selection.h"
+#include "SourceCode.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/Support/Error.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+// Adds Range \p R to the Result if it is distinct from the last added Range.
+// Assumes that only consecutive ranges can coincide.
+void addIfDistinct(const Range &R, std::vector &Result) {
+  if (Result.empty() || Result.back() != R) {
+Result.push_back(R);
+  }
+}
+} // namespace
+
+llvm::Expected> getSemanticRanges(ParsedAST &AST,
+ Position Pos) {
+  std::vector Result;
+  const auto &SM = AST.getSourceManager();
+  const auto &LangOpts = AST.getASTContext().getLangOpts();
+
+  auto FID = SM.getMainFileID();
+  auto Offset = positionToOffset(SM.getBufferData(FID), Pos);
+  if (!Offset) {
+return Offset.takeError();
+  }
+
+  // Get node under the cursor.
+  SelectionTree ST(AST.getASTContext(), AST.getTokens(), *Offset);
+  for (const auto *Node = ST.commonAncestor(); Node != nullptr;
+   Node = Node->Parent) {
+if (const Decl *D = Node->ASTNode.get()) {
+  if (llvm::isa(D)) {
+break;
+  }
+}
+
+auto SR = toHalfOpenFileRange(SM, LangOpts, 
Node->ASTNode.getSourceRange());
+if (!SR.hasValue() || SM.getFileID(SR->getBegin()) != SM.getMainFileID()) {
+  continue;
+}
+Range R;
+R.start = sourceLocToPosition(SM, SR->getBegin());
+R.end = sourceLocToPosition(SM, SR->getEnd());
+addIfDistinct(R, Result);
+  }
+  return Result;
+}
+
+} // namespace clangd
+} // namespace clang

Added: clang-tools-extra/trunk/clangd/SemanticSelection.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticSelection.h?rev=371976&view=auto
==
--- clang-tools-extra/trunk/clangd/SemanticSelection.h (added)
+++ clang-tools-extra/trunk/clangd/SemanticSelection.h Mon Sep 16 04:29:35 2019
@@ -0,0 +1,32 @@
+//===--- SemanticSelection.h -*- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Features for giving interesting semantic ranges around the cursor.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICSELECTION_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICSELECTION_H
+#include "ParsedAST.h"
+#include "Protocol.h"
+#in

[PATCH] D67613: [DWARF-5] Support for DWARF-5 C++ language tags

2019-09-16 Thread Sourabh Singh Tomar via Phabricator via cfe-commits
SouraVX created this revision.
SouraVX added reviewers: aprantl, dblaikie.
SouraVX added a project: debug-info.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch provides support for DW_LANG_C_plus_plus_11, DW_LANG_C_plus_plus_14 
tags in clang C++ frontend.


Repository:
  rC Clang

https://reviews.llvm.org/D67613

Files:
  include/clang/AST/DeclCXX.h
  lib/AST/DeclPrinter.cpp
  lib/AST/JSONNodeDumper.cpp
  lib/AST/TextNodeDumper.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaModule.cpp
  test/Modules/ModuleDebugInfo.cpp

Index: test/Modules/ModuleDebugInfo.cpp
===
--- test/Modules/ModuleDebugInfo.cpp
+++ test/Modules/ModuleDebugInfo.cpp
@@ -12,7 +12,7 @@
 
 // PCH:
 // RUN: %clang_cc1 -triple %itanium_abi_triple -x c++ -std=c++11  -debugger-tuning=lldb -emit-pch -fmodule-format=obj -I %S/Inputs -o %t.pch %S/Inputs/DebugCXX.h -mllvm -debug-only=pchcontainer &>%t-pch.ll
-// RUN: cat %t-pch.ll | FileCheck %s
+// RUN: cat %t-pch.ll | FileCheck --check-prefix=CHECK-CXX %s
 // RUN: cat %t-pch.ll | FileCheck --check-prefix=CHECK-NEG %s
 
 #ifdef MODULES
@@ -23,6 +23,7 @@
 // CHECK-MOD: distinct !DICompileUnit(language: DW_LANG_{{.*}}C_plus_plus,
 
 // CHECK: distinct !DICompileUnit(language: DW_LANG_{{.*}}C_plus_plus,
+// CHECK-CXX: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_11,
 // CHECK-SAME:isOptimized: false,
 // CHECK-NOT: splitDebugFilename:
 // CHECK-SAME:dwoId:
Index: lib/Sema/SemaModule.cpp
===
--- lib/Sema/SemaModule.cpp
+++ lib/Sema/SemaModule.cpp
@@ -31,6 +31,8 @@
 ExternCLoc = LSD->getBeginLoc();
   break;
 case LinkageSpecDecl::lang_cxx:
+case LinkageSpecDecl::lang_cxx_11:
+case LinkageSpecDecl::lang_cxx_14:
   break;
 }
 DC = LSD->getParent();
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -13911,6 +13911,10 @@
 Language = LinkageSpecDecl::lang_c;
   else if (Lang == "C++")
 Language = LinkageSpecDecl::lang_cxx;
+  else if (Lang == "C++11")
+Language = LinkageSpecDecl::lang_cxx_11;
+  else if (Lang == "C++14")
+Language = LinkageSpecDecl::lang_cxx_14;
   else {
 Diag(LangStr->getExprLoc(), diag::err_language_linkage_spec_unknown)
   << LangStr->getSourceRange();
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -5132,7 +5132,9 @@
 // EmitLinkageSpec - Emit all declarations in a linkage spec.
 void CodeGenModule::EmitLinkageSpec(const LinkageSpecDecl *LSD) {
   if (LSD->getLanguage() != LinkageSpecDecl::lang_c &&
-  LSD->getLanguage() != LinkageSpecDecl::lang_cxx) {
+  LSD->getLanguage() != LinkageSpecDecl::lang_cxx &&
+  LSD->getLanguage() != LinkageSpecDecl::lang_cxx_11 &&
+  LSD->getLanguage() != LinkageSpecDecl::lang_cxx_14) {
 ErrorUnsupported(LSD, "linkage spec");
 return;
   }
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -561,6 +561,10 @@
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
+else if (LO.CPlusPlus14)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
+else if (LO.CPlusPlus11)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
 else
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
   } else if (LO.ObjC) {
@@ -878,6 +882,8 @@
 static bool hasCXXMangling(const TagDecl *TD, llvm::DICompileUnit *TheCU) {
   switch (TheCU->getSourceLanguage()) {
   case llvm::dwarf::DW_LANG_C_plus_plus:
+  case llvm::dwarf::DW_LANG_C_plus_plus_11:
+  case llvm::dwarf::DW_LANG_C_plus_plus_14:
 return true;
   case llvm::dwarf::DW_LANG_ObjC_plus_plus:
 return isa(TD) || isa(TD);
Index: lib/AST/TextNodeDumper.cpp
===
--- lib/AST/TextNodeDumper.cpp
+++ lib/AST/TextNodeDumper.cpp
@@ -1767,6 +1767,12 @@
   case LinkageSpecDecl::lang_cxx:
 OS << " C++";
 break;
+  case LinkageSpecDecl::lang_cxx_11:
+OS << " C++11";
+break;
+  case LinkageSpecDecl::lang_cxx_14:
+OS << " C++14";
+break;
   }
 }
 
Index: lib/AST/JSONNodeDumper.cpp
===
--- lib/AST/JSONNodeDumper.cpp
+++ lib/AST/JSONNodeDumper.cpp
@@ -850,6 +850,12 @@
   switch (LSD->getLanguage()) {
   case LinkageSpecDecl::lang_c: Lang = "C"; break;
   case LinkageSpecDecl::lang_cxx: Lang = "C++"; break;
+  case LinkageSpecDecl::lang_cxx_11:
+Lang = "C++_11";
+break;
+  case LinkageSpecDecl::lang_cxx_14:

[PATCH] D66716: [analyzer] PR43102: Fix an assertion and an out-of-bounds error for diagnostic location construction

2019-09-16 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D66716#1671105 , @TWeaver wrote:

> Hi there,
>
> just checking in, is this patch still going ahead?
>
> thanks
>  Tom W


Unfortunately, it seems like the correct solution is a bit more complex than 
these if branches, so it might take just a bit longer, but I'm definitely on 
it! I'm also talking to folks behind to scenes to catch up with how loop 
widening works.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66716/new/

https://reviews.llvm.org/D66716



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


[PATCH] D66716: [analyzer] PR43102: Fix an assertion and an out-of-bounds error for diagnostic location construction

2019-09-16 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

While we're there, could you please see whether the included test case (note 
how condition tracking is turned off) fails on your platform without the rest 
of the patch applied (it definitely does on mine, which is why I was surprised 
to see this bug report pop up only now)? If not, I can just push a small commit 
with the `llvm::isa_and_nonnull` change to get some breathing room.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66716/new/

https://reviews.llvm.org/D66716



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


[clang-tools-extra] r371980 - [clangd] Bump vscode-clangd v0.0.17

2019-09-16 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Sep 16 05:51:07 2019
New Revision: 371980

URL: http://llvm.org/viewvc/llvm-project?rev=371980&view=rev
Log:
[clangd] Bump vscode-clangd v0.0.17

CHANGELOG:
- added semantic highlighting support (under the clangd.semanticHighlighting
  flag);
- better error message when clangd fails to execute refactoring-like
  actions;
- improved the readme doc;

Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json?rev=371980&r1=371979&r2=371980&view=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json (original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json Mon Sep 
16 05:51:07 2019
@@ -2,7 +2,7 @@
 "name": "vscode-clangd",
 "displayName": "vscode-clangd",
 "description": "Clang Language Server",
-"version": "0.0.16",
+"version": "0.0.17",
 "publisher": "llvm-vs-code-extensions",
 "homepage": "https://clang.llvm.org/extra/clangd.html";,
 "engines": {


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


[PATCH] D67368: [NFCI]Create CommonAttributeInfo Type as base type of *Attr and ParsedAttr.

2019-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked an inline comment as done.
erichkeane added inline comments.



Comment at: cfe/trunk/include/clang/Basic/AttributeCommonInfo.h:166
+   ? SpellingIndex
+   : calculateAttributeSpellingListIndex();
+  }

plotfi wrote:
> erichkeane wrote:
> > aheejin wrote:
> > > MaskRay wrote:
> > > > calculateAttributeSpellingListIndex is defined in clangSema. This can 
> > > > cause lib/libclangAST.so.10svn (-DBUILD_SHARED_LIBS=on) fail to link:
> > > > 
> > > > ```
> > > > ld.lld: error: undefined symbol: 
> > > > clang::AttributeCommonInfo::calculateAttributeSpellingListIndex() const 
> > > >   
> > > > >>> referenced by AttributeCommonInfo.h:166 
> > > > >>> (../tools/clang/include/clang/Basic/AttributeCommonInfo.h:166) 
> > > > >>>   
> > > > >>> tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/AttrImpl.cpp.o:(clang::AttributeCommonInfo::getAttributeSpellingListIndex()
> > > > >>>  const)
> > > > ```
> > > +1 This fails builds with `-DBUILD_SHARED_LIBS=ON`. I tried to add 
> > > `clangSema` as a dependent library to `clangAST`, but this creates 
> > > several circular dependencies.
> > Thanks for the heads up.  The solution will just end up being moving that 
> > function's definition.  I'll submit a patch on monday. Thanks for the 
> > reproducer.
> Normally I’d suggest a revert, but I can see downstream some stuff with Swift 
> and apinotes was not completely trivial to get merged in with this patch. Is 
> simply moving the definition the right solution here btw?
Yep, exactly.  I would prefer someone to just fix it (since it IS something 
quite trivial) rather than revert.  This ends up being a massive change for the 
purposes of improving diagnostics here and downstream.

Typically it is considered somewhat fair to give the author time to fix a 
failure before reverting, and unfortunately this was discovered at 8pm on a 
Friday, so it seems longer than this would typically take.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67368/new/

https://reviews.llvm.org/D67368



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


[PATCH] D67608: [ARM] Preserve fpu behaviour for '-crypto'

2019-09-16 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

After retesting on a failing example and experimenting a bit, I think that we 
should only preserve +crypto with -fno-integrated-as. It would also be good to 
mention D66018  and maybe add the original 
author as a reviewer.




Comment at: clang/lib/Driver/ToolChains/Arch/ARM.cpp:499
 << "crypto" << 
llvm::ARM::getArchName(llvm::ARM::parseArch(ArchSuffix));
-  Features.push_back("-crypto");
+  //-mfpu=crypto-neon-fp-armv8 does allow +sha2 / +aes / +crypto features,
+  // even if compiling for an cpu armv7a, if explicitly defined by the 
user,

Looking into this in more detail I think the comment can be made more specific. 
It seems like the main reason to keep +crypto is that when the 
non-integrated-assembler is used, then we get the directive:
```
.fpu crypto-neon-fp-armv8
```
In arm-none-eabi-as the assembler will support crypto instructions. Clang will 
not as any use of crypto instructions will fail due lack of v8 support.

```
With -fno-integrated-as -mfpu=crypto-neon-fp-armv8 some assemblers such as the 
GNU assembler will permit the use of crypto instructions as the fpu will 
override the architecture. We keep the crypto feature in this case to preserve 
compatibility. In all other cases we remove the crypto feature. 
```



Comment at: clang/lib/Driver/ToolChains/Arch/ARM.cpp:502
+  // so do not deactivate them.
+  if ((llvm::find(Features, "+fp-armv8") == Features.end()) ||
+  (llvm::find(Features, "+neon") == Features.end()))

I think we should only do this for -fno-integrated-as as the integrated 
assembler will fail if give a crypto instruction even with this change. With 
the integrated assembler we get:

```
error: instruction requires: armv8
aese.8 q8, q9
```



Comment at: clang/test/Driver/arm-features.c:84
+// Check +crypto does not affect -march=armv7a -mfpu=crypto-neon-fp-armv8, but 
it does warn that +crypto has no effect
+// RUN: %clang -target arm-arm-none-eabi -march=armv7a 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefixes=CHECK-WARNONLY,ALL %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7a+aes 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefixes=CHECK-WARNONLY,ALL,CHECK-HASAES %s

arm-arm-none-eabi is a vendor specific triple? Better to use arm-none-eabi 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67608/new/

https://reviews.llvm.org/D67608



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


r371985 - Move some definitions from Sema to Basic to fix shared libs build

2019-09-16 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Mon Sep 16 06:58:59 2019
New Revision: 371985

URL: http://llvm.org/viewvc/llvm-project?rev=371985&view=rev
Log:
Move some definitions from Sema to Basic to fix shared libs build

r371875 moved some functionality around to a Basic header file, but
didn't move its definitions as well.  This patch moves some things
around so that shared library building can work.

Modified:
cfe/trunk/lib/Basic/Attributes.cpp
cfe/trunk/lib/Sema/ParsedAttr.cpp
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/lib/Basic/Attributes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Attributes.cpp?rev=371985&r1=371984&r2=371985&view=diff
==
--- cfe/trunk/lib/Basic/Attributes.cpp (original)
+++ cfe/trunk/lib/Basic/Attributes.cpp Mon Sep 16 06:58:59 2019
@@ -1,5 +1,6 @@
 #include "clang/Basic/Attributes.h"
 #include "clang/Basic/AttrSubjectMatchRules.h"
+#include "clang/Basic/AttributeCommonInfo.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "llvm/ADT/StringSwitch.h"
 using namespace clang;
@@ -21,7 +22,7 @@ int clang::hasAttribute(AttrSyntax Synta
 
 #include "clang/Basic/AttrHasAttributeImpl.inc"
 
-  return 0;
+  return 0;
 }
 
 const char *attr::getSubjectMatchRuleSpelling(attr::SubjectMatchRule Rule) {
@@ -33,3 +34,75 @@ const char *attr::getSubjectMatchRuleSpe
   }
   llvm_unreachable("Invalid subject match rule");
 }
+
+static StringRef
+normalizeAttrScopeName(StringRef ScopeName,
+   AttributeCommonInfo::Syntax SyntaxUsed) {
+  // Normalize the "__gnu__" scope name to be "gnu" and the "_Clang" scope name
+  // to be "clang".
+  if (SyntaxUsed == AttributeCommonInfo::AS_CXX11 ||
+  SyntaxUsed == AttributeCommonInfo::AS_C2x) {
+if (ScopeName == "__gnu__")
+  ScopeName = "gnu";
+else if (ScopeName == "_Clang")
+  ScopeName = "clang";
+  }
+  return ScopeName;
+}
+
+static StringRef normalizeAttrName(StringRef AttrName,
+   StringRef NormalizedScopeName,
+   AttributeCommonInfo::Syntax SyntaxUsed) {
+  // Normalize the attribute name, __foo__ becomes foo. This is only allowable
+  // for GNU attributes, and attributes using the double square bracket syntax.
+  bool ShouldNormalize =
+  SyntaxUsed == AttributeCommonInfo::AS_GNU ||
+  ((SyntaxUsed == AttributeCommonInfo::AS_CXX11 ||
+SyntaxUsed == AttributeCommonInfo::AS_C2x) &&
+   (NormalizedScopeName.empty() || NormalizedScopeName == "gnu" ||
+NormalizedScopeName == "clang"));
+  if (ShouldNormalize && AttrName.size() >= 4 && AttrName.startswith("__") &&
+  AttrName.endswith("__"))
+AttrName = AttrName.slice(2, AttrName.size() - 2);
+
+  return AttrName;
+}
+
+bool AttributeCommonInfo::isGNUScope() const {
+  return ScopeName && (ScopeName->isStr("gnu") || ScopeName->isStr("__gnu__"));
+}
+
+#include "clang/Sema/AttrParsedAttrKinds.inc"
+
+AttributeCommonInfo::Kind
+AttributeCommonInfo::getParsedKind(const IdentifierInfo *Name,
+   const IdentifierInfo *ScopeName,
+   Syntax SyntaxUsed) {
+  StringRef AttrName = Name->getName();
+
+  SmallString<64> FullName;
+  if (ScopeName)
+FullName += normalizeAttrScopeName(ScopeName->getName(), SyntaxUsed);
+
+  AttrName = normalizeAttrName(AttrName, FullName, SyntaxUsed);
+
+  // Ensure that in the case of C++11 attributes, we look for '::foo' if it is
+  // unscoped.
+  if (ScopeName || SyntaxUsed == AS_CXX11 || SyntaxUsed == AS_C2x)
+FullName += "::";
+  FullName += AttrName;
+
+  return ::getAttrKind(FullName, SyntaxUsed);
+}
+
+unsigned AttributeCommonInfo::calculateAttributeSpellingListIndex() const {
+  // Both variables will be used in tablegen generated
+  // attribute spell list index matching code.
+  auto Syntax = static_cast(getSyntax());
+  StringRef Scope =
+  getScopeName() ? normalizeAttrScopeName(getScopeName()->getName(), 
Syntax)
+ : "";
+  StringRef Name = normalizeAttrName(getAttrName()->getName(), Scope, Syntax);
+
+#include "clang/Sema/AttrSpellingListIndex.inc"
+}

Modified: cfe/trunk/lib/Sema/ParsedAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/ParsedAttr.cpp?rev=371985&r1=371984&r2=371985&view=diff
==
--- cfe/trunk/lib/Sema/ParsedAttr.cpp (original)
+++ cfe/trunk/lib/Sema/ParsedAttr.cpp Mon Sep 16 06:58:59 2019
@@ -100,76 +100,6 @@ void AttributePool::takePool(AttributePo
   pool.Attrs.clear();
 }
 
-#include "clang/Sema/AttrParsedAttrKinds.inc"
-
-static StringRef normalizeAttrScopeName(StringRef ScopeName,
-ParsedAttr::Syntax SyntaxUsed) {
-  // Normalize the "__gnu__" scope name to be "gnu" and the "_Clang" scope name
-  // to be "clang".
-  if (SyntaxUsed == ParsedAttr::AS_CXX11 ||
-Sy

[PATCH] D67368: [NFCI]Create CommonAttributeInfo Type as base type of *Attr and ParsedAttr.

2019-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Fixed in r371985.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67368/new/

https://reviews.llvm.org/D67368



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


[clang-tools-extra] r371986 - [clangd][vscode] update the development doc.

2019-09-16 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Sep 16 07:03:06 2019
New Revision: 371986

URL: http://llvm.org/viewvc/llvm-project?rev=371986&view=rev
Log:
[clangd][vscode] update the development doc.

Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/DEVELOPING.md

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/DEVELOPING.md
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/DEVELOPING.md?rev=371986&r1=371985&r2=371986&view=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/DEVELOPING.md 
(original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/DEVELOPING.md Mon Sep 
16 07:03:06 2019
@@ -48,6 +48,6 @@ please contact clangd-...@lists.llvm.org
   # For the first time, you need to login in the account. vsce will ask you for
 the Personal Access Token, and remember it for future commands.
   $ vsce login llvm-vs-code-extensions
-  $ vsce publish
+  # Make sure the screenshots in the readme are rendered in VSCode marketplace.
+  $ vsce publish --baseImagesUrl 
https://raw.githubusercontent.com/llvm/llvm-project/master/clang-tools-extra/clangd/clients/clangd-vscode/
 ```
-


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


[PATCH] D66951: [ASTImporter] Add comprehensive tests for ODR violation handling strategies

2019-09-16 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 220338.
martong marked 2 inline comments as done.
martong added a comment.

- PrevF->ImportedF, remove braces


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66951/new/

https://reviews.llvm.org/D66951

Files:
  clang/unittests/AST/ASTImporterODRStrategiesTest.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/CMakeLists.txt

Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -11,6 +11,7 @@
   ASTImporterFixtures.cpp
   ASTImporterTest.cpp
   ASTImporterGenericRedeclTest.cpp
+  ASTImporterODRStrategiesTest.cpp
   ASTImporterVisibilityTest.cpp
   ASTTraverserTest.cpp
   ASTTypeTraitsTest.cpp
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5409,187 +5409,6 @@
   EXPECT_EQ(ImportedX->isAggregate(), FromX->isAggregate());
 }
 
-struct ConflictingDeclsWithLiberalStrategy : ASTImporterOptionSpecificTestBase {
-  ConflictingDeclsWithLiberalStrategy() {
-this->ODRHandling = ASTImporter::ODRHandlingType::Liberal;
-  }
-};
-
-// Check that a Decl has been successfully imported into a standalone redecl
-// chain.
-template 
-static void CheckImportedAsNew(llvm::Expected &Result, Decl *ToTU,
-   PatternTy Pattern) {
-  ASSERT_TRUE(isSuccess(Result));
-  Decl *ImportedD = *Result;
-  ASSERT_TRUE(ImportedD);
-  auto *ToD = FirstDeclMatcher().match(ToTU, Pattern);
-  EXPECT_NE(ImportedD, ToD);
-  EXPECT_FALSE(ImportedD->getPreviousDecl());
-  EXPECT_EQ(DeclCounter().match(ToTU, Pattern), 2u);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, Typedef) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  typedef int X;
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  typedef double X;
-  )",
-  Lang_CXX11);
-  auto Pattern = typedefNameDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, TypeAlias) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  using X = int;
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  using X = double;
-  )",
-  Lang_CXX11);
-  auto Pattern = typedefNameDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, EnumDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  enum X { a, b };
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  enum X { a, b, c };
-  )",
-  Lang_CXX11);
-  auto Pattern = enumDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, EnumConstantDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  enum E { X = 0 };
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  enum E { X = 1 };
-  )",
-  Lang_CXX11);
-  auto Pattern = enumConstantDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, RecordDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  class X { int a; };
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  class X { int b; };
-  )",
-  Lang_CXX11);
-  auto Pattern = cxxRecordDecl(hasName("X"), unless(isImplicit()));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, VarDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  int X;
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  double X;
-  )",
-  Lang_CXX11);
-  auto Pattern = varDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, FunctionDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  void X(int);
-  )",
-  Lang_C); // C, no overloading!
-  Decl *FromTU = getTuDecl(
-  R"(
-  void X(double);
-  )",
-  Lang_C);
-  auto Pattern = functionDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected R

[PATCH] D66951: [ASTImporter] Add comprehensive tests for ODR violation handling strategies

2019-09-16 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/unittests/AST/ASTImporterODRStrategiesTest.cpp:274
+// There may be a hidden fwd spec decl before a function spec decl.
+if (auto *PrevF = dyn_cast(ImportedD)) {
+  if (PrevF->getTemplatedKind() ==

balazske wrote:
> This should be called `ImportedF` instead of `PrevF`?
Ok, renamed to `ImportedF`.
Also removed the superfluous braces.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66951/new/

https://reviews.llvm.org/D66951



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


[PATCH] D67621: [libTooling] Add `ifBound`, `elseBranch` RangeSelector combinators.

2019-09-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: gribozavr.
Herald added a project: clang.

Adds two new combinators and corresponding tests to the RangeSelector library.

- `ifBound` -- conditional evaluation of range-selectors, based on whether a 
given node id is bound in the match.
- `elseBranch` -- selects the source range of the else and its statement.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67621

Files:
  clang/include/clang/Tooling/Refactoring/RangeSelector.h
  clang/lib/Tooling/Refactoring/RangeSelector.cpp
  clang/unittests/Tooling/RangeSelectorTest.cpp

Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- clang/unittests/Tooling/RangeSelectorTest.cpp
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -520,6 +520,60 @@
Failed(withTypeErrorMessage("stmt")));
 }
 
+TEST(RangeSelectorTest, IfBoundOpBound) {
+  StringRef Code = R"cc(
+int f() {
+  return 3 + 5;
+}
+  )cc";
+  StringRef ID = "id", Op = "op";
+  TestMatch Match =
+  matchCode(Code, binaryOperator(hasLHS(expr().bind(ID))).bind(Op));
+  EXPECT_THAT_EXPECTED(select(ifBound(ID, node(ID), node(Op)), Match),
+   HasValue("3"));
+}
+
+TEST(RangeSelectorTest, IfBoundOpUnbound) {
+  StringRef Code = R"cc(
+int f() {
+  return 3 + 5;
+}
+  )cc";
+  StringRef ID = "id", Op = "op";
+  TestMatch Match = matchCode(Code, binaryOperator().bind(Op));
+  EXPECT_THAT_EXPECTED(select(ifBound(ID, node(ID), node(Op)), Match),
+   HasValue("3 + 5"));
+}
+
+TEST(RangeSelectorTest, ElseBranchOpSingleStatement) {
+  StringRef Code = R"cc(
+int f() {
+  int x = 0;
+  if (true) x = 3;
+  else x = 4;
+  return x + 5;
+}
+  )cc";
+  StringRef ID = "id";
+  TestMatch Match = matchCode(Code, ifStmt().bind(ID));
+  EXPECT_THAT_EXPECTED(select(elseBranch(ID), Match), HasValue("else x = 4;"));
+}
+
+TEST(RangeSelectorTest, ElseBranchOpCompoundStatement) {
+  StringRef Code = R"cc(
+int f() {
+  int x = 0;
+  if (true) x = 3;
+  else { x = 4; }
+  return x + 5;
+}
+  )cc";
+  StringRef ID = "id";
+  TestMatch Match = matchCode(Code, ifStmt().bind(ID));
+  EXPECT_THAT_EXPECTED(select(elseBranch(ID), Match),
+   HasValue("else { x = 4; }"));
+}
+
 // Tests case where the matched node is the complete expanded text.
 TEST(RangeSelectorTest, ExpansionOp) {
   StringRef Code = R"cc(
Index: clang/lib/Tooling/Refactoring/RangeSelector.cpp
===
--- clang/lib/Tooling/Refactoring/RangeSelector.cpp
+++ clang/lib/Tooling/Refactoring/RangeSelector.cpp
@@ -219,6 +219,9 @@
 }
 
 namespace {
+// FIXME: make this available in the public API for users to easily create their
+// own selectors.
+
 // Creates a selector from a range-selection function \p Func, which selects a
 // range that is relative to a bound node id.  \c T is the node type expected by
 // \p Func.
@@ -286,6 +289,19 @@
   return RelativeSelector(std::move(ID));
 }
 
+namespace {
+// Returns the range of the else branch, including the `else` keyword.
+CharSourceRange getElseRange(const MatchResult &Result, const IfStmt &S) {
+  return maybeExtendRange(
+  CharSourceRange::getTokenRange(S.getElseLoc(), S.getEndLoc()),
+  tok::TokenKind::semi, *Result.Context);
+}
+} // namespace
+
+RangeSelector tooling::elseBranch(std::string ID) {
+  return RelativeSelector(std::move(ID));
+}
+
 RangeSelector tooling::expansion(RangeSelector S) {
   return [S](const MatchResult &Result) -> Expected {
 Expected SRange = S(Result);
@@ -294,3 +310,11 @@
 return Result.SourceManager->getExpansionRange(*SRange);
   };
 }
+
+RangeSelector tooling::ifBound(std::string ID, RangeSelector TrueSelector,
+   RangeSelector FalseSelector) {
+  return [=](const MatchResult &Result) {
+auto &Map = Result.Nodes.getMap();
+return (Map.find(ID) != Map.end() ? TrueSelector : FalseSelector)(Result);
+  };
+}
Index: clang/include/clang/Tooling/Refactoring/RangeSelector.h
===
--- clang/include/clang/Tooling/Refactoring/RangeSelector.h
+++ clang/include/clang/Tooling/Refactoring/RangeSelector.h
@@ -83,6 +83,15 @@
 /// source), if `S` is an expansion, and `S` itself, otherwise.  Corresponds to
 /// `SourceManager::getExpansionRange`.
 RangeSelector expansion(RangeSelector S);
+
+/// Chooses between the two selectors, based on whether \p ID is bound in the
+/// match.
+RangeSelector ifBound(std::string ID, RangeSelector TrueSelector,
+  RangeSelector FalseSelector);
+
+/// Gets the range of the else branch of an if statement, starting from the
+/// \c else keyword.  \param ID must be bound to an `ifStmt`.
+RangeSelector elseBranch(std::string ID);
 } // namespace tooling
 } // namespace clang
 
_

[PATCH] D67545: [clang-tidy] Added DefaultOperatorNewCheck.

2019-09-16 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Some thoughts:

1. Docs missing
2. How does this play with C++17 aligned new? Assuming compiler/library support 
for that isn't broken ('bye, OSX!', ?), i'm not sure why it would be UB for 
C++17, see https://godbolt.org/z/kwxRbu vs https://godbolt.org/z/om-bR2
3. I'm not sure what's `getCharAlign()` has to do with anything here? You want 
to check the alignment requirement against the 
`__STDCPP_DEFAULT_NEW_ALIGNMENT__` (i don't recall how to get it inside of 
clang) i would think?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67545/new/

https://reviews.llvm.org/D67545



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


[PATCH] D67545: [clang-tidy] Added DefaultOperatorNewCheck.

2019-09-16 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang-tools-extra/clang-tidy/cert/DefaultOperatorNewCheck.cpp:26
+
+  if (NewExpr->getNumPlacementArgs() > 0)
+return;

Perhaps we should add in the docs that placement new is not supported. Or add a 
fixme here.
Anyway, I feel this code simply could work with placement new as well. What is 
the reason you disabled it for placement new?



Comment at: clang-tools-extra/clang-tidy/cert/DefaultOperatorNewCheck.cpp:41
+  unsigned SpecifiedAlignment = D->getMaxAlignment();
+  unsigned DefaultAlignment = Context.getTargetInfo().getCharAlign();
+  if (!SpecifiedAlignment)

This might not be what we want... `getCharAlign()` theoretically could return 
even with `1`, I think, though it would be a very strange architecture.
Perhaps we should use `getSuitableAlign()` instead?

Also, I think we should call the variable as `FundamentalAlignment`. 
Fundamental and default alignment can differ, I guess.



Comment at: clang-tools-extra/clang-tidy/cert/DefaultOperatorNewCheck.cpp:49
+  if (HasDefaultOperatorNew && OverAligned)
+diag(NewExpr->getBeginLoc(), "using default 'operator new' with 
over-aligned type %0 may result in undefined behavior")
+  << D;

I think it would be useful to add the value of the fundamental alignment to the 
diagnostics too.



Comment at: clang-tools-extra/docs/clang-tidy/checks/list.rst:107
cert-oop54-cpp (redirects to bugprone-unhandled-self-assignment) 

-   clang-analyzer-core.CallAndMessage
-   clang-analyzer-core.DivideZero
+   clang-analyzer-core.CallAndMessage (redirects to 
https://clang.llvm.org/docs/analyzer/checkers) 

+   clang-analyzer-core.DivideZero (redirects to 
https://clang.llvm.org/docs/analyzer/checkers) 

Why do we have these changes? Seems to be unrelated.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67545/new/

https://reviews.llvm.org/D67545



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


[PATCH] D67341: [clangd] Simplify semantic highlighting visitor

2019-09-16 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL372008: [clangd] Simplify semantic highlighting visitor 
(authored by ibiryukov, committed by ).
Herald added subscribers: llvm-commits, usaxena95.
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D67341?vs=219503&id=220350#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67341/new/

https://reviews.llvm.org/D67341

Files:
  clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp

Index: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
@@ -14,6 +14,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclarationName.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
@@ -24,6 +25,77 @@
 namespace clangd {
 namespace {
 
+/// Some names are not written in the source code and cannot be highlighted,
+/// e.g. anonymous classes. This function detects those cases.
+bool canHighlightName(DeclarationName Name) {
+  if (Name.getNameKind() == DeclarationName::CXXConstructorName ||
+  Name.getNameKind() == DeclarationName::CXXUsingDirective)
+return true;
+  auto *II = Name.getAsIdentifierInfo();
+  return II && !II->getName().empty();
+}
+
+llvm::Optional kindForType(const Type *TP);
+llvm::Optional kindForDecl(const NamedDecl *D) {
+  if (auto *TD = dyn_cast(D)) {
+// We try to highlight typedefs as their underlying type.
+if (auto K = kindForType(TD->getUnderlyingType().getTypePtrOrNull()))
+  return K;
+// And fallback to a generic kind if this fails.
+return HighlightingKind::Typedef;
+  }
+  // We highlight class decls, constructor decls and destructor decls as
+  // `Class` type. The destructor decls are handled in `VisitTypeLoc` (we
+  // will visit a TypeLoc where the underlying Type is a CXXRecordDecl).
+  if (auto *RD = llvm::dyn_cast(D)) {
+// We don't want to highlight lambdas like classes.
+if (RD->isLambda())
+  return llvm::None;
+return HighlightingKind::Class;
+  }
+  if (isa(D) || isa(D) ||
+  isa(D))
+return HighlightingKind::Class;
+  if (auto *MD = dyn_cast(D))
+return MD->isStatic() ? HighlightingKind::StaticMethod
+  : HighlightingKind::Method;
+  if (isa(D))
+return HighlightingKind::Field;
+  if (isa(D))
+return HighlightingKind::Enum;
+  if (isa(D))
+return HighlightingKind::EnumConstant;
+  if (isa(D))
+return HighlightingKind::Parameter;
+  if (auto *VD = dyn_cast(D))
+return VD->isStaticDataMember()
+   ? HighlightingKind::StaticField
+   : VD->isLocalVarDecl() ? HighlightingKind::LocalVariable
+  : HighlightingKind::Variable;
+  if (isa(D))
+return HighlightingKind::Variable;
+  if (isa(D))
+return HighlightingKind::Function;
+  if (isa(D) || isa(D) ||
+  isa(D))
+return HighlightingKind::Namespace;
+  if (isa(D) || isa(D) ||
+  isa(D))
+return HighlightingKind::TemplateParameter;
+  return llvm::None;
+}
+llvm::Optional kindForType(const Type *TP) {
+  if (!TP)
+return llvm::None;
+  if (TP->isBuiltinType()) // Builtins are special, they do not have decls.
+return HighlightingKind::Primitive;
+  if (auto *TD = dyn_cast(TP))
+return kindForDecl(TD->getDecl());
+  if (auto *TD = TP->getAsTagDecl())
+return kindForDecl(TD);
+  return llvm::None;
+}
+
 // Collects all semantic tokens in an ASTContext.
 class HighlightingTokenCollector
 : public RecursiveASTVisitor {
@@ -70,66 +142,30 @@
 
   bool VisitNamespaceAliasDecl(NamespaceAliasDecl *NAD) {
 // The target namespace of an alias can not be found in any other way.
-addToken(NAD->getTargetNameLoc(), HighlightingKind::Namespace);
+addToken(NAD->getTargetNameLoc(), NAD->getAliasedNamespace());
 return true;
   }
 
   bool VisitMemberExpr(MemberExpr *ME) {
-const auto *MD = ME->getMemberDecl();
-if (isa(MD))
-  // When calling the destructor manually like: AAA::~A(); The ~ is a
-  // MemberExpr. Other methods should still be highlighted though.
-  return true;
-if (isa(MD))
-  // The MemberLoc is invalid for C++ conversion operators. We do not
-  // attempt to add tokens with invalid locations.
-  return true;
-addToken(ME->getMemberLoc(), MD);
+if (canHighlightName(ME->getMemberNameInfo().getName()))
+  addToken(ME->getMemberLoc(), ME->getMemberDecl());
 return true;
   }
 
   bool VisitNamedDecl(NamedDecl *ND) {
-// UsingDirectiveDecl's namespaces do not show up anywhere else in the
-// Visit/Traverse mehods. But they should also be highlighted as a
-// namespace.
-if (const auto *UD 

[clang-tools-extra] r372008 - [clangd] Simplify semantic highlighting visitor

2019-09-16 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Sep 16 09:16:03 2019
New Revision: 372008

URL: http://llvm.org/viewvc/llvm-project?rev=372008&view=rev
Log:
[clangd] Simplify semantic highlighting visitor

Summary:
- Functions to compute highlighting kinds for things are separated from
  the ones that add highlighting tokens.
  This keeps each of them more focused on what they're doing: getting
  locations and figuring out the kind of the entity, correspondingly.

- Less special cases in visitor for various nodes.

This change is an NFC.

Reviewers: hokein

Reviewed By: hokein

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp

Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp?rev=372008&r1=372007&r2=372008&view=diff
==
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp Mon Sep 16 09:16:03 
2019
@@ -14,6 +14,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclarationName.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
@@ -24,6 +25,77 @@ namespace clang {
 namespace clangd {
 namespace {
 
+/// Some names are not written in the source code and cannot be highlighted,
+/// e.g. anonymous classes. This function detects those cases.
+bool canHighlightName(DeclarationName Name) {
+  if (Name.getNameKind() == DeclarationName::CXXConstructorName ||
+  Name.getNameKind() == DeclarationName::CXXUsingDirective)
+return true;
+  auto *II = Name.getAsIdentifierInfo();
+  return II && !II->getName().empty();
+}
+
+llvm::Optional kindForType(const Type *TP);
+llvm::Optional kindForDecl(const NamedDecl *D) {
+  if (auto *TD = dyn_cast(D)) {
+// We try to highlight typedefs as their underlying type.
+if (auto K = kindForType(TD->getUnderlyingType().getTypePtrOrNull()))
+  return K;
+// And fallback to a generic kind if this fails.
+return HighlightingKind::Typedef;
+  }
+  // We highlight class decls, constructor decls and destructor decls as
+  // `Class` type. The destructor decls are handled in `VisitTypeLoc` (we
+  // will visit a TypeLoc where the underlying Type is a CXXRecordDecl).
+  if (auto *RD = llvm::dyn_cast(D)) {
+// We don't want to highlight lambdas like classes.
+if (RD->isLambda())
+  return llvm::None;
+return HighlightingKind::Class;
+  }
+  if (isa(D) || isa(D) ||
+  isa(D))
+return HighlightingKind::Class;
+  if (auto *MD = dyn_cast(D))
+return MD->isStatic() ? HighlightingKind::StaticMethod
+  : HighlightingKind::Method;
+  if (isa(D))
+return HighlightingKind::Field;
+  if (isa(D))
+return HighlightingKind::Enum;
+  if (isa(D))
+return HighlightingKind::EnumConstant;
+  if (isa(D))
+return HighlightingKind::Parameter;
+  if (auto *VD = dyn_cast(D))
+return VD->isStaticDataMember()
+   ? HighlightingKind::StaticField
+   : VD->isLocalVarDecl() ? HighlightingKind::LocalVariable
+  : HighlightingKind::Variable;
+  if (isa(D))
+return HighlightingKind::Variable;
+  if (isa(D))
+return HighlightingKind::Function;
+  if (isa(D) || isa(D) ||
+  isa(D))
+return HighlightingKind::Namespace;
+  if (isa(D) || isa(D) ||
+  isa(D))
+return HighlightingKind::TemplateParameter;
+  return llvm::None;
+}
+llvm::Optional kindForType(const Type *TP) {
+  if (!TP)
+return llvm::None;
+  if (TP->isBuiltinType()) // Builtins are special, they do not have decls.
+return HighlightingKind::Primitive;
+  if (auto *TD = dyn_cast(TP))
+return kindForDecl(TD->getDecl());
+  if (auto *TD = TP->getAsTagDecl())
+return kindForDecl(TD);
+  return llvm::None;
+}
+
 // Collects all semantic tokens in an ASTContext.
 class HighlightingTokenCollector
 : public RecursiveASTVisitor {
@@ -70,66 +142,30 @@ public:
 
   bool VisitNamespaceAliasDecl(NamespaceAliasDecl *NAD) {
 // The target namespace of an alias can not be found in any other way.
-addToken(NAD->getTargetNameLoc(), HighlightingKind::Namespace);
+addToken(NAD->getTargetNameLoc(), NAD->getAliasedNamespace());
 return true;
   }
 
   bool VisitMemberExpr(MemberExpr *ME) {
-const auto *MD = ME->getMemberDecl();
-if (isa(MD))
-  // When calling the destructor manually like: AAA::~A(); The ~ is a
-  // MemberExpr. Other methods should still be highlighted though.
-  return true;
-if (isa(MD))
-  // The MemberLoc is invalid for C++ conversion operators. We do not
-  // attempt to add tokens with invalid loca

[PATCH] D66324: clang-misexpect: Profile Guided Validation of Performance Annotations in LLVM

2019-09-16 Thread James Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: llvm/trunk/include/llvm/IR/DiagnosticInfo.h:79
+  DK_FirstPluginKind,
+  DK_MisExpect
 };

Is this not going to clash with the first caller to 
`getNextAvailablePluginDiagnosticKind`? `DK_FirstPluginKind` is special and 
shouldn't have anything after it.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66324/new/

https://reviews.llvm.org/D66324



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


[PATCH] D67549: [IntrinsicEmitter] Add overloaded types for SVE intrinsics (Subdivide2 & Subdivide4)

2019-09-16 Thread Diana Picus via Phabricator via cfe-commits
rovka added inline comments.



Comment at: include/llvm/IR/DerivedTypes.h:515
+  else
+VTy = VectorType::getTruncatedElementVectorType(VTy);
+}

Why not move this logic to getTruncatedElementVectorType and drop 
getNarrowerFpElementVectorType altogether? 



Comment at: include/llvm/IR/Intrinsics.h:130
+ Kind == PtrToElt || Kind == VecElementArgument ||
+ Kind == Subdivide2Argument || Kind == Subdivide4Argument);
   return Argument_Info >> 3;

Not directly related to your change: Is there a reason why VecOfAnyPtrsToElt 
isn't in this assert? If not, maybe this is a good time to add a 
First/LastArgumentKind and just check that Kind is in the range.



Comment at: lib/IR/Function.cpp:989
+Type *Ty = Tys[D.getArgumentNumber()];
+if (VectorType *VTy = dyn_cast(Ty))
+  return VectorType::getSubdividedVectorType(VTy, 1);

Maybe replace this with an assert and drop the unreachable.



Comment at: lib/IR/Function.cpp:997
+  return VectorType::getSubdividedVectorType(VTy, 2);
+llvm_unreachable("unhandled");
+  }

Ditto,



Comment at: lib/IR/Function.cpp:1312
+case IITDescriptor::Subdivide4Argument: {
+  // This may only be used when referring to a previous vector argument.
+  if (D.getArgumentNumber() >= ArgTys.size())

Can you share this code? Either a small helper or a fallthrough with a repeat 
check on D.Kind to get the number of subdivisions would work.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67549/new/

https://reviews.llvm.org/D67549



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


[PATCH] D67613: [DWARF-5] Support for DWARF-5 C++ language tags

2019-09-16 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: include/clang/AST/DeclCXX.h:2931
+lang_cxx_11 = /* DW_LANG_C_plus_plus_11 */ 0x001a,
+lang_cxx_14 = /* DW_LANG_C_plus_plus_14 */ 0x0021
   };

I understand that DWARF does not define a C++17 language constant, but in the 
AST I fell like we should represent it, even if it is being lowered into C++14 
for the debug info.



Comment at: lib/AST/DeclPrinter.cpp:1009
+  l = "C++_14";
+else if (D->getLanguage() == LinkageSpecDecl::lang_cxx_11)
+  l = "C++_11";

Can you turn this into a switch() statement?



Comment at: lib/AST/DeclPrinter.cpp:1010
+else if (D->getLanguage() == LinkageSpecDecl::lang_cxx_11)
+  l = "C++_11";
+else {

Why this weird spelling with the underscore?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67613/new/

https://reviews.llvm.org/D67613



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


[PATCH] D67567: [clang-tidy] New check to warn when storing dispatch_once_t in non-static, non-global storage

2019-09-16 Thread Michael Wyman via Phabricator via cfe-commits
mwyman added a comment.

In D67567#1670264 , @NoQ wrote:

> FTR, we already have a similar Static Analyzer check, eg.:
>  
> https://github.com/llvm-mirror/clang/blob/release_80/test/Analysis/dispatch-once.m#L15
>  
> https://github.com/llvm-mirror/clang/blob/release_80/test/Analysis/dispatch-once.m#L26
>
> Your check is a bit more aggressive but i don't see why didn't we do it that 
> way in the first place :) Though you won't be able to warn on the heap 
> example.


The Static Analyzer check was pointed out by a colleague; unfortunately our 
build environment doesn't currently play nice with running the static analyzer 
(so many devs don't end up running it) but ClangTidy gets run as part of our 
code review process. Given libdispatch's documented requirements, it seemed 
reasonable to be aggressive with a ClangTidy check when we can reasonably 
identify non-static/global storage.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67567/new/

https://reviews.llvm.org/D67567



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


r372011 - [OPENMP]Fix parsing/sema for function templates with declare simd.

2019-09-16 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Sep 16 10:06:31 2019
New Revision: 372011

URL: http://llvm.org/viewvc/llvm-project?rev=372011&view=rev
Log:
[OPENMP]Fix parsing/sema for function templates with declare simd.

Need to return original declaration group with FunctionTemplateDecl, not
the inner FunctionDecl, to correctly handle parsing of directives with
the templates parameters.

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

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=372011&r1=372010&r2=372011&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Mon Sep 16 10:06:31 2019
@@ -4889,7 +4889,7 @@ Sema::DeclGroupPtrTy Sema::ActOnOpenMPDe
   const_cast(LinModifiers.data()), LinModifiers.size(),
   NewSteps.data(), NewSteps.size(), SR);
   ADecl->addAttr(NewAttr);
-  return ConvertDeclToDeclGroup(ADecl);
+  return DG;
 }
 
 Sema::DeclGroupPtrTy

Modified: cfe/trunk/test/OpenMP/declare_simd_ast_print.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_simd_ast_print.cpp?rev=372011&r1=372010&r2=372011&view=diff
==
--- cfe/trunk/test/OpenMP/declare_simd_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_simd_ast_print.cpp Mon Sep 16 10:06:31 2019
@@ -21,6 +21,15 @@ void add_1(float *d) __attribute__((cold
 // CHECK-NEXT: void add_1(float *d) __attribute__((cold));
 //
 
+#pragma omp declare simd aligned(hp, hp2:V)
+#pragma omp declare simd aligned(hp, hp2:V)
+template  void h(C *hp, C *hp2, C *hq, C *lin) {
+}
+// CHECK-NEXT: #pragma omp declare simd aligned(hp: V) aligned(hp2: V)
+// CHECK-NEXT: #pragma omp declare simd aligned(hp: V) aligned(hp2: V)
+// CHECK-NEXT: template  void h(C *hp, C *hp2, C *hq, C *lin) {
+// CHECK-NEXT: }
+
 #pragma omp declare simd aligned(hp, hp2)
 template  void h(C *hp, C *hp2, C *hq, C *lin) {
 }


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


[PATCH] D67567: [clang-tidy] New check to warn when storing dispatch_once_t in non-static, non-global storage

2019-09-16 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D67567#1671499 , @mwyman wrote:

> In D67567#1670264 , @NoQ wrote:
>
> > FTR, we already have a similar Static Analyzer check, eg.:
> >  
> > https://github.com/llvm-mirror/clang/blob/release_80/test/Analysis/dispatch-once.m#L15
> >  
> > https://github.com/llvm-mirror/clang/blob/release_80/test/Analysis/dispatch-once.m#L26
> >
> > Your check is a bit more aggressive but i don't see why didn't we do it 
> > that way in the first place :) Though you won't be able to warn on the heap 
> > example.
>
>
> The Static Analyzer check was pointed out by a colleague; unfortunately our 
> build environment doesn't currently play nice with running the static 
> analyzer (so many devs don't end up running it) but ClangTidy gets run as 
> part of our code review process. Given libdispatch's documented requirements, 
> it seemed reasonable to be aggressive with a ClangTidy check when we can 
> reasonably identify non-static/global storage.


You can run static analyzer checks as normal clang-tidy checks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67567/new/

https://reviews.llvm.org/D67567



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


[PATCH] D67247: Added missing unqualified name lookup of operator overloads for fold expressions

2019-09-16 Thread Jonathan Meier via Phabricator via cfe-commits
jonathanmeier added a comment.

ping @rsmith


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67247/new/

https://reviews.llvm.org/D67247



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


[PATCH] D67567: [clang-tidy] New check to warn when storing dispatch_once_t in non-static, non-global storage

2019-09-16 Thread Michael Wyman via Phabricator via cfe-commits
mwyman updated this revision to Diff 220357.
mwyman edited the summary of this revision.
mwyman added a comment.
Herald added subscribers: usaxena95, kadircet, arphaman, jkorous.

Migrated check to new `darwin` module.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67567/new/

https://reviews.llvm.org/D67567

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/darwin/CMakeLists.txt
  clang-tools-extra/clang-tidy/darwin/DarwinTidyModule.cpp
  clang-tools-extra/clang-tidy/darwin/DispatchOnceNonstaticCheck.cpp
  clang-tools-extra/clang-tidy/darwin/DispatchOnceNonstaticCheck.h
  clang-tools-extra/clang-tidy/plugin/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/darwin-dispatch-once-nonstatic.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/darwin-dispatch-once-nonstatic.mm

Index: clang-tools-extra/test/clang-tidy/darwin-dispatch-once-nonstatic.mm
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/darwin-dispatch-once-nonstatic.mm
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s darwin-dispatch-once-nonstatic %t
+
+typedef int dispatch_once_t;
+extern void dispatch_once(dispatch_once_t *pred, void(^block)(void));
+
+
+void bad_dispatch_once(dispatch_once_t once, void(^block)(void)) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: dispatch_once_ts must have static or global storage duration; function parameters should be pointer references [darwin-dispatch-once-nonstatic]
+
+// file-scope dispatch_once_ts have static storage duration.
+dispatch_once_t global_once;
+static dispatch_once_t file_static_once;
+namespace {
+dispatch_once_t anonymous_once;
+} // end anonymous namespace
+
+int Correct(void) {
+  static int value;
+  static dispatch_once_t once;
+  dispatch_once(&once, ^{
+value = 1;
+  });
+  return value;
+}
+
+int Incorrect(void) {
+  static int value;
+  dispatch_once_t once;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: dispatch_once_t variables must have static or global storage duration [darwin-dispatch-once-nonstatic]
+  // CHECK-FIXES: static dispatch_once_t once;
+  dispatch_once(&once, ^{
+value = 1;
+  });
+  return value;
+}
+
+struct OnceStruct {
+  static dispatch_once_t staticOnce; // Allowed
+  int value;
+  dispatch_once_t once;  // Allowed (at this time)
+};
+
+@interface MyObject {
+  dispatch_once_t _once;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: dispatch_once_t variables must have static or global storage duration and cannot be Objective-C instance variables [darwin-dispatch-once-nonstatic]
+}
+@end
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -211,6 +211,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   darwin-dispatch-once-nonstatic
fuchsia-default-arguments-calls
fuchsia-default-arguments-declarations
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
Index: clang-tools-extra/docs/clang-tidy/checks/darwin-dispatch-once-nonstatic.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/darwin-dispatch-once-nonstatic.rst
@@ -0,0 +1,22 @@
+.. title:: clang-tidy - darwin-dispatch-once-nonstatic
+
+darwin-dispatch-once-nonstatic
+==
+
+Finds declarations of ``dispatch_once_t`` variables without static or global
+storage. The behavior of using ``dispatch_once_t`` predicates with automatic
+or dynamic storage is undefined by libdispatch, and should be avoided.
+
+It is a common paradigm to have functions initialize internal static or global
+data once when the function runs, but programmers have been known to miss the
+static on the ``dispatch_once_t`` predicate, leading to an uninitialized flag
+value at the mercy of the stack.
+
+Programmers have also been known to make ``dispatch_once_t``s be members of
+structs/classes, with the intent to lazily perform some expensive struct or
+class member initialization only once; however, this violates the libdispatch
+requirements.
+
+See the discussion section of
+`Apple's dispatch_once documentation `_
+for more information.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -73,6 +73,12 @@
   Finds instances where variables with static storage are initialized
   dyn

r372014 - [Clang][Codegen] Relax available-externally-suppress.c test

2019-09-16 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Mon Sep 16 10:46:01 2019
New Revision: 372014

URL: http://llvm.org/viewvc/llvm-project?rev=372014&view=rev
Log:
[Clang][Codegen] Relax available-externally-suppress.c test

That test is broken by design.
It depends on llvm middle-end behavior.
No clang codegen test should be doing that.
This one is salvageable by relaxing check lines.

Modified:
cfe/trunk/test/CodeGen/available-externally-suppress.c

Modified: cfe/trunk/test/CodeGen/available-externally-suppress.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/available-externally-suppress.c?rev=372014&r1=372013&r2=372014&view=diff
==
--- cfe/trunk/test/CodeGen/available-externally-suppress.c (original)
+++ cfe/trunk/test/CodeGen/available-externally-suppress.c Mon Sep 16 10:46:01 
2019
@@ -30,10 +30,8 @@ inline int __attribute__((always_inline)
 // CHECK: @test1
 // LTO: @test1
 int test1(int x) {
-  // CHECK: br i1
   // CHECK-NOT: call {{.*}} @f1
   // CHECK: ret i32
-  // LTO: br i1
   // LTO-NOT: call {{.*}} @f1
   // LTO: ret i32
   return f1(x);


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


r372015 - [Clang][Codegen] Disable arm_acle.c test.

2019-09-16 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Mon Sep 16 10:46:08 2019
New Revision: 372015

URL: http://llvm.org/viewvc/llvm-project?rev=372015&view=rev
Log:
[Clang][Codegen] Disable arm_acle.c test.

This test is broken by design. Clang codegen tests should not depend
on llvm middle-end behaviour, they should *only* test clang codegen.
Yet this test runs whole optimization pipeline.
I've really tried to fix it, but there isn't just a few things
that depend on passes, but everything there does.

Modified:
cfe/trunk/test/CodeGen/arm_acle.c

Modified: cfe/trunk/test/CodeGen/arm_acle.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm_acle.c?rev=372015&r1=372014&r2=372015&view=diff
==
--- cfe/trunk/test/CodeGen/arm_acle.c (original)
+++ cfe/trunk/test/CodeGen/arm_acle.c Mon Sep 16 10:46:08 2019
@@ -6,6 +6,8 @@
 // RUN: %clang_cc1 -ffreestanding -triple aarch64-eabi -target-cpu cortex-a57 
-target-feature +v8.4a -O2 -fexperimental-new-pass-manager -S -emit-llvm -o - 
%s | FileCheck %s -check-prefix=AArch64-v8_3
 // RUN: %clang_cc1 -ffreestanding -triple aarch64-eabi -target-cpu cortex-a57 
-target-feature +v8.5a -O2 -fexperimental-new-pass-manager -S -emit-llvm -o - 
%s | FileCheck %s -check-prefix=AArch64-v8_3
 
+// REQUIRES: rewrite
+
 #include 
 
 /* 8 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */


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


[PATCH] D67627: Clang-format: Add Whitesmiths indentation style

2019-09-16 Thread Tim Wojtulewicz via Phabricator via cfe-commits
timwoj created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds support for the Whitesmiths indentation style to clang-format. 
It’s an update to a patch submitted in 2015 (D6833 
), but reworks it to use the newer API.

There are still some issues with this patch, primarily around `switch` and 
`case` support. The added unit test won’t currently pass because of the 
remaining issues.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67627

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2401,6 +2401,16 @@
"  // something\n"
"}",
Style);
+  Style.BreakBeforeBraces = FormatStyle::BS_Whitesmiths;
+  verifyFormat("try\n"
+   "  {\n"
+   "  // something white\n"
+   "  }\n"
+   "catch (...)\n"
+   "  {\n"
+   "  // something white\n"
+   "  }",
+   Style);
   Style.BreakBeforeBraces = FormatStyle::BS_GNU;
   verifyFormat("try\n"
"  {\n"
@@ -4880,6 +4890,13 @@
"}",
Style);
 
+  Style.BreakBeforeBraces = FormatStyle::BS_Whitesmiths;
+  verifyFormat("void someLongFunction(\n"
+   "int someLongParameter) const\n"
+   "  {\n"
+   "  }",
+   Style);
+
   // Unless these are unknown annotations.
   verifyFormat("void SomeFunction(aa aaa,\n"
"  aa aaa)\n"
@@ -11347,6 +11364,238 @@
BreakBeforeBraceShortIfs);
 }
 
+TEST_F(FormatTest, WhitesmithsBraceBreaking) {
+  FormatStyle WhitesmithsBraceStyle = getLLVMStyle();
+  WhitesmithsBraceStyle.BreakBeforeBraces = FormatStyle::BS_Whitesmiths;
+
+  // Make a few changes to the style for testing purposes
+  WhitesmithsBraceStyle.AllowShortFunctionsOnASingleLine =
+  FormatStyle::SFS_Empty;
+  WhitesmithsBraceStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_None;
+  WhitesmithsBraceStyle.ColumnLimit = 0;
+
+  verifyFormat("class A;\n"
+   "namespace B\n"
+   "  {\n"
+   "class C;\n"
+   "// Comment\n"
+   "class D\n"
+   "  {\n"
+   "public:\n"
+   "  D();\n"
+   "  ~D() {}\n"
+   "private:\n"
+   "  enum E\n"
+   "{\n"
+   "F\n"
+   "}\n"
+   "  };\n"
+   "  } // namespace B\n",
+   WhitesmithsBraceStyle);
+
+  verifyFormat("namespace a\n"
+   "  {\n"
+   "class A\n"
+   "  {\n"
+   "  void f()\n"
+   "{\n"
+   "if (true)\n"
+   "  {\n"
+   "  a();\n"
+   "  b();\n"
+   "  }\n"
+   "}\n"
+   "  void g()\n"
+   "{\n"
+   "return;\n"
+   "}\n"
+   "  };\n"
+   "struct B\n"
+   "  {\n"
+   "  int x;\n"
+   "  };\n"
+   "  } // namespace a",
+   WhitesmithsBraceStyle);
+
+  verifyFormat("void f()\n"
+   "  {\n"
+   "  if (true)\n"
+   "{\n"
+   "a();\n"
+   "}\n"
+   "  else if (false)\n"
+   "{\n"
+   "b();\n"
+   "}\n"
+   "  else\n"
+   "{\n"
+   "c();\n"
+   "}\n"
+   "  }\n",
+   WhitesmithsBraceStyle);
+
+  verifyFormat("void f()\n"
+   "  {\n"
+   "  for (int i = 0; i < 10; ++i)\n"
+   "{\n"
+   "a();\n"
+   "}\n"
+   "  while (false)\n"
+   "{\n"
+   "b();\n"
+   "}\n"
+   "  do\n"
+   "{\n"
+   "c();\n"
+   "} while (false)\n"
+   "  }\n",
+   WhitesmithsBraceStyle);
+
+  verifyFormat("void f(int a)\n"
+   "  {\n"
+   "  switch (a)\n"
+   "{\n"
+   "case 2:\n"
+   "  {\n"
+   "  }\n"
+   "  break;\n"
+   "}\n"
+   "  }\n",
+   WhitesmithsBraceStyle);
+

[PATCH] D41217: [Concepts] Concept Specialization Expressions

2019-09-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith marked an inline comment as done.
rsmith added inline comments.



Comment at: include/clang/Sema/Sema.h:5904
+ Expr *ConstraintExpr,
+ bool &IsSatisfied);
+

(Nit: please align the second and subsequent parameters here with the first 
one.)



Comment at: include/clang/Sema/Sema.h:7487-7488
 
+  // We are checking the constraints associated with a constrained entity 
or
+  // the constraint expression of a concept.
+  ConstraintsCheck,

It'd be useful to note that this context covers the check that atomic 
constraints have type `bool` and can be constant-evaluated. (It's not obvious 
how we'd hit diagnostics in this case, since most substitution failures result 
in an unsatisfied constraint.)



Comment at: lib/AST/ExprCXX.cpp:1703-1704
+  bool IsDependent = false;
+  bool IsInstantiationDependent = false;
+  bool ContainsUnexpandedParameterPack = false;
+  for (const TemplateArgumentLoc& LocInfo : ArgsAsWritten->arguments()) {

It'd be nice to assert that the nested name specifier is neither 
instantiation-dependent nor contains an unexpanded parameter pack. (That's true 
today because the NNS of a concept specialization expression can only refer to 
a namespace.) If the NNS could be instantiation-dependent or contain an 
unexpanded pack, we should inherit those properties here.



Comment at: lib/AST/ExprCXX.cpp:1708-1709
+  IsDependent = true;
+  if (ContainsUnexpandedParameterPack && IsInstantiationDependent)
+break;
+}

This code would be a little clearer if you moved an `if (IsDependent && 
ContainsUnexpandedParameterPack && IsInstantiationDependent)` check to the end 
of the loop. (I doubt the change will ever make any performance difference.)



Comment at: lib/AST/StmtProfile.cpp:1303-1305
+  VisitDecl(S->getNamedConcept());
+  VisitTemplateArguments(S->getTemplateArgsAsWritten()->getTemplateArgs(),
+ S->getTemplateArgsAsWritten()->NumTemplateArgs);

It seems a little inconsistent to use the named concept rather than the found 
decl (that is, resolved rather than as-written), but to use the as-written 
template arguments rather than the resolved and converted arguments. (I don't 
think it matters either way, since the profiler is in principle allowed to use 
either the as-written or resolved form, but generally it should prefer to use 
the as-written form.)



Comment at: lib/Sema/SemaConcept.cpp:34
+  Diag(ConstraintExpression->getExprLoc(),
+   diag::err_non_bool_atomic_constraint)
+  << ConstraintExpression << ConstraintExpression->getType();

saar.raz wrote:
> saar.raz wrote:
> > rsmith wrote:
> > > What justifies rejecting this prior to any use of the concept that would 
> > > result in a satisfaction check?
> > > 
> > > (I think checking this is a good thing; what I'm wondering is whether we 
> > > need to file a core issue to get the wording updated to allow us to 
> > > reject such bogus concepts even if they're never used.)
> > I guess this is already justified, if awkwardly (NDR) by [temp.res]p8.2
> Correction - it says that IFNDR occurs when no substitution would result in a 
> valid expression, so maybe this is well formed after all.
> In this case it is a valid expression but not a valid constraint expression, 
> maybe that's the missing word here?
OK, I'll take this to the core reflector to make sure the wording is clear this 
is ill-formed, no diagnostic required.



Comment at: lib/Sema/SemaConcept.cpp:37-41
+} else if (ImplicitCastExpr *E =
+ dyn_cast(ConstraintExpression)) 
{
+  // This will catch expressions such as '2 && true'
+  return CheckConstraintExpression(E->getSubExpr());
+}

rsmith wrote:
> Call `IgnoreParenImpCasts` before checking the type of an atomic constraint, 
> rather than adding an extra recursive step here.
I think we're missing this, and we won't reject:

```
template concept bool X = true && (0 && 0);
```

because we treat `(0 && 0)` as an atomic constraint rather than treating the 
two `0` subexpressions as atomic constraints here.

(Maybe add `ConstraintExpression = 
ConstraintExpression->IgnoreParenImpCasts();` or something like that to the 
start of the function?)



Comment at: lib/Sema/SemaConcept.cpp:29
+  return CheckConstraintExpression(BinOp->getLHS()) &&
+  CheckConstraintExpression(BinOp->getRHS());
+

Nit: indent the second line so that the two `CheckConstraintExpression` calls 
line up.



Comment at: lib/Sema/SemaConcept.cpp:51-68
+  if (auto *BO = dyn_cast(ConstraintExpr)) {
+if (BO->getOpcode() == BO_LAnd) {
+  if (CalculateConstraintSatisfaction

Re: r372015 - [Clang][Codegen] Disable arm_acle.c test.

2019-09-16 Thread Nico Weber via cfe-commits
CodeGen/ARM/CGP/arm-gcp-casts.ll is broken too.

On Mon, Sep 16, 2019 at 1:44 PM Roman Lebedev via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: lebedevri
> Date: Mon Sep 16 10:46:08 2019
> New Revision: 372015
>
> URL: http://llvm.org/viewvc/llvm-project?rev=372015&view=rev
> Log:
> [Clang][Codegen] Disable arm_acle.c test.
>
> This test is broken by design. Clang codegen tests should not depend
> on llvm middle-end behaviour, they should *only* test clang codegen.
> Yet this test runs whole optimization pipeline.
> I've really tried to fix it, but there isn't just a few things
> that depend on passes, but everything there does.
>
> Modified:
> cfe/trunk/test/CodeGen/arm_acle.c
>
> Modified: cfe/trunk/test/CodeGen/arm_acle.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm_acle.c?rev=372015&r1=372014&r2=372015&view=diff
>
> ==
> --- cfe/trunk/test/CodeGen/arm_acle.c (original)
> +++ cfe/trunk/test/CodeGen/arm_acle.c Mon Sep 16 10:46:08 2019
> @@ -6,6 +6,8 @@
>  // RUN: %clang_cc1 -ffreestanding -triple aarch64-eabi -target-cpu
> cortex-a57 -target-feature +v8.4a -O2 -fexperimental-new-pass-manager -S
> -emit-llvm -o - %s | FileCheck %s -check-prefix=AArch64-v8_3
>  // RUN: %clang_cc1 -ffreestanding -triple aarch64-eabi -target-cpu
> cortex-a57 -target-feature +v8.5a -O2 -fexperimental-new-pass-manager -S
> -emit-llvm -o - %s | FileCheck %s -check-prefix=AArch64-v8_3
>
> +// REQUIRES: rewrite
> +
>  #include 
>
>  /* 8 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r372015 - [Clang][Codegen] Disable arm_acle.c test.

2019-09-16 Thread Roman Lebedev via cfe-commits
Oh, that looked like it was due to r372012 but apparently it wasn't.
Fixed in r372019.
Sorry for the breakage.

Roman

On Mon, Sep 16, 2019 at 9:11 PM Nico Weber  wrote:
>
> CodeGen/ARM/CGP/arm-gcp-casts.ll is broken too.
>
> On Mon, Sep 16, 2019 at 1:44 PM Roman Lebedev via cfe-commits 
>  wrote:
>>
>> Author: lebedevri
>> Date: Mon Sep 16 10:46:08 2019
>> New Revision: 372015
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=372015&view=rev
>> Log:
>> [Clang][Codegen] Disable arm_acle.c test.
>>
>> This test is broken by design. Clang codegen tests should not depend
>> on llvm middle-end behaviour, they should *only* test clang codegen.
>> Yet this test runs whole optimization pipeline.
>> I've really tried to fix it, but there isn't just a few things
>> that depend on passes, but everything there does.
>>
>> Modified:
>> cfe/trunk/test/CodeGen/arm_acle.c
>>
>> Modified: cfe/trunk/test/CodeGen/arm_acle.c
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm_acle.c?rev=372015&r1=372014&r2=372015&view=diff
>> ==
>> --- cfe/trunk/test/CodeGen/arm_acle.c (original)
>> +++ cfe/trunk/test/CodeGen/arm_acle.c Mon Sep 16 10:46:08 2019
>> @@ -6,6 +6,8 @@
>>  // RUN: %clang_cc1 -ffreestanding -triple aarch64-eabi -target-cpu 
>> cortex-a57 -target-feature +v8.4a -O2 -fexperimental-new-pass-manager -S 
>> -emit-llvm -o - %s | FileCheck %s -check-prefix=AArch64-v8_3
>>  // RUN: %clang_cc1 -ffreestanding -triple aarch64-eabi -target-cpu 
>> cortex-a57 -target-feature +v8.5a -O2 -fexperimental-new-pass-manager -S 
>> -emit-llvm -o - %s | FileCheck %s -check-prefix=AArch64-v8_3
>>
>> +// REQUIRES: rewrite
>> +
>>  #include 
>>
>>  /* 8 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67590: Properly ignore mismatched exception specifiers in MSVC Compat mode.

2019-09-16 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:3565-3572
+if (OldQTypeForComparison == NewQType ||
+// In Microsoft compatibility mode, the intent is to only warn on
+// mismatched exception specifiers.  By this point, that warning has
+// already been issued, so we should treat mismatches only in exception
+// specifier as equivalent.
+(getLangOpts().MSVCCompat &&
+ 
Context.hasSameFunctionTypeIgnoringExceptionSpec(OldQTypeForComparison,

I wonder if we should simplify this to just call 
`hasSameFunctionTypeIgnoringExceptionSpec` in all modes. Essentially, just 
trust that CheckExceptionSpecification did the right thing, in case it returns 
false for other reasons in the future. It might actually be better for error 
recovery, for example, to continue adding this overload when exception 
specifications don't match. I'll try that and see if it passes tests.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67590/new/

https://reviews.llvm.org/D67590



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


Re: r372015 - [Clang][Codegen] Disable arm_acle.c test.

2019-09-16 Thread Nico Weber via cfe-commits
Bots look happy again. Thanks for the quick fix :)

On Mon, Sep 16, 2019 at 2:27 PM Roman Lebedev  wrote:

> Oh, that looked like it was due to r372012 but apparently it wasn't.
> Fixed in r372019.
> Sorry for the breakage.
>
> Roman
>
> On Mon, Sep 16, 2019 at 9:11 PM Nico Weber  wrote:
> >
> > CodeGen/ARM/CGP/arm-gcp-casts.ll is broken too.
> >
> > On Mon, Sep 16, 2019 at 1:44 PM Roman Lebedev via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >>
> >> Author: lebedevri
> >> Date: Mon Sep 16 10:46:08 2019
> >> New Revision: 372015
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=372015&view=rev
> >> Log:
> >> [Clang][Codegen] Disable arm_acle.c test.
> >>
> >> This test is broken by design. Clang codegen tests should not depend
> >> on llvm middle-end behaviour, they should *only* test clang codegen.
> >> Yet this test runs whole optimization pipeline.
> >> I've really tried to fix it, but there isn't just a few things
> >> that depend on passes, but everything there does.
> >>
> >> Modified:
> >> cfe/trunk/test/CodeGen/arm_acle.c
> >>
> >> Modified: cfe/trunk/test/CodeGen/arm_acle.c
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm_acle.c?rev=372015&r1=372014&r2=372015&view=diff
> >>
> ==
> >> --- cfe/trunk/test/CodeGen/arm_acle.c (original)
> >> +++ cfe/trunk/test/CodeGen/arm_acle.c Mon Sep 16 10:46:08 2019
> >> @@ -6,6 +6,8 @@
> >>  // RUN: %clang_cc1 -ffreestanding -triple aarch64-eabi -target-cpu
> cortex-a57 -target-feature +v8.4a -O2 -fexperimental-new-pass-manager -S
> -emit-llvm -o - %s | FileCheck %s -check-prefix=AArch64-v8_3
> >>  // RUN: %clang_cc1 -ffreestanding -triple aarch64-eabi -target-cpu
> cortex-a57 -target-feature +v8.5a -O2 -fexperimental-new-pass-manager -S
> -emit-llvm -o - %s | FileCheck %s -check-prefix=AArch64-v8_3
> >>
> >> +// REQUIRES: rewrite
> >> +
> >>  #include 
> >>
> >>  /* 8 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
> >>
> >>
> >> ___
> >> cfe-commits mailing list
> >> cfe-commits@lists.llvm.org
> >> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67590: Properly ignore mismatched exception specifiers in MSVC Compat mode.

2019-09-16 Thread Alex Fusco via Phabricator via cfe-commits
alexfusco updated this revision to Diff 220367.
alexfusco added a comment.

Updated to unconditionally ignore the exception spec here, since it has already 
been compared.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67590/new/

https://reviews.llvm.org/D67590

Files:
  lib/Sema/SemaDecl.cpp
  test/SemaCXX/ms-ignore-mismatched-except-specifier.cpp


Index: test/SemaCXX/ms-ignore-mismatched-except-specifier.cpp
===
--- /dev/null
+++ test/SemaCXX/ms-ignore-mismatched-except-specifier.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -std=c++1z -fms-extensions -fms-compatibility
+
+template  struct FooPtr {
+  template  FooPtr(U *p) : m_pT(nullptr) {}
+  template <> FooPtr(T *pInterface) throw() : m_pT(pInterface) {}  // 
expected-warning {{exception specification in declaration does not match 
previous declaration}}
+  T *m_pT;
+};
+struct Bar{};
+template struct FooPtr;
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -3562,7 +3562,12 @@
   }
 }
 
-if (OldQTypeForComparison == NewQType)
+// Exception specifiers have already been compared here so ignore them for
+// the purposes of this comparison. Microsoft compatability mode explicitly
+// downgrades such mismatches to a warning and we shouldn't make it an 
error
+// here.
+if (Context.hasSameFunctionTypeIgnoringExceptionSpec(OldQTypeForComparison,
+ NewQType))
   return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
 
 // If the types are imprecise (due to dependent constructs in friends or


Index: test/SemaCXX/ms-ignore-mismatched-except-specifier.cpp
===
--- /dev/null
+++ test/SemaCXX/ms-ignore-mismatched-except-specifier.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -std=c++1z -fms-extensions -fms-compatibility
+
+template  struct FooPtr {
+  template  FooPtr(U *p) : m_pT(nullptr) {}
+  template <> FooPtr(T *pInterface) throw() : m_pT(pInterface) {}  // expected-warning {{exception specification in declaration does not match previous declaration}}
+  T *m_pT;
+};
+struct Bar{};
+template struct FooPtr;
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -3562,7 +3562,12 @@
   }
 }
 
-if (OldQTypeForComparison == NewQType)
+// Exception specifiers have already been compared here so ignore them for
+// the purposes of this comparison. Microsoft compatability mode explicitly
+// downgrades such mismatches to a warning and we shouldn't make it an error
+// here.
+if (Context.hasSameFunctionTypeIgnoringExceptionSpec(OldQTypeForComparison,
+ NewQType))
   return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
 
 // If the types are imprecise (due to dependent constructs in friends or
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r372026 - do not emit -Wunused-macros warnings in -frewrite-includes mode (PR15614)

2019-09-16 Thread Lubos Lunak via cfe-commits
Author: llunak
Date: Mon Sep 16 12:18:37 2019
New Revision: 372026

URL: http://llvm.org/viewvc/llvm-project?rev=372026&view=rev
Log:
do not emit -Wunused-macros warnings in -frewrite-includes mode (PR15614)

-frewrite-includes calls PP.SetMacroExpansionOnlyInDirectives() to avoid
macro expansions that are useless in that mode, but this can lead
to -Wunused-macros false positives. As -frewrite-includes does not emit
normal warnings, block -Wunused-macros too.

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

Modified:
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/test/Frontend/rewrite-includes-warnings.c

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=372026&r1=372025&r2=372026&view=diff
==
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Mon Sep 16 12:18:37 2019
@@ -2782,7 +2782,8 @@ void Preprocessor::HandleDefineDirective
   // If we need warning for not using the macro, add its location in the
   // warn-because-unused-macro set. If it gets used it will be removed from 
set.
   if (getSourceManager().isInMainFile(MI->getDefinitionLoc()) &&
-  !Diags->isIgnored(diag::pp_macro_not_used, MI->getDefinitionLoc())) {
+  !Diags->isIgnored(diag::pp_macro_not_used, MI->getDefinitionLoc()) &&
+  !MacroExpansionInDirectivesOverride) {
 MI->setIsWarnIfUnused(true);
 WarnUnusedMacroLocs.insert(MI->getDefinitionLoc());
   }

Modified: cfe/trunk/test/Frontend/rewrite-includes-warnings.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/rewrite-includes-warnings.c?rev=372026&r1=372025&r2=372026&view=diff
==
--- cfe/trunk/test/Frontend/rewrite-includes-warnings.c (original)
+++ cfe/trunk/test/Frontend/rewrite-includes-warnings.c Mon Sep 16 12:18:37 2019
@@ -1,4 +1,7 @@
-// RUN: %clang_cc1 -verify -Wall -Wextra -E -frewrite-includes %s
+// RUN: %clang_cc1 -verify -Wall -Wextra -Wunused-macros -E -frewrite-includes 
%s
 // expected-no-diagnostics
 
 #pragma GCC visibility push (default)
+
+#define USED_MACRO 1
+int test() { return USED_MACRO; }


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


[PATCH] D53768: Add VerboseOutputStream to CompilerInstance

2019-09-16 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 220369.
scott.linder edited the summary of this revision.
scott.linder added reviewers: ddunbar, aprantl, cfang, dblaikie.
scott.linder added a comment.

Rebase and ping


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53768/new/

https://reviews.llvm.org/D53768

Files:
  include/clang/Frontend/CompilerInstance.h
  lib/Frontend/CompilerInstance.cpp
  unittests/Frontend/OutputStreamTest.cpp

Index: unittests/Frontend/OutputStreamTest.cpp
===
--- unittests/Frontend/OutputStreamTest.cpp
+++ unittests/Frontend/OutputStreamTest.cpp
@@ -10,6 +10,7 @@
 #include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/CodeGenAction.h"
 #include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/FrontendTool/Utils.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "gtest/gtest.h"
@@ -43,4 +44,29 @@
   EXPECT_TRUE(!IRBuffer.empty());
   EXPECT_TRUE(StringRef(IRBuffer.data()).startswith("BC"));
 }
+
+TEST(FrontendOutputTests, TestVerboseOutputStream) {
+  auto Invocation = std::make_shared();
+  Invocation->getPreprocessorOpts().addRemappedFile(
+  "test.cc", MemoryBuffer::getMemBuffer("invalid").release());
+  Invocation->getFrontendOpts().Inputs.push_back(
+  FrontendInputFile("test.cc", InputKind::CXX));
+  Invocation->getFrontendOpts().ProgramAction = EmitBC;
+  Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu";
+  CompilerInstance Compiler;
+
+  std::string VerboseBuffer;
+  raw_string_ostream VerboseStream(VerboseBuffer);
+
+  Compiler.setInvocation(std::move(Invocation));
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  Compiler.createDiagnostics(
+  new TextDiagnosticPrinter(llvm::nulls(), &*DiagOpts), true);
+  Compiler.setVerboseOutputStream(VerboseStream);
+
+  bool Success = ExecuteCompilerInvocation(&Compiler);
+  EXPECT_FALSE(Success);
+  EXPECT_TRUE(!VerboseStream.str().empty());
+  EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated"));
+}
 }
Index: lib/Frontend/CompilerInstance.cpp
===
--- lib/Frontend/CompilerInstance.cpp
+++ lib/Frontend/CompilerInstance.cpp
@@ -68,6 +68,8 @@
 
 CompilerInstance::~CompilerInstance() {
   assert(OutputFiles.empty() && "Still output files in flight?");
+  if (OwnsVerboseOutputStream)
+delete VerboseOutputStream;
 }
 
 void CompilerInstance::setInvocation(
@@ -86,6 +88,12 @@
   Diagnostics = Value;
 }
 
+void CompilerInstance::setVerboseOutputStream(raw_ostream &Value,
+  bool OwnsOutputStream) {
+  OwnsVerboseOutputStream = OwnsOutputStream;
+  VerboseOutputStream = &Value;
+}
+
 void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; }
 void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; }
 
@@ -897,9 +905,7 @@
   // DesiredStackSpace available.
   noteBottomOfStack();
 
-  // FIXME: Take this as an argument, once all the APIs we used have moved to
-  // taking it as an input instead of hard-coding llvm::errs.
-  raw_ostream &OS = llvm::errs();
+  raw_ostream &OS = getVerboseOutputStream();
 
   if (!Act.PrepareToExecute(*this))
 return false;
Index: include/clang/Frontend/CompilerInstance.h
===
--- include/clang/Frontend/CompilerInstance.h
+++ include/clang/Frontend/CompilerInstance.h
@@ -155,6 +155,12 @@
   /// One or more modules failed to build.
   bool ModuleBuildFailed = false;
 
+  /// Whether we should delete VerboseOutputStream on destruction.
+  bool OwnsVerboseOutputStream = false;
+
+  /// The stream for verbose output.
+  raw_ostream *VerboseOutputStream = &llvm::errs();
+
   /// Holds information about the output file.
   ///
   /// If TempFilename is not empty we must rename it to Filename at the end.
@@ -217,9 +223,6 @@
   /// \param Act - The action to execute.
   /// \return - True on success.
   //
-  // FIXME: This function should take the stream to write any debugging /
-  // verbose output to as an argument.
-  //
   // FIXME: Eliminate the llvm_shutdown requirement, that should either be part
   // of the context or else not CompilerInstance specific.
   bool ExecuteAction(FrontendAction &Act);
@@ -349,6 +352,21 @@
 return *Diagnostics->getClient();
   }
 
+  /// }
+  /// @name VerboseOutputStream
+  /// }
+
+  /// Replace the current stream for verbose output.
+  ///
+  /// If not set, this stream defaults to \c llvm::errs().
+  void setVerboseOutputStream(raw_ostream &Value,
+  bool OwnsOutputStream = false);
+
+  /// Get the current stream for verbose output.
+  raw_ostream &getVerboseOutputStream() {
+return *VerboseOutputStream;
+  }
+
   /// }
   /// @name Target Info
   /// {
___
cfe-commits mailing list
cfe-commits@lists.

[PATCH] D65371: do not emit -Wunused-macros warnings in -frewrite-includes mode (PR15614)

2019-09-16 Thread Luboš Luňák via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa507a5ec8f1d: do not emit -Wunused-macros warnings in 
-frewrite-includes mode (PR15614) (authored by llunak).

Changed prior to commit:
  https://reviews.llvm.org/D65371?vs=219370&id=220370#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65371/new/

https://reviews.llvm.org/D65371

Files:
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Frontend/rewrite-includes-warnings.c


Index: clang/test/Frontend/rewrite-includes-warnings.c
===
--- clang/test/Frontend/rewrite-includes-warnings.c
+++ clang/test/Frontend/rewrite-includes-warnings.c
@@ -1,4 +1,7 @@
-// RUN: %clang_cc1 -verify -Wall -Wextra -E -frewrite-includes %s
+// RUN: %clang_cc1 -verify -Wall -Wextra -Wunused-macros -E -frewrite-includes 
%s
 // expected-no-diagnostics
 
 #pragma GCC visibility push (default)
+
+#define USED_MACRO 1
+int test() { return USED_MACRO; }
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -2782,7 +2782,8 @@
   // If we need warning for not using the macro, add its location in the
   // warn-because-unused-macro set. If it gets used it will be removed from 
set.
   if (getSourceManager().isInMainFile(MI->getDefinitionLoc()) &&
-  !Diags->isIgnored(diag::pp_macro_not_used, MI->getDefinitionLoc())) {
+  !Diags->isIgnored(diag::pp_macro_not_used, MI->getDefinitionLoc()) &&
+  !MacroExpansionInDirectivesOverride) {
 MI->setIsWarnIfUnused(true);
 WarnUnusedMacroLocs.insert(MI->getDefinitionLoc());
   }


Index: clang/test/Frontend/rewrite-includes-warnings.c
===
--- clang/test/Frontend/rewrite-includes-warnings.c
+++ clang/test/Frontend/rewrite-includes-warnings.c
@@ -1,4 +1,7 @@
-// RUN: %clang_cc1 -verify -Wall -Wextra -E -frewrite-includes %s
+// RUN: %clang_cc1 -verify -Wall -Wextra -Wunused-macros -E -frewrite-includes %s
 // expected-no-diagnostics
 
 #pragma GCC visibility push (default)
+
+#define USED_MACRO 1
+int test() { return USED_MACRO; }
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -2782,7 +2782,8 @@
   // If we need warning for not using the macro, add its location in the
   // warn-because-unused-macro set. If it gets used it will be removed from set.
   if (getSourceManager().isInMainFile(MI->getDefinitionLoc()) &&
-  !Diags->isIgnored(diag::pp_macro_not_used, MI->getDefinitionLoc())) {
+  !Diags->isIgnored(diag::pp_macro_not_used, MI->getDefinitionLoc()) &&
+  !MacroExpansionInDirectivesOverride) {
 MI->setIsWarnIfUnused(true);
 WarnUnusedMacroLocs.insert(MI->getDefinitionLoc());
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67627: Clang-format: Add Whitesmiths indentation style

2019-09-16 Thread Eric Christopher via Phabricator via cfe-commits
echristo added reviewers: mboehme, krasimir.
echristo added a comment.

Martin should know who should look at this... maybe Krasimir?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67627/new/

https://reviews.llvm.org/D67627



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


[PATCH] D67590: Properly ignore mismatched exception specifiers in MSVC Compat mode.

2019-09-16 Thread Reid Kleckner via Phabricator via cfe-commits
rnk commandeered this revision.
rnk edited reviewers, added: alexfusco; removed: rnk.
rnk added a comment.

Taking this to move the test around and try the other version...


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67590/new/

https://reviews.llvm.org/D67590



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


[PATCH] D67590: Properly ignore mismatched exception specifiers in MSVC Compat mode.

2019-09-16 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 220376.
rnk added a comment.

- move test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67590/new/

https://reviews.llvm.org/D67590

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/ms-exception-spec.cpp


Index: clang/test/SemaCXX/ms-exception-spec.cpp
===
--- clang/test/SemaCXX/ms-exception-spec.cpp
+++ clang/test/SemaCXX/ms-exception-spec.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-compatibility -fexceptions 
-fcxx-exceptions
+// RUN: %clang_cc1 -std=c++11 %s -fsyntax-only -verify -fms-compatibility 
-fexceptions -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++17 %s -fsyntax-only -verify -fms-compatibility 
-fexceptions -fcxx-exceptions
 
 void f() throw(...) { }
 
@@ -7,3 +8,11 @@
 void fn() throw(S); // expected-warning {{incomplete type}} 
expected-note{{previous declaration}}
 void fn() throw();  // expected-warning {{does not match previous declaration}}
 }
+
+template  struct FooPtr {
+  template  FooPtr(U *p) : m_pT(nullptr) {}
+  template <> FooPtr(T *pInterface) throw() : m_pT(pInterface) {}  // 
expected-warning {{exception specification in declaration does not match 
previous declaration}}
+  T *m_pT;
+};
+struct Bar {};
+template struct FooPtr;
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -3562,7 +3562,14 @@
   }
 }
 
-if (OldQTypeForComparison == NewQType)
+if (OldQTypeForComparison == NewQType ||
+// In Microsoft compatibility mode, the intent is to only warn on
+// mismatched exception specifiers.  By this point, that warning has
+// already been issued, so we should treat mismatches only in exception
+// specifier as equivalent.
+(getLangOpts().MSVCCompat &&
+ 
Context.hasSameFunctionTypeIgnoringExceptionSpec(OldQTypeForComparison,
+  NewQType)))
   return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
 
 // If the types are imprecise (due to dependent constructs in friends or


Index: clang/test/SemaCXX/ms-exception-spec.cpp
===
--- clang/test/SemaCXX/ms-exception-spec.cpp
+++ clang/test/SemaCXX/ms-exception-spec.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-compatibility -fexceptions -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++11 %s -fsyntax-only -verify -fms-compatibility -fexceptions -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++17 %s -fsyntax-only -verify -fms-compatibility -fexceptions -fcxx-exceptions
 
 void f() throw(...) { }
 
@@ -7,3 +8,11 @@
 void fn() throw(S); // expected-warning {{incomplete type}} expected-note{{previous declaration}}
 void fn() throw();  // expected-warning {{does not match previous declaration}}
 }
+
+template  struct FooPtr {
+  template  FooPtr(U *p) : m_pT(nullptr) {}
+  template <> FooPtr(T *pInterface) throw() : m_pT(pInterface) {}  // expected-warning {{exception specification in declaration does not match previous declaration}}
+  T *m_pT;
+};
+struct Bar {};
+template struct FooPtr;
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -3562,7 +3562,14 @@
   }
 }
 
-if (OldQTypeForComparison == NewQType)
+if (OldQTypeForComparison == NewQType ||
+// In Microsoft compatibility mode, the intent is to only warn on
+// mismatched exception specifiers.  By this point, that warning has
+// already been issued, so we should treat mismatches only in exception
+// specifier as equivalent.
+(getLangOpts().MSVCCompat &&
+ Context.hasSameFunctionTypeIgnoringExceptionSpec(OldQTypeForComparison,
+  NewQType)))
   return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
 
 // If the types are imprecise (due to dependent constructs in friends or
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63508: make -frewrite-includes also rewrite conditions in #if/#elif

2019-09-16 Thread Luboš Luňák via Phabricator via cfe-commits
llunak updated this revision to Diff 220378.
llunak added a comment.

- updated to apply to current trunk
- changed misleading condition in a test


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63508/new/

https://reviews.llvm.org/D63508

Files:
  clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
  clang/test/Frontend/rewrite-includes-conditions.c
  clang/test/Frontend/rewrite-includes.c
  clang/test/Modules/preprocess-module.cpp

Index: clang/test/Modules/preprocess-module.cpp
===
--- clang/test/Modules/preprocess-module.cpp
+++ clang/test/Modules/preprocess-module.cpp
@@ -51,7 +51,7 @@
 // RUN: %clang_cc1 -fmodules -fmodule-file=%t/file.rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DFILE_REWRITE -DINCLUDE -I%S/Inputs/preprocess
 //
 // Check that we can preprocess this user of the .pcm file.
-// RUN: %clang_cc1 -fmodules -fmodule-file=%t/file.pcm %s -I%t -E -frewrite-imports -o %t/preprocess-module.ii
+// RUN: %clang_cc1 -fmodules -fmodule-file=%t/file.pcm %s -I%t -E -frewrite-imports -DFILE_REWRITE_FULL -o %t/preprocess-module.ii
 // RUN: %clang_cc1 -fmodules %t/preprocess-module.ii -verify -fno-modules-error-recovery -DFILE_REWRITE_FULL
 //
 // Check that language / header search options are ignored when preprocessing from a .pcm file.
Index: clang/test/Frontend/rewrite-includes.c
===
--- clang/test/Frontend/rewrite-includes.c
+++ clang/test/Frontend/rewrite-includes.c
@@ -110,12 +110,27 @@
 // CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
 // CHECK-NEXT: {{^}}# 22 "{{.*}}rewrite-includes.c"{{$}}
 // CHECK-NEXT: {{^}}# 1 "{{.*[/\\]Inputs(/|)}}rewrite-includes8.h" 1{{$}}
-// CHECK-NEXT: {{^}}#if (0)/*__has_include_next()*/{{$}}
-// CHECK-NEXT: {{^}}#elif (0)/*__has_include()*/{{$}}
+// CHECK-NEXT: {{^}}#if 0 /* disabled by -frewrite-includes */{{$}}
+// CHECK-NEXT: {{^}}#if __has_include_next(){{$}}
+// CHECK-NEXT: {{^}}#endif{{$}}
+// CHECK-NEXT: {{^}}#endif /* disabled by -frewrite-includes */{{$}}
+// CHECK-NEXT: {{^}}#if 0 /* evaluated by -frewrite-includes */{{$}}
+// CHECK-NEXT: {{^}}# 2 "{{.*[/\\]Inputs(/|)}}rewrite-includes8.h"{{$}}
+// CHECK-NEXT: {{^}}#if 0 /* disabled by -frewrite-includes */{{$}}
+// CHECK-NEXT: {{^}}#if 0{{$}}
+// CHECK-NEXT: {{^}}#elif __has_include(){{$}}
+// CHECK-NEXT: {{^}}#endif{{$}}
+// CHECK-NEXT: {{^}}#endif /* disabled by -frewrite-includes */{{$}}
+// CHECK-NEXT: {{^}}#elif 0 /* evaluated by -frewrite-includes */{{$}}
 // CHECK-NEXT: {{^}}# 3 "{{.*[/\\]Inputs(/|)}}rewrite-includes8.h"{{$}}
 // CHECK-NEXT: {{^}}#endif{{$}}
 // CHECK-NEXT: {{^}}# 4 "{{.*[/\\]Inputs(/|)}}rewrite-includes8.h"{{$}}
-// CHECK-NEXT: {{^}}#if !(1)/*__has_include("rewrite-includes8.h")*/{{$}}
+// CHECK-NEXT: {{^}}#if 0 /* disabled by -frewrite-includes */{{$}}
+// CHECK-NEXT: {{^}}#if !__has_include("rewrite-includes8.h"){{$}}
+// CHECK-NEXT: {{^}}#endif{{$}}
+// CHECK-NEXT: {{^}}#endif /* disabled by -frewrite-includes */{{$}}
+// CHECK-NEXT: {{^}}#if 0 /* evaluated by -frewrite-includes */{{$}}
+// CHECK-NEXT: {{^}}# 5 "{{.*[/\\]Inputs(/|)}}rewrite-includes8.h"{{$}}
 // CHECK-NEXT: {{^}}#endif{{$}}
 // CHECK-NEXT: {{^}}# 6 "{{.*[/\\]Inputs(/|)}}rewrite-includes8.h"{{$}}
 // CHECK-NEXT: {{^}}# 23 "{{.*}}rewrite-includes.c" 2{{$}}
@@ -124,7 +139,12 @@
 // CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
 // CHECK-NEXT: {{^}}# 23 "{{.*}}rewrite-includes.c"{{$}}
 // CHECK-NEXT: {{^}}# 1 "{{.*[/\\]Inputs(/|)}}rewrite-includes9.h" 1{{$}}
-// CHECK-NEXT: {{^}}#if (1)/*__has_include_next()*/{{$}}
+// CHECK-NEXT: {{^}}#if 0 /* disabled by -frewrite-includes */{{$}}
+// CHECK-NEXT: {{^}}#if __has_include_next(){{$}}
+// CHECK-NEXT: {{^}}#endif{{$}}
+// CHECK-NEXT: {{^}}#endif /* disabled by -frewrite-includes */{{$}}
+// CHECK-NEXT: {{^}}#if 1 /* evaluated by -frewrite-includes */{{$}}
+// CHECK-NEXT: {{^}}# 2 "{{.*[/\\]Inputs(/|)}}rewrite-includes9.h"{{$}}
 // CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
 // CHECK-NEXT: {{^}}#include_next {{$}}
 // CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
@@ -193,15 +213,32 @@
 // CHECKNL-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
 // CHECKNL-NEXT: {{^}}#include "rewrite-includes8.h"{{$}}
 // CHECKNL-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
-// CHECKNL-NEXT: {{^}}#if (0)/*__has_include_next()*/{{$}}
-// CHECKNL-NEXT: {{^}}#elif (0)/*__has_include()*/{{$}}
+// CHECKNL-NEXT: {{^}}#if 0 /* disabled by -frewrite-includes */{{$}}
+// CHECKNL-NEXT: {{^}}#if __has_include_next(){{$}}
 // CHECKNL-NEXT: {{^}}#endif{{$}}
-// CHECKNL-NEXT: {{^}}#if !(1)/*__has_include("rewrite-includes8.h")*/{{$}}
+// CHECKNL-NEXT: {{^}}#endif /* disabled by -frewrite-includes */{{$}}
+// CHECKNL-NEXT: {{^}}#if 0 /* evaluated by -frewrite-includes */{{$}}
+// CHECKNL-NEXT: {{

[PATCH] D67629: [clang-format] Fix C# breaking before function name when using Attributes

2019-09-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: owenpan, klimek.
MyDeveloperDay added a project: clang-tools-extra.
Herald added a project: clang.

This is  a fix for https://bugs.llvm.org/show_bug.cgi?id=4

This comes with 3 main parts

- C# attributes cause function names on a new line even when 
AlwaysBreakAfterReturnType is set to None
- Add AlwaysBreakAfterReturnType  to None by default in the Microsoft style,
- C# unit tests are not using Microsoft style (which we created to define the 
default C# style to match a vanilla C# project).




Repository:
  rC Clang

https://reviews.llvm.org/D67629

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -32,48 +32,76 @@
 
   static std::string
   format(llvm::StringRef Code,
- const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_CSharp)) {
+ const FormatStyle &Style = getMicrosoftStyle(FormatStyle::LK_CSharp)) {
 return format(Code, 0, Code.size(), Style);
   }
 
   static FormatStyle getStyleWithColumns(unsigned ColumnLimit) {
-FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+FormatStyle Style = getMicrosoftStyle(FormatStyle::LK_CSharp);
 Style.ColumnLimit = ColumnLimit;
 return Style;
   }
 
   static void verifyFormat(
   llvm::StringRef Code,
-  const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_CSharp)) {
+  const FormatStyle &Style = getMicrosoftStyle(FormatStyle::LK_CSharp)) {
 EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
 EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
   }
 };
 
 TEST_F(FormatTestCSharp, CSharpClass) {
-  verifyFormat("public class SomeClass {\n"
-   "  void f() {}\n"
-   "  int g() { return 0; }\n"
-   "  void h() {\n"
-   "while (true) f();\n"
-   "for (;;) f();\n"
-   "if (true) f();\n"
-   "  }\n"
+  verifyFormat("public class SomeClass\n"
+   "{\n"
+   "void f()\n"
+   "{\n"
+   "}\n"
+   "int g()\n"
+   "{\n"
+   "return 0;\n"
+   "}\n"
+   "void h()\n"
+   "{\n"
+   "while (true)\n"
+   "f();\n"
+   "for (;;)\n"
+   "f();\n"
+   "if (true)\n"
+   "f();\n"
+   "}\n"
"}");
 }
 
 TEST_F(FormatTestCSharp, AccessModifiers) {
-  verifyFormat("public String toString() {}");
-  verifyFormat("private String toString() {}");
-  verifyFormat("protected String toString() {}");
-  verifyFormat("internal String toString() {}");
+  verifyFormat("public String toString()\n"
+   "{\n"
+   "}");
+  verifyFormat("private String toString()\n"
+   "{\n"
+   "}");
+  verifyFormat("protected String toString()\n"
+   "{\n"
+   "}");
+  verifyFormat("internal String toString()\n"
+   "{\n"
+   "}");
 
-  verifyFormat("public override String toString() {}");
-  verifyFormat("private override String toString() {}");
-  verifyFormat("protected override String toString() {}");
-  verifyFormat("internal override String toString() {}");
+  verifyFormat("public override String toString()\n"
+   "{\n"
+   "}");
+  verifyFormat("private override String toString()\n"
+   "{\n"
+   "}");
+  verifyFormat("protected override String toString()\n"
+   "{\n"
+   "}");
+  verifyFormat("internal override String toString()\n"
+   "{\n"
+   "}");
 
-  verifyFormat("internal static String toString() {}");
+  verifyFormat("internal static String toString()\n"
+   "{\n"
+   "}");
 }
 
 TEST_F(FormatTestCSharp, NoStringLiteralBreaks) {
@@ -124,45 +152,70 @@
 
   verifyFormat("switch(args?.Length)");
 
-  verifyFormat("public static void Main(string[] args) { string dirPath "
-   "= args?[0]; }");
+  verifyFormat("public static void Main(string[] args)\n"
+   "{\n"
+   "string dirPath = args?[0];\n"
+   "}");
 }
 
 TEST_F(FormatTestCSharp, Attributes) {
   verifyFormat("[STAThread]\n"
-   "static void\n"
-   "Main(string[] args) {}");
+   "static void Main(string[] args)\n"
+   "{\n"
+   "}");
 
   verifyFormat("[TestMethod]\n"
-

[PATCH] D63508: make -frewrite-includes also rewrite conditions in #if/#elif

2019-09-16 Thread Luboš Luňák via Phabricator via cfe-commits
llunak added a comment.

I've noticed that the Developer Policy says that it's actually allowed to 
commit patches without approval for parts "that you have contributed or 
maintain". Given that I'm the author of -rewrite-includes I take it that it's 
ok if I commit this if there are no further comments.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63508/new/

https://reviews.llvm.org/D63508



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


[PATCH] D67590: Properly ignore mismatched exception specifiers in MSVC Compat mode.

2019-09-16 Thread Alex Fusco via Phabricator via cfe-commits
alexfusco added inline comments.



Comment at: clang/test/SemaCXX/ms-exception-spec.cpp:2
+// RUN: %clang_cc1 -std=c++11 %s -fsyntax-only -verify -fms-compatibility 
-fexceptions -fcxx-exceptions
+// RUN: %clang_cc1 -std=c++17 %s -fsyntax-only -verify -fms-compatibility 
-fexceptions -fcxx-exceptions
 

Dynamic exception specifiers are also an error in C++17, which causes issues on 
line 4 and 8 in this invocation



Comment at: clang/test/SemaCXX/ms-exception-spec.cpp:14
+  template  FooPtr(U *p) : m_pT(nullptr) {}
+  template <> FooPtr(T *pInterface) throw() : m_pT(pInterface) {}  // 
expected-warning {{exception specification in declaration does not match 
previous declaration}}
+  T *m_pT;

There's also a (pre-existing and incorrect) note here that this is also the 
previous declaration and a note on line 18 that it's in instantiation of that 
template.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67590/new/

https://reviews.llvm.org/D67590



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


[PATCH] D59516: [analyzer] Add custom filter functions for GenericTaintChecker

2019-09-16 Thread Borsik Gábor via Phabricator via cfe-commits
boga95 updated this revision to Diff 220385.
boga95 marked 4 inline comments as done.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59516/new/

https://reviews.llvm.org/D59516

Files:
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/Taint.cpp
  clang/lib/StaticAnalyzer/Checkers/Taint.h
  clang/test/Analysis/Inputs/taint-generic-config.yaml
  clang/test/Analysis/taint-generic.c

Index: clang/test/Analysis/taint-generic.c
===
--- clang/test/Analysis/taint-generic.c
+++ clang/test/Analysis/taint-generic.c
@@ -56,6 +56,8 @@
 extern FILE *stdin;
 #endif
 
+#define bool int
+
 int fscanf(FILE *restrict stream, const char *restrict format, ...);
 int sprintf(char *str, const char *format, ...);
 void setproctitle(const char *fmt, ...);
@@ -346,6 +348,7 @@
 void myScanf(const char*, ...);
 int myPropagator(int, int*);
 int mySnprintf(char*, size_t, const char*, ...);
+bool isOutOfRange(const int*);
 void mySink(int, int, int);
 
 void testConfigurationSources1() {
@@ -372,6 +375,13 @@
   Buffer[y] = 1; // expected-warning {{Out of bound memory access }}
 }
 
+void testConfigurationFilter() {
+  int x = mySource1();
+  if (isOutOfRange(&x)) // the filter function
+return;
+  Buffer[x] = 1; // no-warning
+}
+
 void testConfigurationSinks() {
   int x = mySource1();
   mySink(x, 1, 2);
Index: clang/test/Analysis/Inputs/taint-generic-config.yaml
===
--- clang/test/Analysis/Inputs/taint-generic-config.yaml
+++ clang/test/Analysis/Inputs/taint-generic-config.yaml
@@ -36,8 +36,8 @@
 # A list of filter functions
 Filters:
   # int x; // x is tainted
-  # myFilter(&x); // x is not tainted anymore
-  - Name: myFilter
+  # isOutOfRange(&x); // x is not tainted anymore
+  - Name: isOutOfRange
 Args: [0]
 
 # A list of sink functions
Index: clang/lib/StaticAnalyzer/Checkers/Taint.h
===
--- clang/lib/StaticAnalyzer/Checkers/Taint.h
+++ clang/lib/StaticAnalyzer/Checkers/Taint.h
@@ -27,34 +27,39 @@
 static constexpr TaintTagType TaintTagGeneric = 0;
 
 /// Create a new state in which the value of the statement is marked as tainted.
-LLVM_NODISCARD ProgramStateRef
-addTaint(ProgramStateRef State, const Stmt *S, const LocationContext *LCtx,
- TaintTagType Kind = TaintTagGeneric);
+LLVM_NODISCARD ProgramStateRef addTaint(ProgramStateRef State, const Stmt *S,
+const LocationContext *LCtx,
+TaintTagType Kind = TaintTagGeneric);
 
 /// Create a new state in which the value is marked as tainted.
-LLVM_NODISCARD ProgramStateRef
-addTaint(ProgramStateRef State, SVal V,
- TaintTagType Kind = TaintTagGeneric);
+LLVM_NODISCARD ProgramStateRef addTaint(ProgramStateRef State, SVal V,
+TaintTagType Kind = TaintTagGeneric);
 
 /// Create a new state in which the symbol is marked as tainted.
-LLVM_NODISCARD ProgramStateRef
-addTaint(ProgramStateRef State, SymbolRef Sym,
- TaintTagType Kind = TaintTagGeneric);
+LLVM_NODISCARD ProgramStateRef addTaint(ProgramStateRef State, SymbolRef Sym,
+TaintTagType Kind = TaintTagGeneric);
 
 /// Create a new state in which the pointer represented by the region
 /// is marked as tainted.
-LLVM_NODISCARD ProgramStateRef
-addTaint(ProgramStateRef State, const MemRegion *R,
- TaintTagType Kind = TaintTagGeneric);
+LLVM_NODISCARD ProgramStateRef addTaint(ProgramStateRef State,
+const MemRegion *R,
+TaintTagType Kind = TaintTagGeneric);
+
+LLVM_NODISCARD ProgramStateRef removeTaint(ProgramStateRef State, SVal V);
+
+LLVM_NODISCARD ProgramStateRef removeTaint(ProgramStateRef State,
+   const MemRegion *R);
+
+LLVM_NODISCARD ProgramStateRef removeTaint(ProgramStateRef State,
+   SymbolRef Sym);
 
 /// Create a new state in a which a sub-region of a given symbol is tainted.
 /// This might be necessary when referring to regions that can not have an
 /// individual symbol, e.g. if they are represented by the default binding of
 /// a LazyCompoundVal.
-LLVM_NODISCARD ProgramStateRef
-addPartialTaint(ProgramStateRef State,
-SymbolRef ParentSym, const SubRegion *SubRegion,
-TaintTagType Kind = TaintTagGeneric);
+LLVM_NODISCARD ProgramStateRef addPartialTaint(
+ProgramStateRef State, SymbolRef ParentSym, const SubRegion *SubRegion,
+TaintTagType Kind = TaintTagGeneric);
 
 /// Check if the statement has a tainted value in the given state.
 bool isTainted(ProgramStateRef State, const Stmt *S,
@@ -99,4 +104,3 @@
 } // namespace clang
 
 #endif
-
Index: clang/lib/StaticAnalyzer/Checkers/Tain

[PATCH] D67632: [libTooling] Introduce new library of source-code builders.

2019-09-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: gribozavr.
Herald added a subscriber: mgorny.
Herald added a project: clang.

Introduces facilities for easily building source-code strings, including
idiomatic use of the address-of, dereference and member-access operators (dot
and arrow) and queries about need for parentheses.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67632

Files:
  clang/include/clang/Tooling/Refactoring/SourceCodeBuilders.h
  clang/lib/Tooling/Refactoring/CMakeLists.txt
  clang/lib/Tooling/Refactoring/SourceCodeBuilders.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/SourceCodeBuildersTest.cpp

Index: clang/unittests/Tooling/SourceCodeBuildersTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/SourceCodeBuildersTest.cpp
@@ -0,0 +1,181 @@
+//===- unittest/Tooling/SourceCodeBuildersTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/Refactoring/SourceCodeBuilders.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace tooling;
+using namespace ast_matchers;
+
+namespace {
+using MatchResult = MatchFinder::MatchResult;
+
+// Create a valid translation-unit from a statement.
+static std::string wrapSnippet(StringRef StatementCode) {
+  return ("struct S { int field; }; "
+  "S operator+(const S &a, const S &b); "
+  "auto test_snippet = []{" + StatementCode +
+  "};")
+  .str();
+}
+
+static DeclarationMatcher wrapMatcher(const StatementMatcher &Matcher) {
+  return varDecl(hasName("test_snippet"),
+ hasDescendant(compoundStmt(hasAnySubstatement(Matcher;
+}
+
+struct TestMatch {
+  // The AST unit from which `result` is built. We bundle it because it backs
+  // the result. Users are not expected to access it.
+  std::unique_ptr AstUnit;
+  // The result to use in the test. References `ast_unit`.
+  MatchResult Result;
+};
+
+// Matches `Matcher` against the statement `StatementCode` and returns the
+// result. Handles putting the statement inside a function and modifying the
+// matcher correspondingly. `Matcher` should match one of the statements in
+// `StatementCode` exactly -- that is, produce exactly one match. However,
+// `StatementCode` may contain other statements not described by `Matcher`.
+static llvm::Optional matchStmt(StringRef StatementCode,
+   StatementMatcher Matcher) {
+  auto AstUnit = buildASTFromCode(wrapSnippet(StatementCode));
+  if (AstUnit == nullptr) {
+ADD_FAILURE() << "AST construction failed";
+return llvm::None;
+  }
+  ASTContext &Context = AstUnit->getASTContext();
+  auto Matches = ast_matchers::match(wrapMatcher(Matcher), Context);
+  // We expect a single, exact match for the statement.
+  if (Matches.size() != 1) {
+ADD_FAILURE() << "Wrong number of matches: " << Matches.size();
+return llvm::None;
+  }
+  return TestMatch{std::move(AstUnit), MatchResult(Matches[0], &Context)};
+}
+
+static void testPredicate(bool (*Pred)(const Expr &ExprNode),
+StringRef Snippet, bool Expected) {
+  auto StmtMatch = matchStmt(Snippet, expr().bind("expr"));
+  ASSERT_TRUE(StmtMatch);
+  EXPECT_EQ(Expected, Pred(*StmtMatch->Result.Nodes.getNodeAs("expr")));
+}
+
+TEST(SourceCodeBuildersTest, needParensAfterUnaryOperator) {
+  testPredicate(needParensAfterUnaryOperator, "3 + 5;", true);
+  testPredicate(needParensAfterUnaryOperator, "true ? 3 : 5;", true);
+
+  testPredicate(needParensAfterUnaryOperator, "int x; x;", false);
+  testPredicate(needParensAfterUnaryOperator, "int(3.0);", false);
+  testPredicate(needParensAfterUnaryOperator, "void f(); f();", false);
+  testPredicate(needParensAfterUnaryOperator, "int a[3]; a[0];", false);
+  testPredicate(needParensAfterUnaryOperator, "S x; x.field;", false);
+  testPredicate(needParensAfterUnaryOperator, "int x = 1; --x;", false);
+  testPredicate(needParensAfterUnaryOperator, "int x = 1; -x;", false);
+}
+
+TEST(SourceCodeBuildersTest, mayNeedParens) {
+  testPredicate(mayNeedParens, "3 + 5;", true);
+  testPredicate(mayNeedParens, "true ? 3 : 5;", true);
+  testPredicate(mayNeedParens, "int x = 1; --x;", true);
+  testPredicate(mayNeedParens, "int x = 1; -x;", true);
+
+  testPredicate(mayNeedParens, "int x; x;", false);
+  testPredicate(mayNeedParens, "int(3.0);", false);
+  testPredicate(mayNeedParens, "void f(); f();", false);
+  testPredicate(mayNeedParens, "int a[3]; a[0];", false);
+  testPredicate(ma

[PATCH] D67633: [libTooling] Add `access` and `ifBound` combinators to Stencil library.

2019-09-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: gribozavr.
Herald added a project: clang.
ymandel added a parent revision: D67632: [libTooling] Introduce new library of 
source-code builders..

This revision add the `access` and `ifBound` combinators to the Stencil library:

- `access` -- constructs an idiomatic expression for accessing a member (a 
`MemberExpr`).
- `ifBound` -- chooses between two `StencilParts` based on the whether an id is 
bound in the match (corresponds to the combinator of the same name in 
RangeSelector).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67633

Files:
  clang/include/clang/Tooling/Refactoring/Stencil.h
  clang/lib/Tooling/Refactoring/Stencil.cpp
  clang/unittests/Tooling/StencilTest.cpp

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -10,6 +10,8 @@
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/FixIt.h"
 #include "clang/Tooling/Tooling.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -18,10 +20,13 @@
 using namespace ast_matchers;
 
 namespace {
+using ::llvm::HasValue;
 using ::testing::AllOf;
 using ::testing::Eq;
 using ::testing::HasSubstr;
 using MatchResult = MatchFinder::MatchResult;
+using stencil::access;
+using stencil::ifBound;
 using stencil::cat;
 using stencil::dPrint;
 using stencil::text;
@@ -44,8 +49,10 @@
 }
 
 // Create a valid translation-unit from a statement.
-static std::string wrapSnippet(llvm::Twine StatementCode) {
-  return ("auto stencil_test_snippet = []{" + StatementCode + "};").str();
+static std::string wrapSnippet(StringRef StatementCode) {
+  return ("struct S { int field; }; auto stencil_test_snippet = []{" +
+  StatementCode + "};")
+  .str();
 }
 
 static DeclarationMatcher wrapMatcher(const StatementMatcher &Matcher) {
@@ -63,9 +70,10 @@
 
 // Matches `Matcher` against the statement `StatementCode` and returns the
 // result. Handles putting the statement inside a function and modifying the
-// matcher correspondingly. `Matcher` should match `StatementCode` exactly --
-// that is, produce exactly one match.
-static llvm::Optional matchStmt(llvm::Twine StatementCode,
+// matcher correspondingly. `Matcher` should match one of the statements in
+// `StatementCode` exactly -- that is, produce exactly one match. However,
+// `StatementCode` may contain other statements not described by `Matcher`.
+static llvm::Optional matchStmt(StringRef StatementCode,
StatementMatcher Matcher) {
   auto AstUnit = buildASTFromCode(wrapSnippet(StatementCode));
   if (AstUnit == nullptr) {
@@ -123,7 +131,7 @@
 
   // Tests failures caused by references to unbound nodes. `unbound_id` is the
   // id that will cause the failure.
-  void testUnboundNodeError(const Stencil &Stencil, llvm::StringRef UnboundId) {
+  void testUnboundNodeError(const Stencil &Stencil, StringRef UnboundId) {
 testError(Stencil, AllOf(HasSubstr(UnboundId), HasSubstr("not bound")));
   }
 };
@@ -188,8 +196,7 @@
   StringRef Expected) {
   auto StmtMatch = matchStmt(Snippet, expr().bind(Id));
   ASSERT_TRUE(StmtMatch);
-  EXPECT_THAT(toOptional(Stencil.eval(StmtMatch->Result)),
-  IsSomething(Expected));
+  EXPECT_THAT_EXPECTED(Stencil.eval(StmtMatch->Result), HasValue(Expected));
 }
 
 TEST_F(StencilTest, SelectionOp) {
@@ -197,6 +204,102 @@
   testExpr(Id, "3;", cat(node(Id)), "3");
 }
 
+TEST_F(StencilTest, IfBoundOpBound) {
+  StringRef Id = "id";
+  testExpr(Id, "3;", cat(ifBound(Id, text("5"), text("7"))), "5");
+}
+
+TEST_F(StencilTest, IfBoundOpUnbound) {
+  StringRef Id = "id";
+  testExpr(Id, "3;", cat(ifBound("other", text("5"), text("7"))), "7");
+}
+
+TEST_F(StencilTest, AccessOpValue) {
+  StringRef Snippet = R"cc(
+S x;
+x;
+  )cc";
+  StringRef Id = "id";
+  testExpr(Id, Snippet, cat(access(Id, "field")), "x.field");
+}
+
+TEST_F(StencilTest, AccessOpValueExplicitText) {
+  StringRef Snippet = R"cc(
+S x;
+x;
+  )cc";
+  StringRef Id = "id";
+  testExpr(Id, Snippet, cat(access(Id, text("field"))), "x.field");
+}
+
+TEST_F(StencilTest, AccessOpValueAddress) {
+  StringRef Snippet = R"cc(
+S x;
+&x;
+  )cc";
+  StringRef Id = "id";
+  testExpr(Id, Snippet, cat(access(Id, "field")), "x.field");
+}
+
+TEST_F(StencilTest, AccessOpPointer) {
+  StringRef Snippet = R"cc(
+S *x;
+x;
+  )cc";
+  StringRef Id = "id";
+  testExpr(Id, Snippet, cat(access(Id, "field")), "x->field");
+}
+
+TEST_F(StencilTest, AccessOpPointerDereference) {
+  StringRef Snippet = R"cc(
+S *x;
+*x;
+  )cc";
+  StringRef Id = "id";
+  testExpr(Id, Snippet, cat(access(Id, "field")), "x->field");
+}
+
+TEST_F(StencilTest, AccessOpExplicitThis) {
+  using clang::ast_matchers::hasObjectExpressio

[PATCH] D67635: Fix for stringized function-macro args continued across lines

2019-09-16 Thread Kousik Kumar via Phabricator via cfe-commits
kousikk created this revision.
kousikk added a reviewer: arphaman.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

In case of certain #define'd macros, there's a space just before line 
continuation
that the minimized-source lexer was missing to include, resulting in invalid 
stringize.
For example:
#define foo(x) x+7
#define bar(a,b) \

  #a \
  foo(b)

should result in "#a  foo(b)", but 
actually results in "#afoo(b)" (which is invalid).

Fixing it by keeping last but one space. I am confident that keeping the space 
is the right fix,
although I'm not sure if I've done it in the right way :)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67635

Files:
  clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
  clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp


Index: clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
===
--- clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
@@ -157,19 +157,19 @@
 
   ASSERT_FALSE(minimizeSourceToDependencyDirectives(
   "#define MACRO(\t)\tcon \t tent\t", Out));
-  EXPECT_STREQ("#define MACRO() con \t tent\n", Out.data());
+  EXPECT_STREQ("#define MACRO() con \t tent\t\n", Out.data());
 
   ASSERT_FALSE(minimizeSourceToDependencyDirectives(
   "#define MACRO(\f)\fcon \f tent\f", Out));
-  EXPECT_STREQ("#define MACRO() con \f tent\n", Out.data());
+  EXPECT_STREQ("#define MACRO() con \f tent\f\n", Out.data());
 
   ASSERT_FALSE(minimizeSourceToDependencyDirectives(
   "#define MACRO(\v)\vcon \v tent\v", Out));
-  EXPECT_STREQ("#define MACRO() con \v tent\n", Out.data());
+  EXPECT_STREQ("#define MACRO() con \v tent\v\n", Out.data());
 
   ASSERT_FALSE(minimizeSourceToDependencyDirectives(
   "#define MACRO \t\v\f\v\t con\f\t\vtent\v\f \v", Out));
-  EXPECT_STREQ("#define MACRO con\f\t\vtent\n", Out.data());
+  EXPECT_STREQ("#define MACRO con\f\t\vtent\v\n", Out.data());
 }
 
 TEST(MinimizeSourceToDependencyDirectivesTest, DefineMultilineArgs) {
@@ -187,7 +187,7 @@
"call((a),  \\\n"
" (b))",
Out));
-  EXPECT_STREQ("#define MACRO(a,b) call((a),(b))\n", Out.data());
+  EXPECT_STREQ("#define MACRO(a,b) call((a), (b))\n", Out.data());
 }
 
 TEST(MinimizeSourceToDependencyDirectivesTest,
@@ -200,7 +200,19 @@
"call((a),  \\\r"
" (b))",
Out));
-  EXPECT_STREQ("#define MACRO(a,b) call((a),(b))\n", Out.data());
+  EXPECT_STREQ("#define MACRO(a,b) call((a), (b))\n", Out.data());
+}
+
+TEST(MinimizeSourceToDependencyDirectivesTest,
+ DefineMultilineArgsStringize) {
+  SmallVector Out;
+
+  ASSERT_FALSE(
+  minimizeSourceToDependencyDirectives("#define MACRO(a,b) \\\n"
+   "#a \\\n"
+   "#b",
+   Out));
+  EXPECT_STREQ("#define MACRO(a,b) #a #b\n", Out.data());
 }
 
 TEST(MinimizeSourceToDependencyDirectivesTest,
@@ -213,7 +225,7 @@
"call((a),  \\\r\n"
" (b))",
Out));
-  EXPECT_STREQ("#define MACRO(a,b) call((a),(b))\n", Out.data());
+  EXPECT_STREQ("#define MACRO(a,b) call((a), (b))\n", Out.data());
 }
 
 TEST(MinimizeSourceToDependencyDirectivesTest,
@@ -226,7 +238,7 @@
"call((a),  \\\n\r"
" (b))",
Out));
-  EXPECT_STREQ("#define MACRO(a,b) call((a),(b))\n", Out.data());
+  EXPECT_STREQ("#define MACRO(a,b) call((a), (b))\n", Out.data());
 }
 
 TEST(MinimizeSourceToDependencyDirectivesTest, DefineNumber) {
Index: clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
===
--- clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -246,9 +246,12 @@
 
 static const char *reverseOverSpaces(const char *First, const char *Last) {
   assert(First <= Last);
-  while (First != Last && isHorizontalWhitespace(Last[-1]))
+  const char *PrevLast = Last;
+  while (First != Last && isHorizontalWhitespace(Last[-1])) {
+PrevLast = Last;
 --Last;
-  return Last;
+  }
+  return PrevLast;
 }
 
 static void skipLineComment(const char *&First, const char *const End) {


Index: clang/unittests/Lex/DependencyDirectivesSourceMinimizerT

[PATCH] D63508: make -frewrite-includes also rewrite conditions in #if/#elif

2019-09-16 Thread Tor Arne Vestbø via Phabricator via cfe-commits
torarnv added a comment.

Just for understanding what's going on here, I'm going to ask some stupid 
questions 😄

So, this will make `-frewrite-includes` do more work, to ensure that it not 
only covers the "top level" `#include` or `__has_include` case, but also 
`__has_include` in one or more levels of macros?

Does that effectively means it needs to do full preprocessing? Eg. to determine 
cases like this:

  #ifdef FOO
  #define BAR(x) __has_include(x)
  #else
  #define BAR(x) 0
  #endif

Or do we draw the line there and only support `__has_include` in macros if 
those are not conditional themselves? Does it depend on whether `-E` is passed 
with `-frewrite-includes`?

Will this mean that cases like icecream and distcc that use 
`-frewrite-includes` will have fully preprocessed sources to send to the remote 
hosts (with correct line/column number when compilation fails), or should they 
still pass `-D` options during the remote compilation? I'm referring to this 
quote from the distcc manual:

> run_second_cpp
> 
> If false, ccache will first run preprocessor to preprocess the source code 
> and then on a cache miss run the compiler on the preprocessed source code 
> instead of the original source code. This makes cache misses slightly faster 
> since the source code only has to be preprocessed once. The downside is that 
> some compilers won’t produce the same result (for instance diagnostics 
> warnings) when compiling preprocessed source code.
> 
> A solution to the above mentioned downside is to set run_second_cpp to false 
> and pass -fdirectives-only (for GCC) or -frewrite-includes (for Clang) to the 
> compiler. This will cause the compiler to leave the macros and other 
> preprocessor information, and only process the #include directives. When run 
> in this way, the preprocessor arguments will be passed to the compiler since 
> it still has to do some preprocessing (like macros).

How does `ICECC_REMOTE_CPP` work in this case?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63508/new/

https://reviews.llvm.org/D63508



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


[PATCH] D66627: [clang-tidy] add checks to bugprone-posix-return

2019-09-16 Thread Jian Cai via Phabricator via cfe-commits
jcai19 updated this revision to Diff 220393.
jcai19 added a comment.

Thanks for the confirmation!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66627/new/

https://reviews.llvm.org/D66627

Files:
  clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-posix-return.rst
  clang-tools-extra/test/clang-tidy/bugprone-posix-return.cpp

Index: clang-tools-extra/test/clang-tidy/bugprone-posix-return.cpp
===
--- clang-tools-extra/test/clang-tidy/bugprone-posix-return.cpp
+++ clang-tools-extra/test/clang-tidy/bugprone-posix-return.cpp
@@ -9,6 +9,16 @@
 typedef decltype(sizeof(int)) size_t;
 typedef struct __posix_spawn_file_actions* posix_spawn_file_actions_t;
 typedef struct __posix_spawnattr* posix_spawnattr_t;
+# define __CPU_SETSIZE 1024
+# define __NCPUBITS (8 * sizeof (__cpu_mask))
+typedef unsigned long int __cpu_mask;
+typedef struct
+{
+  __cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS];
+} cpu_set_t;
+typedef struct _opaque_pthread_t *__darwin_pthread_t;
+typedef __darwin_pthread_t pthread_t;
+typedef struct pthread_attr_t_ *pthread_attr_t;
 
 extern "C" int posix_fadvise(int fd, off_t offset, off_t len, int advice);
 extern "C" int posix_fallocate(int fd, off_t offset, off_t len);
@@ -23,6 +33,12 @@
  const posix_spawn_file_actions_t *file_actions,
  const posix_spawnattr_t *attrp,
  char *const argv[], char *const envp[]);
+extern "C" int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg);
+extern "C" int pthread_attr_setaffinity_np(pthread_attr_t *attr, size_t cpusetsize, const cpu_set_t *cpuset);
+extern "C" int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
+extern "C" int pthread_attr_init(pthread_attr_t *attr);
+extern "C" int pthread_yield(void);
+
 
 void warningLessThanZero() {
   if (posix_fadvise(0, 0, 0, 0) < 0) {}
@@ -43,11 +59,38 @@
   if (posix_spawnp(NULL, NULL, NULL, NULL, {NULL}, {NULL}) < 0) {}
   // CHECK-MESSAGES: :[[@LINE-1]]:60: warning:
   // CHECK-FIXES: posix_spawnp(NULL, NULL, NULL, NULL, {NULL}, {NULL}) > 0
+  if (pthread_create(NULL, NULL, NULL, NULL) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: the comparison always evaluates to false because pthread_create always returns non-negative values
+  // CHECK-FIXES: pthread_create(NULL, NULL, NULL, NULL) > 0
+  if (pthread_attr_setaffinity_np(NULL, 0, NULL) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:50: warning:
+  // CHECK-FIXES: pthread_attr_setaffinity_np(NULL, 0, NULL) > 0
+  if (pthread_attr_setschedpolicy(NULL, 0) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:44: warning:
+  // CHECK-FIXES: pthread_attr_setschedpolicy(NULL, 0) > 0)
+  if (pthread_attr_init(NULL) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning:
+  // CHECK-FIXES: pthread_attr_init(NULL) > 0
+  if (pthread_yield() < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning:
+  // CHECK-FIXES: pthread_yield() > 0
+
 }
 
 void warningAlwaysTrue() {
   if (posix_fadvise(0, 0, 0, 0) >= 0) {}
   // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: the comparison always evaluates to true because posix_fadvise always returns non-negative values
+  if (pthread_create(NULL, NULL, NULL, NULL) >= 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: the comparison always evaluates to true because pthread_create always returns non-negative values
+  if (pthread_attr_setaffinity_np(NULL, 0, NULL) >= 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:50: warning:
+  if (pthread_attr_setschedpolicy(NULL, 0) >= 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:44: warning:
+  if (pthread_attr_init(NULL) >= 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning:
+  if (pthread_yield() >= 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning:
+
 }
 
 void warningEqualsNegative() {
@@ -69,6 +112,15 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:59: warning:
   if (posix_spawnp(NULL, NULL, NULL, NULL, {NULL}, {NULL}) == -1) {}
   // CHECK-MESSAGES: :[[@LINE-1]]:60: warning:
+  if (pthread_create(NULL, NULL, NULL, NULL) == -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: pthread_create
+  if (pthread_create(NULL, NULL, NULL, NULL) != -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:46: warning:
+  if (pthread_create(NULL, NULL, NULL, NULL) <= -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:46: warning:
+  if (pthread_create(NULL, NULL, NULL, NULL) < -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:46: warning:
+
 }
 
 void WarningWithMacro() {
@@ -85,6 +137,20 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
   if (posix_fadvise(0, 0, 0, 0) < NEGATIVE_ONE) {}
   // CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
+  if (pthread_create(NULL, NULL, NULL, NULL) < ZERO) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:46: warning:
+  // CHECK-FIXES: pthread_create

[clang-tools-extra] r372037 - [clang-tidy] add checks to bugprone-posix-return

2019-09-16 Thread Jian Cai via cfe-commits
Author: jcai19
Date: Mon Sep 16 14:43:56 2019
New Revision: 372037

URL: http://llvm.org/viewvc/llvm-project?rev=372037&view=rev
Log:
[clang-tidy] add checks to bugprone-posix-return

This check now also checks if any calls to pthread_* functions expect negative 
return values. These functions return either 0 on success or an errno on 
failure, which is positive only.

Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-posix-return.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-posix-return.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.cpp?rev=372037&r1=372036&r2=372037&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.cpp Mon Sep 16 
14:43:56 2019
@@ -28,26 +28,31 @@ static StringRef getFunctionSpelling(con
 }
 
 void PosixReturnCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(binaryOperator(hasOperatorName("<"),
-hasLHS(callExpr(callee(functionDecl(
-matchesName("^::posix_"),
-unless(hasName("::posix_openpt")),
-hasRHS(integerLiteral(equals(0
- .bind("ltzop"),
- this);
-  Finder->addMatcher(binaryOperator(hasOperatorName(">="),
-hasLHS(callExpr(callee(functionDecl(
-matchesName("^::posix_"),
-unless(hasName("::posix_openpt")),
-hasRHS(integerLiteral(equals(0
- .bind("atop"),
- this);
+  Finder->addMatcher(
+  binaryOperator(
+  hasOperatorName("<"),
+  hasLHS(callExpr(callee(functionDecl(
+  anyOf(matchesName("^::posix_"), matchesName("^::pthread_")),
+  unless(hasName("::posix_openpt")),
+  hasRHS(integerLiteral(equals(0
+  .bind("ltzop"),
+  this);
+  Finder->addMatcher(
+  binaryOperator(
+  hasOperatorName(">="),
+  hasLHS(callExpr(callee(functionDecl(
+  anyOf(matchesName("^::posix_"), matchesName("^::pthread_")),
+  unless(hasName("::posix_openpt")),
+  hasRHS(integerLiteral(equals(0
+  .bind("atop"),
+  this);
   Finder->addMatcher(
   binaryOperator(
   anyOf(hasOperatorName("=="), hasOperatorName("!="),
 hasOperatorName("<="), hasOperatorName("<")),
   hasLHS(callExpr(callee(functionDecl(
-  matchesName("^::posix_"), unless(hasName("::posix_openpt")),
+  anyOf(matchesName("^::posix_"), matchesName("^::pthread_")),
+  unless(hasName("::posix_openpt")),
   hasRHS(unaryOperator(hasOperatorName("-"),
hasUnaryOperand(integerLiteral()
   .bind("binop"),

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.h?rev=372037&r1=372036&r2=372037&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/PosixReturnCheck.h Mon Sep 16 
14:43:56 2019
@@ -1,4 +1,4 @@
-//===--- PosixReturnCheck.h - clang-tidy-*- C++ 
-*-===//
+//===--- PosixReturnCheck.h - clang-tidy *- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=372037&r1=372036&r2=372037&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Mon Sep 16 14:43:56 2019
@@ -91,6 +91,11 @@ Improvements to clang-tidy
   Finds historical use of ``unsigned`` to hold vregs and physregs and rewrites
   them to use ``Register``
 
+- Improved :doc:`bugprone-posix-return
+  ` check.
+
+  Now also checks if any calls to ``pthread_*`` functions expect negative 
return
+  values.
 
 Improvements to include-fixer
 --

[PATCH] D53768: Add VerboseOutputStream to CompilerInstance

2019-09-16 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 220396.
scott.linder added a comment.

Actually rebase this time


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53768/new/

https://reviews.llvm.org/D53768

Files:
  include/clang/Frontend/CompilerInstance.h
  lib/Frontend/CompilerInstance.cpp
  unittests/Frontend/OutputStreamTest.cpp

Index: unittests/Frontend/OutputStreamTest.cpp
===
--- unittests/Frontend/OutputStreamTest.cpp
+++ unittests/Frontend/OutputStreamTest.cpp
@@ -10,6 +10,7 @@
 #include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/CodeGenAction.h"
 #include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/FrontendTool/Utils.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "gtest/gtest.h"
@@ -43,4 +44,29 @@
   EXPECT_TRUE(!IRBuffer.empty());
   EXPECT_TRUE(StringRef(IRBuffer.data()).startswith("BC"));
 }
+
+TEST(FrontendOutputTests, TestVerboseOutputStream) {
+  auto Invocation = std::make_shared();
+  Invocation->getPreprocessorOpts().addRemappedFile(
+  "test.cc", MemoryBuffer::getMemBuffer("invalid").release());
+  Invocation->getFrontendOpts().Inputs.push_back(
+  FrontendInputFile("test.cc", Language::CXX));
+  Invocation->getFrontendOpts().ProgramAction = EmitBC;
+  Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu";
+  CompilerInstance Compiler;
+
+  std::string VerboseBuffer;
+  raw_string_ostream VerboseStream(VerboseBuffer);
+
+  Compiler.setInvocation(std::move(Invocation));
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  Compiler.createDiagnostics(
+  new TextDiagnosticPrinter(llvm::nulls(), &*DiagOpts), true);
+  Compiler.setVerboseOutputStream(VerboseStream);
+
+  bool Success = ExecuteCompilerInvocation(&Compiler);
+  EXPECT_FALSE(Success);
+  EXPECT_TRUE(!VerboseStream.str().empty());
+  EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated"));
+}
 }
Index: lib/Frontend/CompilerInstance.cpp
===
--- lib/Frontend/CompilerInstance.cpp
+++ lib/Frontend/CompilerInstance.cpp
@@ -68,6 +68,8 @@
 
 CompilerInstance::~CompilerInstance() {
   assert(OutputFiles.empty() && "Still output files in flight?");
+  if (OwnsVerboseOutputStream)
+delete VerboseOutputStream;
 }
 
 void CompilerInstance::setInvocation(
@@ -86,6 +88,12 @@
   Diagnostics = Value;
 }
 
+void CompilerInstance::setVerboseOutputStream(raw_ostream &Value,
+  bool OwnsOutputStream) {
+  OwnsVerboseOutputStream = OwnsOutputStream;
+  VerboseOutputStream = &Value;
+}
+
 void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; }
 void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; }
 
@@ -897,9 +905,7 @@
   // DesiredStackSpace available.
   noteBottomOfStack();
 
-  // FIXME: Take this as an argument, once all the APIs we used have moved to
-  // taking it as an input instead of hard-coding llvm::errs.
-  raw_ostream &OS = llvm::errs();
+  raw_ostream &OS = getVerboseOutputStream();
 
   if (!Act.PrepareToExecute(*this))
 return false;
Index: include/clang/Frontend/CompilerInstance.h
===
--- include/clang/Frontend/CompilerInstance.h
+++ include/clang/Frontend/CompilerInstance.h
@@ -155,6 +155,12 @@
   /// One or more modules failed to build.
   bool ModuleBuildFailed = false;
 
+  /// Whether we should delete VerboseOutputStream on destruction.
+  bool OwnsVerboseOutputStream = false;
+
+  /// The stream for verbose output.
+  raw_ostream *VerboseOutputStream = &llvm::errs();
+
   /// Holds information about the output file.
   ///
   /// If TempFilename is not empty we must rename it to Filename at the end.
@@ -217,9 +223,6 @@
   /// \param Act - The action to execute.
   /// \return - True on success.
   //
-  // FIXME: This function should take the stream to write any debugging /
-  // verbose output to as an argument.
-  //
   // FIXME: Eliminate the llvm_shutdown requirement, that should either be part
   // of the context or else not CompilerInstance specific.
   bool ExecuteAction(FrontendAction &Act);
@@ -349,6 +352,21 @@
 return *Diagnostics->getClient();
   }
 
+  /// }
+  /// @name VerboseOutputStream
+  /// }
+
+  /// Replace the current stream for verbose output.
+  ///
+  /// If not set, this stream defaults to \c llvm::errs().
+  void setVerboseOutputStream(raw_ostream &Value,
+  bool OwnsOutputStream = false);
+
+  /// Get the current stream for verbose output.
+  raw_ostream &getVerboseOutputStream() {
+return *VerboseOutputStream;
+  }
+
   /// }
   /// @name Target Info
   /// {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r372039 - [Modules][Objective-C] Use complete decl from module when diagnosing missing import

2019-09-16 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Mon Sep 16 15:00:29 2019
New Revision: 372039

URL: http://llvm.org/viewvc/llvm-project?rev=372039&view=rev
Log:
[Modules][Objective-C] Use complete decl from module when diagnosing missing 
import

Summary:
Otherwise the definition (first found) for ObjCInterfaceDecl's might
precede the module one, which will eventually lead to crash, since
diagnoseMissingImport needs one coming from a module.

This behavior changed after Richard's r342018, which started to look
into the definition of ObjCInterfaceDecls.

rdar://problem/49237144

Reviewers: rsmith, arphaman

Subscribers: jkorous, dexonsmith, ributzka, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/

cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/

cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/

cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h

cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h

cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/

cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap

cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/

cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h
cfe/trunk/test/Modules/interface-diagnose-missing-import.m
Modified:
cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=372039&r1=372038&r2=372039&view=diff
==
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Mon Sep 16 15:00:29 2019
@@ -5273,8 +5273,11 @@ static NamedDecl *getDefinitionToImport(
 return FD->getDefinition();
   if (TagDecl *TD = dyn_cast(D))
 return TD->getDefinition();
+  // The first definition for this ObjCInterfaceDecl might be in the TU
+  // and not associated with any module. Use the one we know to be complete
+  // and have just seen in a module.
   if (ObjCInterfaceDecl *ID = dyn_cast(D))
-return ID->getDefinition();
+return ID;
   if (ObjCProtocolDecl *PD = dyn_cast(D))
 return PD->getDefinition();
   if (TemplateDecl *TD = dyn_cast(D))

Added: 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h?rev=372039&view=auto
==
--- 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h
 (added)
+++ 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h
 Mon Sep 16 15:00:29 2019
@@ -0,0 +1 @@
+// interface-diagnose-missing-import/Foo.framework/Headers/Bar.h

Added: 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h?rev=372039&view=auto
==
--- 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h
 (added)
+++ 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h
 Mon Sep 16 15:00:29 2019
@@ -0,0 +1,2 @@
+#import 
+#import 

Added: 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap?rev=372039&view=auto
==
--- 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap
 (added)
+++ 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap
 Mon Sep 16 15:00:29 2019
@@ -0,0 +1,6 @@
+// interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap
+framework module Foo {
+  umbrella header "Foo.h"
+  export *
+  module * { export * }
+}

Added: 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h?rev=372039&view=auto
==
--- 
cfe/t

[PATCH] D66982: [Modules][Objective-C] Use complete decl from module when diagnosing missing import

2019-09-16 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL372039: [Modules][Objective-C] Use complete decl from module 
when diagnosing missing… (authored by bruno, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66982?vs=217999&id=220397#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66982/new/

https://reviews.llvm.org/D66982

Files:
  cfe/trunk/lib/Sema/SemaLookup.cpp
  
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h
  
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h
  
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap
  
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h
  cfe/trunk/test/Modules/interface-diagnose-missing-import.m


Index: cfe/trunk/test/Modules/interface-diagnose-missing-import.m
===
--- cfe/trunk/test/Modules/interface-diagnose-missing-import.m
+++ cfe/trunk/test/Modules/interface-diagnose-missing-import.m
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 %s -fsyntax-only -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t -F%S/Inputs/interface-diagnose-missing-import -verify
+@interface Buggy
+@end
+
+@import Foo.Bar;
+
+@interface Buggy (MyExt) // expected-error {{definition of 'Buggy' must be 
imported from module 'Foo' before it is required}}
+@end
+
+// expected-note@Foo/RandoPriv.h:3{{previous definition is here}}
Index: 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h
===
--- 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h
+++ 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Bar.h
@@ -0,0 +1 @@
+// interface-diagnose-missing-import/Foo.framework/Headers/Bar.h
Index: 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h
===
--- 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h
+++ 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Headers/Foo.h
@@ -0,0 +1,2 @@
+#import 
+#import 
Index: 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap
===
--- 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap
+++ 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap
@@ -0,0 +1,6 @@
+// interface-diagnose-missing-import/Foo.framework/Modules/module.modulemap
+framework module Foo {
+  umbrella header "Foo.h"
+  export *
+  module * { export * }
+}
Index: 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h
===
--- 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h
+++ 
cfe/trunk/test/Modules/Inputs/interface-diagnose-missing-import/Foo.framework/PrivateHeaders/RandoPriv.h
@@ -0,0 +1,4 @@
+@interface NSObject
+@end
+@interface Buggy : NSObject
+@end
Index: cfe/trunk/lib/Sema/SemaLookup.cpp
===
--- cfe/trunk/lib/Sema/SemaLookup.cpp
+++ cfe/trunk/lib/Sema/SemaLookup.cpp
@@ -5273,8 +5273,11 @@
 return FD->getDefinition();
   if (TagDecl *TD = dyn_cast(D))
 return TD->getDefinition();
+  // The first definition for this ObjCInterfaceDecl might be in the TU
+  // and not associated with any module. Use the one we know to be complete
+  // and have just seen in a module.
   if (ObjCInterfaceDecl *ID = dyn_cast(D))
-return ID->getDefinition();
+return ID;
   if (ObjCProtocolDecl *PD = dyn_cast(D))
 return PD->getDefinition();
   if (TemplateDecl *TD = dyn_cast(D))


Index: cfe/trunk/test/Modules/interface-diagnose-missing-import.m
===
--- cfe/trunk/test/Modules/interface-diagnose-missing-import.m
+++ cfe/trunk/test/Modules/interface-diagnose-missing-import.m
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 %s -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F%S/Inputs/interface-diagnose-missing-import -verify
+@interface Buggy
+@end
+
+@import Foo.Bar;
+
+@interface Buggy (MyExt) // expected-error {{definition of 'Buggy' must be imported from module 'Foo' before it is required}}
+@end
+
+// expected-note@Foo/RandoPriv.h:3{{previous definition is here}}
Index

r372040 - [OPENMP]Fix the test, NFC.

2019-09-16 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Sep 16 15:17:10 2019
New Revision: 372040

URL: http://llvm.org/viewvc/llvm-project?rev=372040&view=rev
Log:
[OPENMP]Fix the test, NFC.

Modified:
cfe/trunk/test/OpenMP/parallel_for_codegen.cpp

Modified: cfe/trunk/test/OpenMP/parallel_for_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_for_codegen.cpp?rev=372040&r1=372039&r2=372040&view=diff
==
--- cfe/trunk/test/OpenMP/parallel_for_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/parallel_for_codegen.cpp Mon Sep 16 15:17:10 2019
@@ -19,6 +19,7 @@
 #ifndef HEADER
 #define HEADER
 
+#ifndef OMP5
 // CHECK-DAG: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
 // CHECK-DAG: [[LOOP_LOC:@.+]] = private unnamed_addr global [[IDENT_T_TY]] { 
i32 0, i32 514, i32 0, i32 0, i8*
 
@@ -383,7 +384,7 @@ void parallel_for(float *a, const int n)
 // TERM_DEBUG-DAG: [[DBG_LOC_START]] = !DILocation(line: [[@LINE-4]],
 // TERM_DEBUG-DAG: [[DBG_LOC_END]] = !DILocation(line: [[@LINE-18]],
 
-#ifdef OMP5
+#else // OMP5
 // OMP5-DAG: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
 // OMP5-DAG: [[LOOP_LOC:@.+]] = private unnamed_addr global [[IDENT_T_TY]] { 
i32 0, i32 514, i32 0, i32 0, i8*
 
@@ -467,7 +468,7 @@ int decrement_nowait () {
   return 0;
 // OMP5: ret i32 0
 }
-#endif
+#endif // OMP5
 
 #endif // HEADER
 


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


[PATCH] D67638: Improve __builtin_constant_p lowering

2019-09-16 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg created this revision.
joerg added a reviewer: rsmith.
Herald added subscribers: kristina, kbarton, nemanjai.
Herald added a project: clang.
Herald added a subscriber: wuzish.

__builtin_constant_p used to be short-cut evaluated to false when building with 
-O0. This is undesirable as it means that constant folding in the front-end can 
give different results than folding in the back-end.  It can also create 
conditional branches on constant conditions that don't get folded away. With 
the improvements to the llvm.is.constant handling on the LLVM side, the 
short-cut is no longer useful.

Adjust various codegen tests to not depend on the optimizations.


Repository:
  rC Clang

https://reviews.llvm.org/D67638

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/builtin-constant-p.c
  test/CodeGen/ppc-emmintrin.c
  test/CodeGen/ppc-tmmintrin.c

Index: test/CodeGen/ppc-tmmintrin.c
===
--- test/CodeGen/ppc-tmmintrin.c
+++ test/CodeGen/ppc-tmmintrin.c
@@ -108,7 +108,8 @@
 // CHECK: store <2 x i64> [[REG61]], <2 x i64>* [[REG65:[0-9a-zA-Z_%.]+]], align 16
 // CHECK-NEXT: store <2 x i64> [[REG62]], <2 x i64>* [[REG66:[0-9a-zA-Z_%.]+]], align 16
 // CHECK-NEXT: store i32 [[REG63]], i32* [[REG64:[0-9a-zA-Z_%.]+]], align 4
-// CHECK-NEXT: br i1 false, label %[[REG67:[0-9a-zA-Z_%.]+]], label %[[REG68:[0-9a-zA-Z_%.]+]]
+// CHECK: %[[REG64b:[0-9a-zA-Z_%.]+]] = call i1 @llvm.is.constant.i32(i32 %0)
+// CHECK-NEXT: br i1 %[[REG64b]], label %[[REG67:[0-9a-zA-Z_%.]+]], label %[[REG68:[0-9a-zA-Z_%.]+]]
 
 // CHECK: [[REG67]]:
 // CHECK-NEXT: [[REG69:[0-9a-zA-Z_%.]+]] = load i32, i32* [[REG64]], align 4
Index: test/CodeGen/ppc-emmintrin.c
===
--- test/CodeGen/ppc-emmintrin.c
+++ test/CodeGen/ppc-emmintrin.c
@@ -231,7 +231,9 @@
 // CHECK-NEXT: br i1 [[REG147]], label %[[REG148:[0-9a-zA-Z_%.]+]], label %[[REG149:[0-9a-zA-Z_%.]+]]
 // CHECK: [[REG148]]:
 
-// CHECK-LE-NEXT: br i1 false, label %[[REG150:[0-9a-zA-Z_%.]+]], label %[[REG151:[0-9a-zA-Z_%.]+]]
+// CHECK-LE-NEXT: load
+// CHECK-LE-NEXT: call i1 @llvm.is.constant
+// CHECK-LE-NEXT: br i1 %[[REG1896a:[0-9a-zA-Z_%.]+]], label %[[REG150:[0-9a-zA-Z_%.]+]], label %[[REG151:[0-9a-zA-Z_%.]+]]
 // CHECK-LE: [[REG150]]:
 // CHECK-LE: [[REG152:[0-9a-zA-Z_%.]+]] = load <2 x i64>, <2 x i64>* [[REG143]], align 16
 // CHECK-LE-NEXT: [[REG153:[0-9a-zA-Z_%.]+]] = bitcast <2 x i64> [[REG152]] to <16 x i8>
@@ -2326,7 +2328,9 @@
 // CHECK-NEXT: br i1 [[REG1559]], label %[[REG1560:[0-9a-zA-Z_%.]+]], label %[[REG1557:[0-9a-zA-Z_%.]+]]
 
 // CHECK: [[REG1560]]:
-// CHECK-NEXT: br i1 false, label %[[REG1561:[0-9a-zA-Z_%.]+]], label %[[REG1562:[0-9a-zA-Z_%.]+]]
+// CHECK-NEXT: load
+// CHECK-NEXT: call i1 @llvm.is.constant
+// CHECK-NEXT: br i1 %[[REG1561a:[0-9a-zA-Z_%.]+]], label %[[REG1561:[0-9a-zA-Z_%.]+]], label %[[REG1562:[0-9a-zA-Z_%.]+]]
 
 // CHECK: [[REG1561]]:
 // CHECK-NEXT: [[REG1563:[0-9a-zA-Z_%.]+]] = load i32, i32* [[REG1552]], align 4
@@ -2369,7 +2373,9 @@
 // CHECK-NEXT: br i1 [[REG1587]], label %[[REG1588:[0-9a-zA-Z_%.]+]], label %[[REG1585:[0-9a-zA-Z_%.]+]]
 
 // CHECK: [[REG1588]]:
-// CHECK-NEXT: br i1 false, label %[[REG1589:[0-9a-zA-Z_%.]+]], label %[[REG1590:[0-9a-zA-Z_%.]+]]
+// CHECK-NEXT: load
+// CHECK-NEXT: call i1 @llvm.is.constant
+// CHECK-NEXT: br i1 %{{[0-9a-zA-Z_%.]+}}, label %[[REG1589:[0-9a-zA-Z_%.]+]], label %[[REG1590:[0-9a-zA-Z_%.]+]]
 
 // CHECK: [[REG1589]]:
 // CHECK-NEXT: [[REG1591:[0-9a-zA-Z_%.]+]] = load i32, i32* [[REG1580]], align 4
@@ -2416,7 +2422,9 @@
 // CHECK-NEXT: br i1 [[REG1617]], label %[[REG1618:[0-9a-zA-Z_%.]+]], label %[[REG1615:[0-9a-zA-Z_%.]+]]
 
 // CHECK: [[REG1618]]:
-// CHECK-NEXT: br i1 false, label %[[REG1619:[0-9a-zA-Z_%.]+]], label %[[REG1620:[0-9a-zA-Z_%.]+]]
+// CHECK-NEXT: load
+// CHECK-NEXT: call i1 @llvm.is.constant
+// CHECK-NEXT: br i1 %{{[0-9a-zA-Z_%.]+}}, label %[[REG1619:[0-9a-zA-Z_%.]+]], label %[[REG1620:[0-9a-zA-Z_%.]+]]
 
 // CHECK: [[REG1619]]:
 // CHECK-NEXT: [[REG1621:[0-9a-zA-Z_%.]+]] = load i32, i32* [[REG1610]], align 4
@@ -2563,7 +2571,9 @@
 // CHECK-NEXT: br i1 [[REG1712]], label %[[REG1713:[0-9a-zA-Z_%.]+]], label %[[REG1714:[0-9a-zA-Z_%.]+]]
 
 // CHECK: [[REG1713]]:
-// CHECK-NEXT: br i1 false, label %[[REG1715:[0-9a-zA-Z_%.]+]], label %[[REG1716:[0-9a-zA-Z_%.]+]]
+// CHECK-NEXT: load
+// CHECK-NEXT: call i1 @llvm.is.constant
+// CHECK-NEXT: br i1 %[[REG1715a:[0-9a-zA-Z_%.]+]], label %[[REG1715:[0-9a-zA-Z_%.]+]], label %[[REG1716:[0-9a-zA-Z_%.]+]]
 
 // CHECK: [[REG1715]]:
 // CHECK-NEXT: [[REG1717:[0-9a-zA-Z_%.]+]] = load i32, i32* [[REG1709]], align 4
@@ -2601,7 +2611,9 @@
 // CHECK-NEXT: br i1 [[REG1737]], label %[[REG1738:[0-9a-zA-Z_%.]+]], label %[[REG1739:[0-9a-zA-Z_%.]+]]
 
 // CHECK: [[REG1738]]:
-// CHECK-NEXT: br i1 false, label %[[REG1740:[0-9a-zA-Z_%.]+]], label %[[REG1741:[0-9a-zA-Z_%.]+]]
+// CHECK-NEXT: load
+// CHECK-NEXT: call i1 @llvm.is.constant
+//

[PATCH] D67578: [clang-tidy] New check to warn when writing to a dispatch_once_t variable.

2019-09-16 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/misc-dispatch-once-assignment.rst:9
+and making such direct writes may potentially violate the run-once protections
+intended by the library.

Eugene.Zelenko wrote:
> Does library documentation contain this recommendation? If so, will be good 
> idea to add link. Same for other check.
I don't recall if there is explicit GCD documentation anywhere. The closest 
thing I could find was a post from Greg Parker: 
https://stackoverflow.com/a/19845164.

I think the general issue is that GCD performs atomic operations internally on 
`dispatch_once_t` memory. A recent 
[snapshot](https://github.com/apple/swift-corelibs-libdispatch/blob/631821c2bfcf296995a8424f148a9365470c2210/src/once.c)
 of a version of GCD suggests that C11 atomic operations are used but the 
general issue is that GCD does not publicly declare how it internally 
guarantees atomicity while managing `dispatch_once_t` state. The safest way to 
make mutations to `dispatch_once_t` memory is by using the same atomic 
operations library that the particular version of GCD loaded into your process 
uses (in theory this can vary depending on a number of factors including the 
system version). Given that this information is not exposed and it seems 
unlikely, if not unreasonable, to be exposed,  the safest approach is 
presumably to to let GCD handle all mutations.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67578/new/

https://reviews.llvm.org/D67578



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


[PATCH] D67632: [libTooling] Introduce new library of source-code builders.

2019-09-16 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang/lib/Tooling/Refactoring/SourceCodeBuilders.cpp:77
+
+  if (Text.empty()) return std::string();
+  // Add leading '*'.

Could return {}. Same in other places. By the word, did you run Clang-format 
over code?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67632/new/

https://reviews.llvm.org/D67632



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


[PATCH] D67567: [clang-tidy] New check to warn when storing dispatch_once_t in non-static, non-global storage

2019-09-16 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added a comment.

In D67567#1670144 , @mwyman wrote:

> In D67567#1670035 , @lebedev.ri 
> wrote:
>
> > In D67567#1670017 , @mwyman wrote:
> >
> > > In D67567#1669866 , @lebedev.ri 
> > > wrote:
> > >
> > > > 2. Is `dispatch_once_t` OSX-specific thing? Should those checks be in 
> > > > `osx` module?
> > >
> >
> >
> >
> >
> > > 2. I don't see an `osx` module—am I somehow missing seeing it?
> >
> > One can be added.
> >
> > > `dispatch_once_t` is something from `libdispatch`which is an 
> > > Apple-created API, but is OSS and available outside Apple. It's also a C 
> > > API, which is why I didn't feel `objc` was an appropriate module either. 
> > > I'm open to a better home module for this check, it's just not clear to 
> > > me where that might be.
> >
> > No opinion on my question, just thought it should be asked,
>
>
> As Ben commented, I don't feel this should be in an `osx` module, as 
> libdispatch is highly used on iOS and other Apple platforms. I know it's 
> available elsewhere, but it may be so seldom used that I think a 
> `darwin`module might be reasonable. I looked at the process for creating a 
> new module, and can do that if we'd like, but should that be part of this 
> same review?


As alluded to, //technically// Grand Central Dispatch is documented to support 
FreeBSD. With that said, I would be okay with putting this in a `darwin` module 
because GCD is most prevalent on Darwin platforms.




Comment at: 
clang-tools-extra/test/clang-tidy/darwin-dispatch-once-nonstatic.mm:45
+  dispatch_once_t _once;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: dispatch_once_t variables must 
have static or global storage duration and cannot be Objective-C instance 
variables [darwin-dispatch-once-nonstatic]
+}

Maybe add a `CHECK-FIXES` to make sure that no fix was recommended?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67567/new/

https://reviews.llvm.org/D67567



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


r372055 - [OPENMP] Fix the test, NFC

2019-09-16 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Sep 16 17:08:50 2019
New Revision: 372055

URL: http://llvm.org/viewvc/llvm-project?rev=372055&view=rev
Log:
[OPENMP] Fix the test, NFC

Modified:
cfe/trunk/test/OpenMP/parallel_for_codegen.cpp

Modified: cfe/trunk/test/OpenMP/parallel_for_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_for_codegen.cpp?rev=372055&r1=372054&r2=372055&view=diff
==
--- cfe/trunk/test/OpenMP/parallel_for_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/parallel_for_codegen.cpp Mon Sep 16 17:08:50 2019
@@ -15,7 +15,9 @@
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -DOMP5 -x c++ -triple 
x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | 
FileCheck --check-prefix=OMP5 %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -DOMP5 -x c++ -std=c++11 
-triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -DOMP5 -x c++ -triple 
x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck --check-prefix=OMP5 %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -x c++ -std=c++11 -triple 
x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=50 -DOMP5 -x c++ 
-triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - 
| FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -DOMP5 -x c++ -std=c++11 
-triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -DOMP5 -x c++ -triple 
x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 #ifndef HEADER
 #define HEADER
 
@@ -385,8 +387,8 @@ void parallel_for(float *a, const int n)
 // TERM_DEBUG-DAG: [[DBG_LOC_END]] = !DILocation(line: [[@LINE-18]],
 
 #else // OMP5
-// OMP5-DAG: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
-// OMP5-DAG: [[LOOP_LOC:@.+]] = private unnamed_addr global [[IDENT_T_TY]] { 
i32 0, i32 514, i32 0, i32 0, i8*
+// OMP5: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
+// OMP5: [[LOOP_LOC:@.+]] = private unnamed_addr global [[IDENT_T_TY]] { i32 
0, i32 514, i32 0, i32 0, i8*
 
 // OMP5-LABEL: increment
 int increment () {


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


[PATCH] D65694: Properly instantiate a decltype in argument's default initializer

2019-09-16 Thread Nicholas Allegra via Phabricator via cfe-commits
comex added a comment.

Ping.  I'm not qualified to review this myself but I'd like to see the bug 
fixed. :)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65694/new/

https://reviews.llvm.org/D65694



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


[PATCH] D38479: Make -mgeneral-regs-only more like GCC's

2019-09-16 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv added a comment.

Apologies for the latency of my updates.

> Something I ran into when reviewing https://reviews.llvm.org/D62639 is that 
> on AArch64, for varargs functions, we emit floating-point stores when 
> noimplicitfloat is specified. That seems fine for -mno-implicit-float, but 
> maybe not for -mgeneral-regs-only?

Interesting. Yeah, -mgeneral-regs-only definitely doesn't want to use FP for 
varargs calls. As discussed offline, this doesn't appear to be an issue today, 
and is something we can look into in the future.




Comment at: clang/lib/Sema/SemaExprCXX.cpp:7951
+  // they don't have to write out memcpy() for simple cases. For that reason,
+  // it's very limited in what it will detect.
+  //

george.burgess.iv wrote:
> efriedma wrote:
> > We don't always lower struct copies to memcpy(); I'm not sure this is safe.
> I see; removed. If this check ends up being important (it doesn't seem to be 
> in local builds), we can revisit. :)
(readded as noted)



Comment at: clang/lib/Sema/SemaExprCXX.cpp:8003
+!isRValueOfIllegalType(E) &&
+E->isConstantInitializer(S.getASTContext(), /*ForRef=*/false)) {
+  resetDiagnosticState(InitialState);

efriedma wrote:
> george.burgess.iv wrote:
> > efriedma wrote:
> > > Just because we can constant-fold an expression, doesn't mean we will, 
> > > especially at -O0.
> > Are there any guarantees that we offer along these lines? The code in 
> > particular that this cares about boils down to a bunch of integer literals 
> > doing mixed math with FP literals, all of which gets casted to an `int`. 
> > Conceptually, it seems silly to me to emit an addition for something as 
> > straightforward as `int i = 1 + 2.0;`, even at -O0, though I totally agree 
> > that you're right, and codegen like this is reasonable at -O0: 
> > https://godbolt.org/z/NS0L17
> > 
> > (This also brings up a good point: this visitor probably shouldn't be run 
> > on `IsConstexpr` expressions; fixed that later on)
> On trunk, we now have the notion of a ConstantExpr; this represents an 
> expression which the language guarantees must be constant-evaluated.  For 
> example, initializers for static variables in C are always constant-evaluated.
> 
> (On a related note, now that we have ConstantExpr, the IsConstexpr operand to 
> ActOnFinishFullExpr probably isn't necessary.)
> 
> Beyond that, no, we don't really have any guarantees.  We may or may not try 
> to constant-evaluate an expression, depending on whether we think it'll save 
> compile-time.  For example, we try to fold branch conditions to avoid 
> emitting the guarded block of code, but we don't try to fold the 
> initialization of an arbitrary variable.
> 
> I don't think we want to introduce any additional guarantees here, if we can 
> avoid it.
Resolving per offline discussion; anything wrapped in `ConstantExpr` is no 
longer checked, and we no longer try to constant evaluate anything else.

> On a related note, now that we have ConstantExpr, the IsConstexpr operand to 
> ActOnFinishFullExpr probably isn't necessary

Looks like the lack of `IsConstexpr` fails to save us from one case:

```
constexpr float x = 1.;
```

In this context, all we have to work with from this point is an `IsConstexpr` 
`IntegerLiteral`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D38479/new/

https://reviews.llvm.org/D38479



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


[PATCH] D38479: Make -mgeneral-regs-only more like GCC's

2019-09-16 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv updated this revision to Diff 220416.
george.burgess.iv marked 4 inline comments as done.
george.burgess.iv added a reviewer: efriedma.
george.burgess.iv added a comment.

Chatted with Eli offline; updated here to reflect the conclusions of that.

Importantly, this patch readds some of the peepholes we try to not diagnose, 
since the target users of this quite commonly do things that, after macro 
expansion, fold into e.g., `(int)(3.0 + 1)`. By wrapping these into 
`ConstantExpr`s at the cast point, we get our nice guaranteed lowering to 0 
FP/vector ops in IR.

Similarly for struct assignment, I couldn't find a way to get an assignment of 
a struct of multiple fields to turn into a not-memcpy, so it seems safe to me 
to keep that around. I have tests to this effect, and am happy to add more if 
people can think of cases these tests may not adequately cover.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D38479/new/

https://reviews.llvm.org/D38479

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CodeGen/aarch64-mgeneral_regs_only.c
  clang/test/Sema/aarch64-mgeneral_regs_only.c
  clang/test/SemaCXX/aarch64-mgeneral_regs_only.cpp

Index: clang/test/SemaCXX/aarch64-mgeneral_regs_only.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/aarch64-mgeneral_regs_only.cpp
@@ -0,0 +1,214 @@
+// RUN: %clang_cc1 -triple aarch64-linux-eabi -std=c++11 -general-regs-only %s -verify -DBANNED=float -Wno-unused-value
+// RUN: %clang_cc1 -triple aarch64-linux-eabi -std=c++11 -general-regs-only %s -verify -DBANNED=int '-DVECATTR=__attribute__((ext_vector_type(2)))' -Wno-unused-value
+// RUN: %clang_cc1 -triple aarch64-linux-eabi -std=c++11 -general-regs-only %s -verify -DBANNED=FloatTypedef -Wno-unused-value
+
+using FloatTypedef = float;
+
+#ifndef VECATTR
+#define VECATTR
+#define BannedToInt(x) (x)
+#else
+#define BannedToInt(x) ((x)[0])
+#endif
+
+typedef BANNED BannedTy VECATTR;
+
+namespace default_args {
+int foo(BannedTy = 0); // expected-error 2{{use of floating-point or vector values is disabled}}
+int bar(int = 1.0);
+
+void baz(int a = foo()); // expected-note{{from use of default argument here}}
+void bazz(int a = bar());
+
+void test() {
+  foo(); // expected-note{{from use of default argument here}}
+  bar();
+  baz(); // expected-note{{from use of default argument here}}
+  baz(4);
+  bazz();
+}
+} // namespace default_args
+
+namespace conversions {
+struct ConvertToFloat {
+  explicit operator BannedTy();
+};
+struct ConvertToFloatImplicit { /* implicit */
+  operator BannedTy();
+};
+struct ConvertFromFloat {
+  ConvertFromFloat(BannedTy);
+};
+
+void takeFloat(BannedTy);
+void takeConvertFromFloat(ConvertFromFloat);
+void takeConvertFromFloatRef(const ConvertFromFloat &);
+
+void test() {
+  BannedTy(ConvertToFloat());
+
+  takeFloat(ConvertToFloatImplicit{}); // expected-error{{use of floating-point or vector values is disabled}}
+
+  ConvertFromFloat(0);// expected-error{{use of floating-point or vector values is disabled}}
+  ConvertFromFloat(ConvertToFloatImplicit{}); // expected-error{{use of floating-point or vector values is disabled}}
+
+  ConvertFromFloat{0};// expected-error{{use of floating-point or vector values is disabled}}
+  ConvertFromFloat{ConvertToFloatImplicit{}}; // expected-error{{use of floating-point or vector values is disabled}}
+
+  takeConvertFromFloat(0);// expected-error{{use of floating-point or vector values is disabled}}
+  takeConvertFromFloatRef(0); // expected-error{{use of floating-point or vector values is disabled}}
+
+  takeConvertFromFloat(ConvertFromFloat(0));// expected-error{{use of floating-point or vector values is disabled}}
+  takeConvertFromFloatRef(ConvertFromFloat(0)); // expected-error{{use of floating-point or vector values is disabled}}
+}
+
+void takeImplicitFloat(BannedTy = ConvertToFloatImplicit()); // expected-error{{use of floating-point or vector values is disabled}}
+void test2() {
+  takeImplicitFloat(); // expected-note{{from use of default argument here}}
+}
+} // namespace conversions
+
+namespace refs {
+struct BannedRef {
+  const BannedTy &f;
+  BannedRef(const BannedTy &f) : f(f) {}
+};
+
+BannedTy &getBanned();
+BannedTy getBannedVal();
+
+void foo() {
+  BannedTy &a = getBanned();
+  BannedTy b = getBanned(); // expected-error{{use of floating-point or vector values is disabled}}
+  const BannedTy &c = getBanned();
+  const Ban

r372058 - Push lambda scope earlier when transforming lambda expression

2019-09-16 Thread Nicholas Allegra via cfe-commits
Author: comex
Date: Mon Sep 16 18:43:33 2019
New Revision: 372058

URL: http://llvm.org/viewvc/llvm-project?rev=372058&view=rev
Log:
Push lambda scope earlier when transforming lambda expression

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


Modified:
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=372058&r1=372057&r2=372058&view=diff
==
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Mon Sep 16 18:43:33 2019
@@ -11325,10 +11325,14 @@ TreeTransform::TransformLambdaE
 }
   }
 
+  LambdaScopeInfo *LSI = getSema().PushLambdaScope();
+  Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
+
   // Transform the template parameters, and add them to the current
   // instantiation scope. The null case is handled correctly.
   auto TPL = getDerived().TransformTemplateParameterList(
   E->getTemplateParameterList());
+  LSI->GLTemplateParameterList = TPL;
 
   // Transform the type of the original lambda's call operator.
   // The transformation MUST be done in the CurrentInstantiationScope since
@@ -11355,10 +11359,6 @@ TreeTransform::TransformLambdaE
 NewCallOpType);
   }
 
-  LambdaScopeInfo *LSI = getSema().PushLambdaScope();
-  Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
-  LSI->GLTemplateParameterList = TPL;
-
   // Create the local class that will describe the lambda.
   CXXRecordDecl *OldClass = E->getLambdaClass();
   CXXRecordDecl *Class

Modified: cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp?rev=372058&r1=372057&r2=372058&view=diff
==
--- cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp (original)
+++ cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp Mon Sep 16 18:43:33 
2019
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s
 // expected-no-diagnostics
 
 // Test default template arguments for function templates.
@@ -114,3 +115,17 @@ namespace rdar34167492 {
 S _a{};
   };
 }
+
+#if __cplusplus >= 201402L
+namespace lambda {
+  // Verify that a default argument in a lambda can refer to the type of a
+  // previous `auto` argument without crashing.
+  template 
+  void bar() {
+(void) [](auto c, int x = sizeof(decltype(c))) {};
+  }
+  void foo() {
+bar();
+  }
+} // namespace lambda
+#endif


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


[PATCH] D66067: Push lambda scope earlier when transforming lambda expression

2019-09-16 Thread Nicholas Allegra via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL372058: Push lambda scope earlier when transforming lambda 
expression (authored by comex, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66067?vs=217230&id=220419#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66067/new/

https://reviews.llvm.org/D66067

Files:
  cfe/trunk/lib/Sema/TreeTransform.h
  cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp


Index: cfe/trunk/lib/Sema/TreeTransform.h
===
--- cfe/trunk/lib/Sema/TreeTransform.h
+++ cfe/trunk/lib/Sema/TreeTransform.h
@@ -11325,10 +11325,14 @@
 }
   }
 
+  LambdaScopeInfo *LSI = getSema().PushLambdaScope();
+  Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
+
   // Transform the template parameters, and add them to the current
   // instantiation scope. The null case is handled correctly.
   auto TPL = getDerived().TransformTemplateParameterList(
   E->getTemplateParameterList());
+  LSI->GLTemplateParameterList = TPL;
 
   // Transform the type of the original lambda's call operator.
   // The transformation MUST be done in the CurrentInstantiationScope since
@@ -11355,10 +11359,6 @@
 NewCallOpType);
   }
 
-  LambdaScopeInfo *LSI = getSema().PushLambdaScope();
-  Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
-  LSI->GLTemplateParameterList = TPL;
-
   // Create the local class that will describe the lambda.
   CXXRecordDecl *OldClass = E->getLambdaClass();
   CXXRecordDecl *Class
Index: cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp
===
--- cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp
+++ cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s
 // expected-no-diagnostics
 
 // Test default template arguments for function templates.
@@ -114,3 +115,17 @@
 S _a{};
   };
 }
+
+#if __cplusplus >= 201402L
+namespace lambda {
+  // Verify that a default argument in a lambda can refer to the type of a
+  // previous `auto` argument without crashing.
+  template 
+  void bar() {
+(void) [](auto c, int x = sizeof(decltype(c))) {};
+  }
+  void foo() {
+bar();
+  }
+} // namespace lambda
+#endif


Index: cfe/trunk/lib/Sema/TreeTransform.h
===
--- cfe/trunk/lib/Sema/TreeTransform.h
+++ cfe/trunk/lib/Sema/TreeTransform.h
@@ -11325,10 +11325,14 @@
 }
   }
 
+  LambdaScopeInfo *LSI = getSema().PushLambdaScope();
+  Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
+
   // Transform the template parameters, and add them to the current
   // instantiation scope. The null case is handled correctly.
   auto TPL = getDerived().TransformTemplateParameterList(
   E->getTemplateParameterList());
+  LSI->GLTemplateParameterList = TPL;
 
   // Transform the type of the original lambda's call operator.
   // The transformation MUST be done in the CurrentInstantiationScope since
@@ -11355,10 +11359,6 @@
 NewCallOpType);
   }
 
-  LambdaScopeInfo *LSI = getSema().PushLambdaScope();
-  Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
-  LSI->GLTemplateParameterList = TPL;
-
   // Create the local class that will describe the lambda.
   CXXRecordDecl *OldClass = E->getLambdaClass();
   CXXRecordDecl *Class
Index: cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp
===
--- cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp
+++ cfe/trunk/test/SemaTemplate/default-arguments-cxx0x.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s
 // expected-no-diagnostics
 
 // Test default template arguments for function templates.
@@ -114,3 +115,17 @@
 S _a{};
   };
 }
+
+#if __cplusplus >= 201402L
+namespace lambda {
+  // Verify that a default argument in a lambda can refer to the type of a
+  // previous `auto` argument without crashing.
+  template 
+  void bar() {
+(void) [](auto c, int x = sizeof(decltype(c))) {};
+  }
+  void foo() {
+bar();
+  }
+} // namespace lambda
+#endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66830: Consumed checker: various improvements

2019-09-16 Thread Nicholas Allegra via Phabricator via cfe-commits
comex abandoned this revision.
comex added a comment.
Herald added a subscriber: dmgreen.

Sounds good; I'll split this into a few separate patches.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66830/new/

https://reviews.llvm.org/D66830



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


[PATCH] D65917: [clang-tidy] Added check for the Google style guide's category method naming rule.

2019-09-16 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore requested changes to this revision.
stephanemoore added inline comments.
This revision now requires changes to proceed.



Comment at: 
clang-tools-extra/clang-tidy/google/RequireCategoryMethodPrefixesCheck.cpp:23
+  Finder->addMatcher(objcMethodDecl(hasDeclContext(
+  objcCategoryDecl())).bind(CustomCategoryMethodIdentifier), this);
+}

Technically category method prefixing is only strictly enforced on classes that 
are shared:
"If a class is not shared with other projects, categories extending it may omit 
name prefixes and method name prefixes."
https://github.com/google/styleguide/blob/gh-pages/objcguide.md#category-naming

With that in mind, perhaps we should match on categories on classes that extend 
classes that are declared in system headers? I think you can accomplish that by 
adding a custom inner matcher in `objcCategoryDecl` which pulls out the 
Objective-C interface using 
[clang::ObjCCategoryDecl::getClassInterface](https://clang.llvm.org/doxygen/classclang_1_1ObjCCategoryDecl.html#acdb14eeca277cfa745a4e8e842312008)
 and then add `isExpansionInSystemHeader` as an inner matcher on the custom 
inner matcher. WDYT? Let me know if you need help putting together.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/google-objc-require-category-method-prefixes.rst:41
+
+.. option:: ExpectedPrefixes
+

This option seems to describe a list of class prefixes that are whitelisted. If 
that is the case, perhaps `WhitelistedPrefixes` or `WhitelistedClassPrefixes` 
would be a better name for the option? WDYT?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65917/new/

https://reviews.llvm.org/D65917



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


[PATCH] D67647: [Consumed] Refactor handleCall to take function argument list. NFC.

2019-09-16 Thread Nicholas Allegra via Phabricator via cfe-commits
comex created this revision.
comex added a reviewer: dblaikie.
Herald added subscribers: cfe-commits, dmgreen, kristof.beyls.
Herald added a project: clang.

Currently, `handleCall` takes a `CallExpr` as an argument and retrieves the 
arguments from there.  This changes it to take the argument list as a separate 
argument of type `ArrayRef`.

The main motivation that I want `VisitCXXConstructExpr` to also be able to 
invoke `handleCall`, even though `CXXConstructExpr` is not a subclass of 
`CallExpr`.  But actually adding that will wait for a future patch.

However, this also fixes a minor bug in `VisitCXXOperatorCallExpr`:

  if (const auto *MCall = dyn_cast(Call))
handleCall(MCall, MCall->getImplicitObjectArgument(), FunDecl);
  else
handleCall(Call, Call->getArg(0), FunDecl);

`Call` here is a `CXXOperatorCallExpr`, and `CXXMemberCallExpr` is a sibling 
class, so the cast will never succeed.  CXXMemberCallExprs go through a 
separate visitor, `VisitCXXMemberCallExpr`.

On the other hand, this logic may be intended to reflect the fact that C++ 
operators can be declared as either methods or free functions.  The correct way 
to differentiate these is shown at the beginning of handleCall:

  unsigned Offset = 0;
  if (isa(Call) && isa(FunD))
Offset = 1;  // first argument is 'this'

For `CXXOperatorCallExpr`s, if the decl is a `CXXMethodDecl`, the first 
argument is `this`; otherwise there is no `this`.

Going back to the other first: currently, since the `dyn_cast` always fails, it 
always passes `Call->getArg(0)` as `ObjArg` (i.e. the expression representing 
`this`), even for operators declared as free functions.  However, this is 
harmless, because `ObjArg` is only used if the function is marked as one of 
`set_typestate` or `test_typestate`, or `callable_when`, yet those attributes 
are only allowed on methods.  `Call->getArg(0)` will crash if there are zero 
arguments, but the only kind of non-method operator function allowed to have 
zero arguments is a user-defined literal, and those do not produce 
`CXXOperatorCallExpr`s.

The bug could be fixed by changing the first snippet to check for 
`CXXMethodDecl` like the second one, but this refactor makes things cleaner by 
only having to check in one place.


Repository:
  rC Clang

https://reviews.llvm.org/D67647

Files:
  lib/Analysis/Consumed.cpp

Index: lib/Analysis/Consumed.cpp
===
--- lib/Analysis/Consumed.cpp
+++ lib/Analysis/Consumed.cpp
@@ -494,8 +494,8 @@
   void checkCallability(const PropagationInfo &PInfo,
 const FunctionDecl *FunDecl,
 SourceLocation BlameLoc);
-  bool handleCall(const CallExpr *Call, const Expr *ObjArg,
-  const FunctionDecl *FunD);
+  bool handleCall(const Expr *Call, const Expr *ObjArg,
+  ArrayRef Args, const FunctionDecl *FunD);
 
   void VisitBinaryOperator(const BinaryOperator *BinOp);
   void VisitCallExpr(const CallExpr *Call);
@@ -608,22 +608,21 @@
 // Factors out common behavior for function, method, and operator calls.
 // Check parameters and set parameter state if necessary.
 // Returns true if the state of ObjArg is set, or false otherwise.
-bool ConsumedStmtVisitor::handleCall(const CallExpr *Call, const Expr *ObjArg,
+bool ConsumedStmtVisitor::handleCall(const Expr *Call,
+ const Expr *ObjArg,
+ ArrayRef Args,
  const FunctionDecl *FunD) {
-  unsigned Offset = 0;
-  if (isa(Call) && isa(FunD))
-Offset = 1;  // first argument is 'this'
-
   // check explicit parameters
-  for (unsigned Index = Offset; Index < Call->getNumArgs(); ++Index) {
+  unsigned Index = 0;
+  for (const Expr *Arg : Args) {
 // Skip variable argument lists.
-if (Index - Offset >= FunD->getNumParams())
+if (Index >= FunD->getNumParams())
   break;
 
-const ParmVarDecl *Param = FunD->getParamDecl(Index - Offset);
+const ParmVarDecl *Param = FunD->getParamDecl(Index++);
 QualType ParamType = Param->getType();
 
-InfoEntry Entry = findInfo(Call->getArg(Index));
+InfoEntry Entry = findInfo(Arg);
 
 if (Entry == PropagationMap.end() || Entry->second.isTest())
   continue;
@@ -636,7 +635,7 @@
 
   if (ParamState != ExpectedState)
 Analyzer.WarningsHandler.warnParamTypestateMismatch(
-  Call->getArg(Index)->getExprLoc(),
+  Arg->getExprLoc(),
   stateToString(ExpectedState), stateToString(ParamState));
 }
 
@@ -749,7 +748,9 @@
 return;
   }
 
-  handleCall(Call, nullptr, FunDecl);
+  handleCall(Call, nullptr,
+ llvm::makeArrayRef(Call->getArgs(), Call->getNumArgs()),
+ FunDecl);
   propagateReturnType(Call, FunDecl);
 }
 
@@ -805,7 +806,8 @@
   if (!MD)
 return;
 
-  handleCall(Call, Call->getImplicitObjectArgument(), MD);
+  handleCall(Call, Call->getImplicitObjectA

r372061 - Remove reliance on lax vector conversions from altivec.h in VSX mode.

2019-09-16 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Sep 16 20:56:26 2019
New Revision: 372061

URL: http://llvm.org/viewvc/llvm-project?rev=372061&view=rev
Log:
Remove reliance on lax vector conversions from altivec.h in VSX mode.

Modified:
cfe/trunk/lib/Headers/altivec.h
cfe/trunk/test/CodeGen/altivec-ct.c
cfe/trunk/test/CodeGen/builtins-ppc-error.c
cfe/trunk/test/CodeGen/builtins-ppc-p9vector.c
cfe/trunk/test/CodeGen/builtins-ppc-vsx.c

Modified: cfe/trunk/lib/Headers/altivec.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/altivec.h?rev=372061&r1=372060&r2=372061&view=diff
==
--- cfe/trunk/lib/Headers/altivec.h (original)
+++ cfe/trunk/lib/Headers/altivec.h Mon Sep 16 20:56:26 2019
@@ -2761,8 +2761,8 @@ static __inline__ vector double __ATTRS_
   return (vector double)__builtin_vsx_lxvl(__a, (__b << 56));
 }
 
-static __inline__ vector double __ATTRS_o_ai vec_xl_len_r(unsigned char *__a,
-  size_t __b) {
+static __inline__ vector unsigned char __ATTRS_o_ai
+vec_xl_len_r(unsigned char *__a, size_t __b) {
   vector unsigned char __res =
   (vector unsigned char)__builtin_vsx_lxvll(__a, (__b << 56));
 #ifdef __LITTLE_ENDIAN__
@@ -2912,10 +2912,11 @@ static __inline__ vector double __ATTRS_
 #ifdef __VSX__
 #define vec_cts(__a, __b)  
\
   _Generic((__a), vector float 
\
-   : __builtin_altivec_vctsxs((__a), (__b)), vector double 
\
+   : __builtin_altivec_vctsxs((vector float)(__a), (__b)), 
\
+ vector double 
\
: __extension__({   
\
  vector double __ret = 
\
- (__a) *   
\
+ (vector double)(__a) *
\
  (vector double)(vector unsigned long long)((0x3ffULL + (__b)) 
\
 << 52);
\
  __builtin_convertvector(__ret, vector signed long long);  
\
@@ -2933,10 +2934,11 @@ static __inline__ vector double __ATTRS_
 #ifdef __VSX__
 #define vec_ctu(__a, __b)  
\
   _Generic((__a), vector float 
\
-   : __builtin_altivec_vctuxs((__a), (__b)), vector double 
\
+   : __builtin_altivec_vctuxs((vector float)(__a), (__b)), 
\
+ vector double 
\
: __extension__({   
\
  vector double __ret = 
\
- (__a) *   
\
+ (vector double)(__a) *
\
  (vector double)(vector unsigned long long)((0x3ffULL + __b)   
\
 << 52);
\
  __builtin_convertvector(__ret, vector unsigned long long);
\
@@ -6301,19 +6303,20 @@ static __inline__ vector float __ATTRS_o
 #ifdef __VSX__
 static __inline__ vector double __ATTRS_o_ai vec_or(vector bool long long __a,
 vector double __b) {
-  return (vector unsigned long long)__a | (vector unsigned long long)__b;
+  return (vector double)((vector unsigned long long)__a |
+ (vector unsigned long long)__b);
 }
 
 static __inline__ vector double __ATTRS_o_ai vec_or(vector double __a,
 vector bool long long __b) 
{
-  return (vector unsigned long long)__a | (vector unsigned long long)__b;
+  return (vector double)((vector unsigned long long)__a |
+ (vector unsigned long long)__b);
 }
 
 static __inline__ vector double __ATTRS_o_ai vec_or(vector double __a,
 vector double __b) {
-  vector unsigned long long __res =
-  (vector unsigned long long)__a | (vector unsigned long long)__b;
-  return (vector double)__res;
+  return (vector double)((vector unsigned long long)__a |
+ (vector unsigned long long)__b);
 }
 
 static __inline__ vector signed long long __ATTRS_o_ai
@@ -14781,7 +14784,7 @@ static __inline__ int __ATTRS_o_ai vec_a
 static __inline__ int __ATTRS_o_ai vec_all_ne(vector float __a,
   vector float __b) {
 #ifdef __VSX__
-  return __builtin_vsx_xvcmpeqdp_p(__CR6_EQ, __a, __b);
+  return __builtin_vsx_xvcmpeqd

r372063 - Fix reliance on -flax-vector-conversions in AVX intrinsics headers and

2019-09-16 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Sep 16 20:56:30 2019
New Revision: 372063

URL: http://llvm.org/viewvc/llvm-project?rev=372063&view=rev
Log:
Fix reliance on -flax-vector-conversions in AVX intrinsics headers and
corresponding tests.

Modified:
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/test/CodeGen/avx-builtins.c
cfe/trunk/test/CodeGen/avx-cmp-builtins.c
cfe/trunk/test/CodeGen/avx512f-builtins.c

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=372063&r1=372062&r2=372063&view=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Mon Sep 16 20:56:30 2019
@@ -7658,13 +7658,13 @@ _mm512_maskz_getexp_ps (__mmask16 __U, _
 #define _mm512_i32gather_ps(index, addr, scale) \
   (__m512)__builtin_ia32_gathersiv16sf((__v16sf)_mm512_undefined_ps(), \
(void const *)(addr), \
-   (__v16sf)(__m512)(index), \
+   (__v16si)(__m512)(index), \
(__mmask16)-1, (int)(scale))
 
 #define _mm512_mask_i32gather_ps(v1_old, mask, index, addr, scale) \
   (__m512)__builtin_ia32_gathersiv16sf((__v16sf)(__m512)(v1_old), \
(void const *)(addr), \
-   (__v16sf)(__m512)(index), \
+   (__v16si)(__m512)(index), \
(__mmask16)(mask), (int)(scale))
 
 #define _mm512_i32gather_epi32(index, addr, scale) \

Modified: cfe/trunk/test/CodeGen/avx-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx-builtins.c?rev=372063&r1=372062&r2=372063&view=diff
==
--- cfe/trunk/test/CodeGen/avx-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avx-builtins.c Mon Sep 16 20:56:30 2019
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +avx -emit-llvm -o - -Wall -Werror | FileCheck %s
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +avx -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck 
%s
-// RUN: %clang_cc1 -fms-extensions -fms-compatibility -ffreestanding %s 
-triple=x86_64-windows-msvc -target-feature +avx -emit-llvm -o - -Wall -Werror 
| FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - -Wall -Werror 
| FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx -fno-signed-char -emit-llvm -o 
- -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -fms-extensions 
-fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc 
-target-feature +avx -emit-llvm -o - -Wall -Werror | FileCheck %s
 
 
 #include 
@@ -105,7 +105,7 @@ __m256d test_mm256_broadcast_sd(double*
   return _mm256_broadcast_sd(A);
 }
 
-__m128d test_mm_broadcast_ss(float* A) {
+__m128 test_mm_broadcast_ss(float* A) {
   // CHECK-LABEL: test_mm_broadcast_ss
   // CHECK: load float, float* %{{.*}}
   // CHECK: insertelement <4 x float> undef, float %{{.*}}, i32 0
@@ -115,7 +115,7 @@ __m128d test_mm_broadcast_ss(float* A) {
   return _mm_broadcast_ss(A);
 }
 
-__m256d test_mm256_broadcast_ss(float* A) {
+__m256 test_mm256_broadcast_ss(float* A) {
   // CHECK-LABEL: test_mm256_broadcast_ss
   // CHECK: load float, float* %{{.*}}
   // CHECK: insertelement <8 x float> undef, float %{{.*}}, i32 0
@@ -1278,7 +1278,7 @@ __m128 test_mm_maskload_ps(float* A, __m
   return _mm_maskload_ps(A, B);
 }
 
-__m256d test_mm256_maskload_ps(float* A, __m256i B) {
+__m256 test_mm256_maskload_ps(float* A, __m256i B) {
   // CHECK-LABEL: test_mm256_maskload_ps
   // CHECK: call <8 x float> @llvm.x86.avx.maskload.ps.256(i8* %{{.*}}, <8 x 
i32> %{{.*}})
   return _mm256_maskload_ps(A, B);

Modified: cfe/trunk/test/CodeGen/avx-cmp-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx-cmp-builtins.c?rev=372063&r1=372062&r2=372063&view=diff
==
--- cfe/trunk/test/CodeGen/avx-cmp-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avx-cmp-builtins.c Mon Sep 16 20:56:30 2019
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -ffreestanding %s -O3 -triple=x86_64-apple-darwin 
-target-feature +avx -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -O3 
-triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - | FileCheck %s
 // FIXME: The shufflevector instructions in test_cmpgt_sd are relying on O3 
here.
 
 
@@ -14,7 +14,7 @@ __m128d test_cmp_sd(__m128d a, __m128d b
   return _mm_cmp_sd(

r372062 - Fix reliance on lax vector conversions in tests for x86 intrinsics.

2019-09-16 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Sep 16 20:56:28 2019
New Revision: 372062

URL: http://llvm.org/viewvc/llvm-project?rev=372062&view=rev
Log:
Fix reliance on lax vector conversions in tests for x86 intrinsics.

Modified:
cfe/trunk/test/CodeGen/const-init.c
cfe/trunk/test/CodeGen/ppc-smmintrin.c
cfe/trunk/test/CodeGen/sse-builtins.c
cfe/trunk/test/CodeGen/sse.c
cfe/trunk/test/CodeGen/target-builtin-error.c
cfe/trunk/test/CodeGen/x86-builtins-vector-width.c
cfe/trunk/test/Headers/xmmintrin.c
cfe/trunk/test/Sema/builtins-x86.c

Modified: cfe/trunk/test/CodeGen/const-init.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/const-init.c?rev=372062&r1=372061&r2=372062&view=diff
==
--- cfe/trunk/test/CodeGen/const-init.c (original)
+++ cfe/trunk/test/CodeGen/const-init.c Mon Sep 16 20:56:28 2019
@@ -141,8 +141,8 @@ void g28() {
   // CHECK: @g28.b = internal global <12 x i16> 
   // CHECK: @g28.c = internal global <2 x x86_fp80> , align 32
   static v1i64 a = (v1i64)10LL;
-  static v12i16 b = (v2f80){1,2};
-  static v2f80 c = (v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0};
+  static v12i16 b = (v12i16)(v2f80){1,2};
+  static v2f80 c = (v2f80)(v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0};
 }
 
 // PR13643

Modified: cfe/trunk/test/CodeGen/ppc-smmintrin.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ppc-smmintrin.c?rev=372062&r1=372061&r2=372062&view=diff
==
--- cfe/trunk/test/CodeGen/ppc-smmintrin.c (original)
+++ cfe/trunk/test/CodeGen/ppc-smmintrin.c Mon Sep 16 20:56:28 2019
@@ -15,7 +15,7 @@ test_extract() {
   _mm_extract_epi8(mi, 0);
   _mm_extract_epi32(mi, 0);
   _mm_extract_epi64(mi, 0);
-  _mm_extract_ps(mi, 0);
+  _mm_extract_ps((__m128)mi, 0);
 }
 
 // CHECK-LABEL: @test_extract

Modified: cfe/trunk/test/CodeGen/sse-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/sse-builtins.c?rev=372062&r1=372061&r2=372062&view=diff
==
--- cfe/trunk/test/CodeGen/sse-builtins.c (original)
+++ cfe/trunk/test/CodeGen/sse-builtins.c Mon Sep 16 20:56:28 2019
@@ -714,7 +714,7 @@ void test_mm_storeu_ps(float* x,  __m128
   _mm_storeu_ps(x, y);
 }
 
-void test_mm_stream_ps(float*A, __m128d B) {
+void test_mm_stream_ps(float*A, __m128 B) {
   // CHECK-LABEL: test_mm_stream_ps
   // CHECK: store <4 x float> %{{.*}}, <4 x float>* %{{.*}}, align 16, 
!nontemporal
   _mm_stream_ps(A, B);

Modified: cfe/trunk/test/CodeGen/sse.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/sse.c?rev=372062&r1=372061&r2=372062&view=diff
==
--- cfe/trunk/test/CodeGen/sse.c (original)
+++ cfe/trunk/test/CodeGen/sse.c Mon Sep 16 20:56:28 2019
@@ -5,37 +5,37 @@
 #include 
 
 // Byte-shifts look reversed due to xmm register layout
-__m128 test_mm_slli_si128(__m128 a) {
+__m128i test_mm_slli_si128(__m128i a) {
   // CHECK-LABEL: @test_mm_slli_si128
   // CHECK: shufflevector <16 x i8> <{{.*}}, i8 0, i8 0, i8 0, i8 0, i8 0>, 
<16 x i8> {{.*}}, <16 x i32> 
   return _mm_slli_si128(a, 5);
 }
 
-__m128 test_mm_slli_si128_0(__m128 a) {
+__m128i test_mm_slli_si128_0(__m128i a) {
   // CHECK-LABEL: @test_mm_slli_si128_0
   // CHECK-NOT: shufflevector
   return _mm_slli_si128(a, 0);
 }
 
-__m128 test_mm_slli_si128_16(__m128 a) {
+__m128i test_mm_slli_si128_16(__m128i a) {
   // CHECK-LABEL: @test_mm_slli_si128_16
   // CHECK-NOT: shufflevector
   return _mm_slli_si128(a, 16);
 }
 
-__m128 test_mm_srli_si128(__m128 a) {
+__m128i test_mm_srli_si128(__m128i a) {
   // CHECK-LABEL: @test_mm_srli_si128
   // CHECK: shufflevector <16 x i8> {{.*}}, <16 x i8> , <16 x i32> 
   return _mm_srli_si128(a, 5);
 }
 
-__m128 test_mm_srli_si128_0(__m128 a) {
+__m128i test_mm_srli_si128_0(__m128i a) {
   // CHECK-LABEL: @test_mm_srli_si128_0
   // CHECK-NOT: shufflevector
   return _mm_srli_si128(a, 0);
 }
 
-__m128 test_mm_srli_si128_16(__m128 a) {
+__m128i test_mm_srli_si128_16(__m128i a) {
   // CHECK-LABEL: @test_mm_srli_si128_16
   // CHECK-NOT: shufflevector
   return _mm_srli_si128(a, 16);

Modified: cfe/trunk/test/CodeGen/target-builtin-error.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/target-builtin-error.c?rev=372062&r1=372061&r2=372062&view=diff
==
--- cfe/trunk/test/CodeGen/target-builtin-error.c (original)
+++ cfe/trunk/test/CodeGen/target-builtin-error.c Mon Sep 16 20:56:28 2019
@@ -3,6 +3,6 @@
 
 #include 
 
-__m128d foo(__m128d a, __m128d b) {
+__m128 foo(__m128 a, __m128 b) {
   return __builtin_ia32_addsubps(b, a); // expected-error 
{{'__builtin_ia32_addsubps' needs target feature sse3}}
 }

Modified: cfe/trunk/test/CodeGen/x86-builtins-vector-width.c

  1   2   >