[PATCH] D87243: [cmake] Centralize LLVM_ENABLE_WARNINGS option

2020-09-07 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

This is not nessesairy correct, at least the clang can be built in standalone 
mode, not as part of monorepo checkout (i.e. it's `clang/cmakelists.txt` is the 
root cmakelists, not `llvm/cmakelists.txt`'s)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87243

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


[PATCH] D87243: [cmake] Centralize LLVM_ENABLE_WARNINGS option

2020-09-07 Thread Dave Lee via Phabricator via cfe-commits
kastiglione added a comment.

The `LLVM_ENABLE_WARNINGS` variable is read only within 
`HandleLLVMOptions.cmake`. Outside declarations/defaults have effect only when 
`HandleLLVMOptions` is loaded, one way or another.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87243

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


[PATCH] D83360: [InstSimplify] Remove select ?, undef, X -> X and select ?, X, undef -> X

2020-09-07 Thread Craig Topper via Phabricator via cfe-commits
craig.topper abandoned this revision.
craig.topper added a comment.

This got replaced by D85765 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83360

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


[PATCH] D86699: [SyntaxTree] Ignore implicit non-leaf `CXXConstructExpr`

2020-09-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 290327.
eduucaldas marked 3 inline comments as done.
eduucaldas added a comment.

answer comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86699

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp

Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -1745,19 +1745,15 @@
 struct X {
   friend X operator+(X, const X&);
 };
-// FIXME: Remove additional `UnknownExpression` wrapping `x`. For that, ignore
-// implicit copy constructor called on `x`. This should've been ignored already,
-// as we `IgnoreImplicit` when traversing an `Stmt`.
 void test(X x, X y) {
   [[x + y]];
 }
 )cpp",
   {R"txt(
 BinaryOperatorExpression Expression
-|-UnknownExpression LeftHandSide
-| `-IdExpression
-|   `-UnqualifiedId UnqualifiedId
-| `-'x'
+|-IdExpression LeftHandSide
+| `-UnqualifiedId UnqualifiedId
+|   `-'x'
 |-'+' OperatorToken
 `-IdExpression RightHandSide
   `-UnqualifiedId UnqualifiedId
@@ -3821,26 +3817,135 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, InitDeclarator_Equal) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S { S(int);};
+void test() {
+  [[S s = 1]];
+}
+)cpp",
+  {R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s'
+  |-'='
+  `-IntegerLiteralExpression
+`-'1' LiteralToken
+)txt"}));
+}
+
 TEST_P(SyntaxTreeTest, InitDeclarator_Brace) {
   if (!GetParam().isCXX11OrLater()) {
 return;
   }
-  EXPECT_TRUE(treeDumpEqual(
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
   R"cpp(
-int a {};
+struct S { 
+  S();
+  S(int);
+  S(int, float);
+};
+void test(){
+  [[S s0{}]];
+  [[S s1{1}]];
+  [[S s2{1, 2.}]];
+}
 )cpp",
-  R"txt(
-TranslationUnit Detached
-`-SimpleDeclaration
-  |-'int'
-  |-SimpleDeclarator Declarator
-  | |-'a'
-  | `-UnknownExpression
-  |   `-UnknownExpression
-  | |-'{'
-  | `-'}'
-  `-';'
-)txt"));
+  {R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  `-UnknownExpression
+|-'s0'
+|-'{'
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  `-UnknownExpression
+|-'s1'
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  `-UnknownExpression
+|-'s2'
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+|-','
+|-FloatingLiteralExpression
+| `-'2.' LiteralToken
+`-'}'
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, InitDeclarator_EqualBrace) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S { 
+  S();
+  S(int);
+  S(int, float);
+};
+void test() {
+  [[S s0 = {}]];
+  [[S s1 = {1}]];
+  [[S s2 = {1, 2.}]];
+}
+)cpp",
+  {R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s0'
+  |-'='
+  `-UnknownExpression
+|-'{'
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s1'
+  |-'='
+  `-UnknownExpression
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s2'
+  |-'='
+  `-UnknownExpression
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+|-','
+|-FloatingLiteralExpression
+| `-'2.' LiteralToken
+`-'}'
+)txt"}));
 }
 
 TEST_P(SyntaxTreeTest, InitDeclarator_Paren) {
@@ -3851,15 +3956,133 @@
   R"cpp(
 struct S {
   S(int);
+  S(int, float);
 };
-[[S s(1);]]
+[[S s1(1);]]
+[[S s2(1, 2.);]]
 )cpp",
   {R"txt(
 SimpleDeclaration
 |-'S'
 |-SimpleDeclarator Declarator
 | `-UnknownExpression
-|   |-'s'
+|   |-'s1'
+|   |-'('
+|   |-IntegerLiteralExpression
+|   | `-'1' LiteralToken
+|   `-')'
+`-';'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+|-SimpleDeclarator Declarator
+| `-UnknownExpression
+|   |-'s2'
+|   |-'('
+|   |-IntegerLiteralExpression
+|   | `-'1' LiteralToken
+|   |-','
+|   |-FloatingLiteralExpression
+|   | `-'2.' LiteralToken
+|   `-')'
+`-';'
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, ImplicitConversion_Argument) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct X {
+  X(int);
+};
+void TakeX(const X&);
+void test() {
+  [[TakeX(1)]];
+}
+)cpp",
+  {R"txt(
+CallExpression Expression
+|-IdExpression Callee
+| `-UnqualifiedId UnqualifiedId
+|   `-'TakeX'
+|-'(' OpenParen
+|-CallArguments Arguments
+| `-IntegerLiteralExpression ListElement
+|   `-'1' LiteralToken
+`-')' CloseParen
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, 

[PATCH] D87201: [clang-format] Add a option for the position of Java static import

2020-09-07 Thread Jake Merdich via Phabricator via cfe-commits
JakeMerdichAMD added inline comments.



Comment at: clang/include/clang/Format/Format.h:1705
+  /// \endcode
+  bool JavaStaticImportAfterImport;
+

bc-lee wrote:
> JakeMerdichAMD wrote:
> > 3 things here:
> > 
> > 1. Did you mix up the true and false cases?
> > 2. (nit) You should also note that if this option is false, all static 
> > imports are before all non-static imports (as opposed to mixed together 
> > alphabetically). I was confused on first glance.
> > 3. Please add this config option to 
> > FormatTests.cpp:ParsesConfigurationBools.
> I understand. The description is somewhat misleading. 
New phrasing makes it clear, but true and false are still inverted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87201

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


[PATCH] D87256: [clangd] Avoid relations being overwritten in a header shard

2020-09-07 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added a reviewer: hokein.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.
nridge requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

Fixes https://github.com/clangd/clangd/issues/510


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87256

Files:
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/FileIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -547,6 +547,8 @@
   Sym2.CanonicalDeclaration.FileURI = BHeaderUri.c_str();
   Sym2.Definition.FileURI = BSourceUri.c_str();
 
+  auto Sym3 = symbol("3"); // not stored
+
   IndexFileIn IF;
   {
 SymbolSlab::Builder B;
@@ -562,12 +564,12 @@
   }
   {
 RelationSlab::Builder B;
-// Should be stored in a.h
-B.insert(Relation{Sym1.ID, RelationKind::BaseOf, Sym2.ID});
 // Should be stored in b.h
+B.insert(Relation{Sym1.ID, RelationKind::BaseOf, Sym2.ID});
+// Should be stored in a.h
 B.insert(Relation{Sym2.ID, RelationKind::BaseOf, Sym1.ID});
-// Dangling relation should be dropped.
-B.insert(Relation{symbol("3").ID, RelationKind::BaseOf, Sym1.ID});
+// Should be stored in a.h even though it's dangling
+B.insert(Relation{Sym3.ID, RelationKind::BaseOf, Sym1.ID});
 IF.Relations.emplace(std::move(B).build());
   }
 
@@ -605,7 +607,8 @@
 EXPECT_THAT(*Shard->Refs, IsEmpty());
 EXPECT_THAT(
 *Shard->Relations,
-UnorderedElementsAre(Relation{Sym1.ID, RelationKind::BaseOf, Sym2.ID}));
+UnorderedElementsAre(Relation{Sym2.ID, RelationKind::BaseOf, Sym1.ID},
+ Relation{Sym3.ID, RelationKind::BaseOf, Sym1.ID}));
 ASSERT_THAT(Shard->Sources->keys(), UnorderedElementsAre(AHeaderUri));
 EXPECT_THAT(Shard->Sources->lookup(AHeaderUri).DirectIncludes, IsEmpty());
 EXPECT_TRUE(Shard->Cmd.hasValue());
@@ -617,7 +620,7 @@
 EXPECT_THAT(*Shard->Refs, IsEmpty());
 EXPECT_THAT(
 *Shard->Relations,
-UnorderedElementsAre(Relation{Sym2.ID, RelationKind::BaseOf, Sym1.ID}));
+UnorderedElementsAre(Relation{Sym1.ID, RelationKind::BaseOf, Sym2.ID}));
 ASSERT_THAT(Shard->Sources->keys(),
 UnorderedElementsAre(BHeaderUri, AHeaderUri));
 EXPECT_THAT(Shard->Sources->lookup(BHeaderUri).DirectIncludes,
Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -229,6 +229,49 @@
FileURI("unittest:///root/B.cc")}));
 }
 
+TEST_F(BackgroundIndexTest, RelationsMultiFile) {
+  MockFS FS;
+  FS.Files[testPath("root/RAV.h")] = "template  class RAV {};";
+  FS.Files[testPath("root/A.cc")] = R"cpp(
+#include "RAV.h"
+class A : public RAV {};
+  )cpp";
+  FS.Files[testPath("root/B.cc")] = R"cpp(
+#include "RAV.h"
+class B : public RAV {};
+  )cpp";
+
+  llvm::StringMap Storage;
+  size_t CacheHits = 0;
+  MemoryShardStorage MSS(Storage, CacheHits);
+  OverlayCDB CDB(/*Base=*/nullptr);
+  BackgroundIndex Index(FS, CDB, [&](llvm::StringRef) { return  },
+/*Opts=*/{});
+
+  tooling::CompileCommand Cmd;
+  Cmd.Filename = testPath("root/A.cc");
+  Cmd.Directory = testPath("root");
+  Cmd.CommandLine = {"clang++", Cmd.Filename};
+  CDB.setCompileCommand(testPath("root/A.cc"), Cmd);
+  ASSERT_TRUE(Index.blockUntilIdleForTest());
+
+  Cmd.Filename = testPath("root/B.cc");
+  Cmd.CommandLine = {"clang++", Cmd.Filename};
+  CDB.setCompileCommand(testPath("root/B.cc"), Cmd);
+  ASSERT_TRUE(Index.blockUntilIdleForTest());
+
+  auto HeaderShard = MSS.loadShard(testPath("root/RAV.h"));
+  EXPECT_NE(HeaderShard, nullptr);
+  SymbolID RAV = findSymbol(*HeaderShard->Symbols, "RAV").ID;
+
+  RelationsRequest Req;
+  Req.Subjects.insert(RAV);
+  Req.Predicate = RelationKind::BaseOf;
+  uint32_t Results = 0;
+  Index.relations(Req, [&](const SymbolID &, const Symbol &) { ++Results; });
+  EXPECT_EQ(Results, 2u);
+}
+
 TEST_F(BackgroundIndexTest, MainFileRefs) {
   MockFS FS;
   FS.Files[testPath("root/A.h")] = R"cpp(
@@ -346,13 +389,13 @@
 UnorderedElementsAre(FileURI("unittest:///root/A.cc")));
 
   // The BaseOf relationship between A_CC and B_CC is stored in the file
-  // containing the definition of the subject (A_CC)
+  // containing the definition of the object (B_CC)
   SymbolID A = findSymbol(*ShardHeader->Symbols, "A_CC").ID;
   SymbolID B = findSymbol(*ShardSource->Symbols, "B_CC").ID;
-  

[PATCH] D87250: [OpenMP] Fix typo in CodeGenFunction::EmitOMPWorksharingLoop (PR46412)

2020-09-07 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon created this revision.
RKSimon added reviewers: ABataev, doctorpangloss.
Herald added subscribers: guansong, yaxunl.
Herald added a project: clang.
RKSimon requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Fixes issue noticed by static analysis where we appear to have a copy+paste 
typo, testing ScheduleKind.M1  twice instead of 
ScheduleKind.M2 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87250

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -2982,7 +2982,7 @@
   ((ScheduleKind.Schedule == OMPC_SCHEDULE_static ||
 ScheduleKind.Schedule == OMPC_SCHEDULE_unknown) &&
!(ScheduleKind.M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ||
- ScheduleKind.M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic)) ||
+ ScheduleKind.M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic)) ||
   ScheduleKind.M1 == OMPC_SCHEDULE_MODIFIER_monotonic ||
   ScheduleKind.M2 == OMPC_SCHEDULE_MODIFIER_monotonic;
   if ((RT.isStaticNonchunked(ScheduleKind.Schedule,


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -2982,7 +2982,7 @@
   ((ScheduleKind.Schedule == OMPC_SCHEDULE_static ||
 ScheduleKind.Schedule == OMPC_SCHEDULE_unknown) &&
!(ScheduleKind.M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ||
- ScheduleKind.M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic)) ||
+ ScheduleKind.M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic)) ||
   ScheduleKind.M1 == OMPC_SCHEDULE_MODIFIER_monotonic ||
   ScheduleKind.M2 == OMPC_SCHEDULE_MODIFIER_monotonic;
   if ((RT.isStaticNonchunked(ScheduleKind.Schedule,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86699: [SyntaxTree] Ignore implicit non-leaf `CXXConstructExpr`

2020-09-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 290331.
eduucaldas added a comment.

- Rename tests
- Add FIXMEs for init-declarators


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86699

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp

Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -1745,19 +1745,15 @@
 struct X {
   friend X operator+(X, const X&);
 };
-// FIXME: Remove additional `UnknownExpression` wrapping `x`. For that, ignore
-// implicit copy constructor called on `x`. This should've been ignored already,
-// as we `IgnoreImplicit` when traversing an `Stmt`.
 void test(X x, X y) {
   [[x + y]];
 }
 )cpp",
   {R"txt(
 BinaryOperatorExpression Expression
-|-UnknownExpression LeftHandSide
-| `-IdExpression
-|   `-UnqualifiedId UnqualifiedId
-| `-'x'
+|-IdExpression LeftHandSide
+| `-UnqualifiedId UnqualifiedId
+|   `-'x'
 |-'+' OperatorToken
 `-IdExpression RightHandSide
   `-UnqualifiedId UnqualifiedId
@@ -3821,26 +3817,137 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, InitDeclarator_Equal) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S { S(int);};
+void test() {
+  [[S s = 1]];
+}
+)cpp",
+  {R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s'
+  |-'='
+  `-IntegerLiteralExpression
+`-'1' LiteralToken
+)txt"}));
+}
+
 TEST_P(SyntaxTreeTest, InitDeclarator_Brace) {
   if (!GetParam().isCXX11OrLater()) {
 return;
   }
-  EXPECT_TRUE(treeDumpEqual(
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
   R"cpp(
-int a {};
+struct S { 
+  S();
+  S(int);
+  S(int, float);
+};
+void test(){
+  // FIXME: 's...' is a declarator and '{...}' is initializer
+  [[S s0{}]];
+  [[S s1{1}]];
+  [[S s2{1, 2.}]];
+}
 )cpp",
-  R"txt(
-TranslationUnit Detached
-`-SimpleDeclaration
-  |-'int'
-  |-SimpleDeclarator Declarator
-  | |-'a'
-  | `-UnknownExpression
-  |   `-UnknownExpression
-  | |-'{'
-  | `-'}'
-  `-';'
-)txt"));
+  {R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  `-UnknownExpression
+|-'s0'
+|-'{'
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  `-UnknownExpression
+|-'s1'
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  `-UnknownExpression
+|-'s2'
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+|-','
+|-FloatingLiteralExpression
+| `-'2.' LiteralToken
+`-'}'
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, InitDeclarator_EqualBrace) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S { 
+  S();
+  S(int);
+  S(int, float);
+};
+void test() {
+  // FIXME: '= {...}' is initializer
+  [[S s0 = {}]];
+  [[S s1 = {1}]];
+  [[S s2 = {1, 2.}]];
+}
+)cpp",
+  {R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s0'
+  |-'='
+  `-UnknownExpression
+|-'{'
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s1'
+  |-'='
+  `-UnknownExpression
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s2'
+  |-'='
+  `-UnknownExpression
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+|-','
+|-FloatingLiteralExpression
+| `-'2.' LiteralToken
+`-'}'
+)txt"}));
 }
 
 TEST_P(SyntaxTreeTest, InitDeclarator_Paren) {
@@ -3851,15 +3958,134 @@
   R"cpp(
 struct S {
   S(int);
+  S(int, float);
 };
-[[S s(1);]]
+// FIXME: 's...' is a declarator and '(...)' is initializer
+[[S s1(1);]]
+[[S s2(1, 2.);]]
 )cpp",
   {R"txt(
 SimpleDeclaration
 |-'S'
 |-SimpleDeclarator Declarator
 | `-UnknownExpression
-|   |-'s'
+|   |-'s1'
+|   |-'('
+|   |-IntegerLiteralExpression
+|   | `-'1' LiteralToken
+|   `-')'
+`-';'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+|-SimpleDeclarator Declarator
+| `-UnknownExpression
+|   |-'s2'
+|   |-'('
+|   |-IntegerLiteralExpression
+|   | `-'1' LiteralToken
+|   |-','
+|   |-FloatingLiteralExpression
+|   | `-'2.' LiteralToken
+|   `-')'
+`-';'
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, ImplicitConversion_Argument) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct X {
+  X(int);
+};
+void TakeX(const X&);
+void test() {
+  [[TakeX(1)]];
+}
+)cpp",
+  {R"txt(
+CallExpression Expression
+|-IdExpression Callee
+| `-UnqualifiedId UnqualifiedId
+|   `-'TakeX'
+|-'(' OpenParen

[PATCH] D87250: [OpenMP] Fix typo in CodeGenFunction::EmitOMPWorksharingLoop (PR46412)

2020-09-07 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LGTM thx


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87250

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


[PATCH] D86089: [flang][driver]Add experimental flang driver and frontend with help screen

2020-09-07 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

In D86089#2256139 , 
@richard.barton.arm wrote:

> Another random thought that just came to me: what does the new driver do when 
> you invoke it with no input files or options? I could imagine a few sensible 
> outcomes (error: no input (clang and gcc/gfortran behaviour), print version 
> and exit, print help and exit, etc.) and I don't have a strong preference 
> over which we chose here but I think there should be a test for it in 
> test/Driver

`flang-new` inherits generic things like this from libclangDriver. In this case:

  error: no input files

This is consistent with `clang`. I've added a test for this. As for `flang-new 
-fc1` - it in general does very little right now :) `clang -cc1` just sits 
there waiting




Comment at: flang/test/CMakeLists.txt:8
 
+llvm_canonicalize_cmake_booleans(FLANG_BUILD_NEW_DRIVER)
+

richard.barton.arm wrote:
> So do the other bools like LINK_WITH_FIR also need this treatment and this is 
> a latent bug? Seems amazing we've not hit that before now.
> 
> From an offline conversation ISTR you saying this was to do with how the 
> variable is translated into the lit config? If that is the case then I think 
> there is a function you can use called lit.util.pythonize_bool which converts 
> various strings that mean "True/False" into a real bool for python. That 
> would also let you clean up the lit.cfg.py later on (separate comments).
AFAIK, `LINK_WITH_FIR` is not used in LIT tests.

I switched to `lit.util.pythonize_bool `, thanks for the suggestion!



Comment at: flang/test/Flang-Driver/driver-error-cc1.c:7
+
+// CHECK:error: unknown integrated tool '-cc1'. Valid tools include '-fc1'.

richard.barton.arm wrote:
> I am surprised that you don't need to prefix this run line with 'not' 
> indicating that flang-new returns 0 exit code in this instance, which seems 
> wrong to me.
Good catch, thanks! Fixed in the latest revision.



Comment at: flang/test/Flang-Driver/driver-error-cc1.cpp:1
+// RUN: %flang-new %s 2>&1 | FileCheck %s
+

richard.barton.arm wrote:
> Same comment as above on exit code.
Good catch, thanks! Fixed in the latest revision.



Comment at: flang/test/Flang-Driver/emit-obj.f90:2
+! RUN: %flang-new  %s 2>&1 | FileCheck %s --check-prefix=ERROR
+! RUN: %flang-new  -fc1 -emit-obj %s 2>&1 | FileCheck %s --check-prefix=ERROR
+

richard.barton.arm wrote:
> Seems like it would be helpful to have also implemented `-###` in this patch 
> so that you don't need to write tests like this. You could simply run 
> flang-new -### then check the -fc1 line that would have been emitted for the 
> presence of -emit-obj.
> 
> Same comment above regarding exit code.
> Seems like it would be helpful to have also implemented -### in this patch

As`flang-new` is based on libclangDriver, we get `-###` for free (i.e. it's 
already supported).

However, there's a catch: 
https://github.com/llvm/llvm-project/blob/master/clang/include/clang/Driver/Options.td#L369-L370.
 Currently `flang-new --help` will not display `-###`  because the the 
corresponding option definition hasn't been updated (i.e. it is not flagged as 
a Flang option):
```
def _HASH_HASH_HASH : Flag<["-"], "###">, Flags<[DriverOption, CoreOption]>,
HelpText<"Print (but do not run) the commands to run for this compilation">;
``` 
We have three options:
1. Make `flang-new --help` display options that are flagged as `DriverOption` 
or `CoreOption`. Note this will include many other options (currently 
unsupported) and extra filtering would be required.
2. Add `FlangOption` to the definition of `_HASH_HASH_HASH`, but IMO that's a 
bit controversial. Is that what we want to do long-term? Or shall we create a 
separate category for generic driver options that apply to both Clang and Flang?
3. Delay the decision until there is more code to base our design on.

I'm in favor of Option 3.



Comment at: flang/test/lit.cfg.py:39
 # directories.
+# exclude the tests for flang_new driver while there are two drivers
 config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']

richard.barton.arm wrote:
> This comment should be on line 41
Updated, ta!



Comment at: flang/test/lit.site.cfg.py.in:14
+# control the regression test for flang-new driver
+config.include_flang_new_driver_test="@FLANG_BUILD_NEW_DRIVER@"
+

richard.barton.arm wrote:
> awarzynski wrote:
> > `FLANG_BUILD_NEW_DRIVER` should be canonicalized in CMake first: 
> > https://github.com/llvm/llvm-project/blob/c79a366ec0f87eafca123138b550b039618bf880/llvm/cmake/modules/AddLLVM.cmake#L1424-L1435
> I think it might be better to use lit.util.pythonize_bool to do the 
> canonicalisation. It would let you use config.include_flang_new_driver_test 
> as a real bool later in the file rather 

[PATCH] D87218: [builtins] Inline __paritysi2 into __paritydi2 and inline __paritydi2 into __parityti2.

2020-09-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I think this is correct, but does their performance matter? 
llvm/IR/RuntimeLibcalls.def do not define them (they cannot be produced by 
llvm). Targets either emit popcount & 1 or detect the idiom and emit an 
optimized parity (x86 after PR46954)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87218

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


[PATCH] D82725: [PowerPC] Implement Move to VSR Mask builtins in LLVM/Clang

2020-09-07 Thread Qing Shan Zhang via Phabricator via cfe-commits
steven.zhang added inline comments.



Comment at: llvm/lib/Target/PowerPC/PPCISelLowering.cpp:10054
+
+  case Intrinsic::ppc_altivec_mtvsrbm: {
+// The llvm.ppc.altivec.mtvsrbm intrinsic can correspond to two different

Can we handle this inside the .td ? i.e. change the definition of the instr as:
```
  def MTVSRBMI : DXForm<4, 10, (outs vrrc:$vD), (ins u8imm64:$D),
"mtvsrbmi $vD, $D", IIC_VecGeneral,
[(set v16i8:$vD,
  (int_ppc_altivec_mtvsrbm imm:$D))]>;
```
And add the missing u8imm64 as what we did for u16imm64 ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82725

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


[PATCH] D87243: [cmake] Centralize LLVM_ENABLE_WARNINGS option

2020-09-07 Thread Dave Lee via Phabricator via cfe-commits
kastiglione added a comment.

@lebedev.ri `clang/CMakeLists.txt` contains `include(HandleLLVMOptions)` for 
its standalone build, I think this covers the issue you're pointing out


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87243

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


[PATCH] D87218: [builtins] Inline __paritysi2 into __paritydi2 and inline __paritydi2 into __parityti2.

2020-09-07 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D87218#2259972 , @MaskRay wrote:

> I think this is correct, but does their performance matter? 
> `llvm/IR/RuntimeLibcalls.def` does not define them (they cannot be produced 
> by llvm). Targets either emit popcount & 1 or detect the idiom and emit an 
> optimized parity (x86 after PR46954)

Performance probably doesn't matter. Just one of the things a certain someone 
wasn't amused by.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87218

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


[PATCH] D87257: [clang] Traverse init-captures while indexing

2020-09-07 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a reviewer: hokein.
nridge added a comment.

I did try to add a test to `clang/test/Index/Core/index-source.cpp`, however 
the output of `c-index-test` does not seem to be changed by adding this 
reference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87257

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


[PATCH] D87257: [clang] Traverse init-captures while indexing

2020-09-07 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.
nridge requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87257

Files:
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang/lib/Index/IndexBody.cpp


Index: clang/lib/Index/IndexBody.cpp
===
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -391,11 +391,13 @@
 if (C->capturesThis() || C->capturesVLAType())
   return true;
 
+// if (!base::TraverseStmt(Init))
+//  return false;
+
 if (C->capturesVariable() && IndexCtx.shouldIndexFunctionLocalSymbols())
   return IndexCtx.handleReference(C->getCapturedVar(), C->getLocation(),
   Parent, ParentDC, SymbolRoleSet());
 
-// FIXME: Lambda init-captures.
 return true;
   }
 
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1589,6 +1589,12 @@
 [[Vector]] x2;
 Vector y;
   )cpp",
+  R"cpp(// Lambda capture initializer
+void foo() {
+  int [[w^aldo]] = 42;
+  auto lambda = [x = [[waldo]]](){};
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);


Index: clang/lib/Index/IndexBody.cpp
===
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -391,11 +391,13 @@
 if (C->capturesThis() || C->capturesVLAType())
   return true;
 
+// if (!base::TraverseStmt(Init))
+//  return false;
+
 if (C->capturesVariable() && IndexCtx.shouldIndexFunctionLocalSymbols())
   return IndexCtx.handleReference(C->getCapturedVar(), C->getLocation(),
   Parent, ParentDC, SymbolRoleSet());
 
-// FIXME: Lambda init-captures.
 return true;
   }
 
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1589,6 +1589,12 @@
 [[Vector]] x2;
 Vector y;
   )cpp",
+  R"cpp(// Lambda capture initializer
+void foo() {
+  int [[w^aldo]] = 42;
+  auto lambda = [x = [[waldo]]](){};
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87257: [clang] Traverse init-captures while indexing

2020-09-07 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 290379.
nridge added a comment.

Fix typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87257

Files:
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang/lib/Index/IndexBody.cpp


Index: clang/lib/Index/IndexBody.cpp
===
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -391,11 +391,13 @@
 if (C->capturesThis() || C->capturesVLAType())
   return true;
 
+if (!base::TraverseStmt(Init))
+  return false;
+
 if (C->capturesVariable() && IndexCtx.shouldIndexFunctionLocalSymbols())
   return IndexCtx.handleReference(C->getCapturedVar(), C->getLocation(),
   Parent, ParentDC, SymbolRoleSet());
 
-// FIXME: Lambda init-captures.
 return true;
   }
 
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1589,6 +1589,12 @@
 [[Vector]] x2;
 Vector y;
   )cpp",
+  R"cpp(// Lambda capture initializer
+void foo() {
+  int [[w^aldo]] = 42;
+  auto lambda = [x = [[waldo]]](){};
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);


Index: clang/lib/Index/IndexBody.cpp
===
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -391,11 +391,13 @@
 if (C->capturesThis() || C->capturesVLAType())
   return true;
 
+if (!base::TraverseStmt(Init))
+  return false;
+
 if (C->capturesVariable() && IndexCtx.shouldIndexFunctionLocalSymbols())
   return IndexCtx.handleReference(C->getCapturedVar(), C->getLocation(),
   Parent, ParentDC, SymbolRoleSet());
 
-// FIXME: Lambda init-captures.
 return true;
   }
 
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1589,6 +1589,12 @@
 [[Vector]] x2;
 Vector y;
   )cpp",
+  R"cpp(// Lambda capture initializer
+void foo() {
+  int [[w^aldo]] = 42;
+  auto lambda = [x = [[waldo]]](){};
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86700: [SyntaxTree] Ignore leaf implicit `CXXConstructExpr`

2020-09-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 290328.
eduucaldas marked 2 inline comments as done.
eduucaldas added a comment.

answer comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86700

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp


Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -548,9 +548,6 @@
   struct S { };
 }
 void test() {
-  // FIXME: Remove the `UnknownExpression` wrapping `s1` and `s2`. This
-  // `UnknownExpression` comes from a leaf `CXXConstructExpr` in the
-  // ClangAST. We need to ignore leaf implicit nodes.
   [[::n::S s1]];
   [[n::S s2]];
 }
@@ -564,8 +561,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s1'
+  `-'s1'
 )txt",
R"txt(
 SimpleDeclaration
@@ -575,8 +571,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s2'
+  `-'s2'
 )txt"}));
 }
 
@@ -608,8 +603,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s1'
+  `-'s1'
 )txt",
R"txt(
 SimpleDeclaration
@@ -623,8 +617,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s2'
+  `-'s2'
 )txt"}));
 }
 
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1132,6 +1132,14 @@
 return true;
   }
 
+  bool WalkUpFromCXXConstructExpr(CXXConstructExpr *S) {
+// Ignore the implicit calls to default constructors.
+if ((S->getNumArgs() == 0 || isa(S->getArg(0))) &&
+S->getParenOrBraceRange().isInvalid())
+  return true;
+return RecursiveASTVisitor::WalkUpFromCXXConstructExpr(S);
+  }
+
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
 // To construct a syntax tree of the same shape for calls to built-in and
 // user-defined operators, ignore the `DeclRefExpr` that refers to the


Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -548,9 +548,6 @@
   struct S { };
 }
 void test() {
-  // FIXME: Remove the `UnknownExpression` wrapping `s1` and `s2`. This
-  // `UnknownExpression` comes from a leaf `CXXConstructExpr` in the
-  // ClangAST. We need to ignore leaf implicit nodes.
   [[::n::S s1]];
   [[n::S s2]];
 }
@@ -564,8 +561,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s1'
+  `-'s1'
 )txt",
R"txt(
 SimpleDeclaration
@@ -575,8 +571,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s2'
+  `-'s2'
 )txt"}));
 }
 
@@ -608,8 +603,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s1'
+  `-'s1'
 )txt",
R"txt(
 SimpleDeclaration
@@ -623,8 +617,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s2'
+  `-'s2'
 )txt"}));
 }
 
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1132,6 +1132,14 @@
 return true;
   }
 
+  bool WalkUpFromCXXConstructExpr(CXXConstructExpr *S) {
+// Ignore the implicit calls to default constructors.
+if ((S->getNumArgs() == 0 || isa(S->getArg(0))) &&
+S->getParenOrBraceRange().isInvalid())
+  return true;
+return RecursiveASTVisitor::WalkUpFromCXXConstructExpr(S);
+  }
+
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
 // To construct a syntax tree of the same shape for calls to built-in and
 // user-defined operators, ignore the `DeclRefExpr` that refers to the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86699: [SyntaxTree] Ignore implicit non-leaf `CXXConstructExpr`

2020-09-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp:4042
+
+TEST_P(SyntaxTreeTest, ExplicitConversion_ZeroArguments) {
+  if (!GetParam().isCXX()) {

gribozavr2 wrote:
> This is not a conversion, this is an explicit constructor call 
> (CXXTemporaryObjectExpr) -- so please rename the test. Same for other tests 
> below.
I am trying to follow the syntax to name things. And in the  [[ 
https://eel.is/c++draft/expr.type.conv | grammar ]] this is under "Explicit 
type conversion (functional notation)", which englobes as well things of the 
type `float(3)`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86699

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


[PATCH] D86700: [SyntaxTree] Ignore leaf implicit `CXXConstructExpr`

2020-09-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:1137
+// Ignore the implicit default constructs.
+if ((S->getNumArgs() == 0 || isa(S->getArg(0))) &&
+S->getParenOrBraceRange().isInvalid())

gribozavr2 wrote:
> I don't quite understand which test is checking the CXXDefaultArgExpr case -- 
> could you help me?
`CXXDefaultArgExpr` is in another [[ https://reviews.llvm.org/D87249 | patch 
]]. Although I discovered while working on this it is as linked to Constructors 
as it is linked to function calls. As such I decided to add that in a separate 
patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86700

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


[PATCH] D85960: [AST][FPEnv] Keep FP options in trailing storage of CastExpr

2020-09-07 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

> This change allow a CallExpr to have optional FPOptionsOverride object,

Should this be `CastExpr` instead?

> stored in trailing storage. The implementaion is made similar to the way
> used in CallExpr.

Nit, but that's not really similar. In the `CallExpr` case the trailing objects 
are directly managed by `CallExpr` without using `TrailingObjects` in the 
sub-classes.




Comment at: clang/include/clang/AST/Expr.h:3471
 
+  /// Return a pointer to the trailing FPOptions.
+  FPOptionsOverride *getTrailingFPFeatures();

Can you document that `hasStoredFPFeatures()` must  be true as a pre-condition?



Comment at: clang/include/clang/AST/Expr.h:3612
 
+  unsigned numTrailingObjects(OverloadToken) const {
+return path_size();

Here and elsewhere: `numTrailingObjects` is not part of the public interface.



Comment at: clang/include/clang/AST/ExprCXX.h:475
   : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
- writtenTy, l, RParenLoc, AngleBrackets) {}
+ false, writtenTy, l, RParenLoc, AngleBrackets) {}
 

`/*frob=*/false` here and elsewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85960

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


[PATCH] D87253: [libTooling] Change CDB heuristic to look further for files in a given language.

2020-09-07 Thread Alain Mosnier via Phabricator via cfe-commits
amosnier accepted this revision.
amosnier added a comment.
This revision is now accepted and ready to land.

I'm not sure I'm supposed to accept a revision, but apparently I'm authorized 
to do so. And I'm obviously biased since I wrote the bug report. While looking 
for candidates close to the target file might often sound reasonable, it does 
not feel particularly adapted to a whole category of files: template 
declarations. Why would the files that include those be anywhere close to them? 
Also, fetching compile commands from a file written in another language pretty 
much always seems like a bad idea. If I understand correctly, with this commit, 
an arbitrary file of the same language will be picked, every time one such file 
is found. It would of course be even better to pick one that includes the 
target file (in case of a header file), but I can easily imagine that it would 
be much more difficult to implement.
Based on the previous analysis, I approve this commit.
I would also like to express how impressed I am by this project's efficiency!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87253

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


[PATCH] D87201: [clang-format] Add a option for the position of Java static import

2020-09-07 Thread Byoungchan Lee via Phabricator via cfe-commits
bc-lee updated this revision to Diff 290381.
bc-lee added a comment.

Fix the example to match the description.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87201

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

Index: clang/unittests/Format/SortImportsTestJava.cpp
===
--- clang/unittests/Format/SortImportsTestJava.cpp
+++ clang/unittests/Format/SortImportsTestJava.cpp
@@ -250,6 +250,30 @@
  "import org.c;\n"));
 }
 
+TEST_F(SortImportsTestJava, FormatJavaStaticImportAfterImport) {
+  FmtStyle.JavaStaticImportAfterImport = true;
+
+  EXPECT_EQ("import com.test.b;\n"
+"import com.test.c;\n"
+"\n"
+"import org.b;\n"
+"\n"
+"import com.b;\n"
+"\n"
+"import static com.test.a;\n"
+"\n"
+"import static org.a;\n"
+"\n"
+"import static com.a;\n",
+sort("import static com.test.a;\n"
+ "import static org.a;\n"
+ "import static com.a;\n"
+ "import com.test.b;\n"
+ "import org.b;\n"
+ "import com.b;\n"
+ "import com.test.c;\n"));
+}
+
 TEST_F(SortImportsTestJava, DeduplicateImports) {
   EXPECT_EQ("import org.a;\n", sort("import org.a;\n"
 "import org.a;\n"));
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13929,6 +13929,7 @@
   CHECK_PARSE_BOOL(IndentCaseBlocks);
   CHECK_PARSE_BOOL(IndentGotoLabels);
   CHECK_PARSE_BOOL(IndentWrappedFunctionNames);
+  CHECK_PARSE_BOOL(JavaStaticImportAfterImport);
   CHECK_PARSE_BOOL(KeepEmptyLinesAtTheStartOfBlocks);
   CHECK_PARSE_BOOL(ObjCSpaceAfterProperty);
   CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -544,6 +544,8 @@
 IO.mapOptional("JavaImportGroups", Style.JavaImportGroups);
 IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
+IO.mapOptional("JavaStaticImportAfterImport",
+   Style.JavaStaticImportAfterImport);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
@@ -901,6 +903,7 @@
   LLVMStyle.InsertTrailingCommas = FormatStyle::TCS_None;
   LLVMStyle.JavaScriptQuotes = FormatStyle::JSQS_Leave;
   LLVMStyle.JavaScriptWrapImports = true;
+  LLVMStyle.JavaStaticImportAfterImport = false;
   LLVMStyle.TabWidth = 8;
   LLVMStyle.MaxEmptyLinesToKeep = 1;
   LLVMStyle.KeepEmptyLinesAtTheStartOfBlocks = true;
@@ -2312,12 +2315,15 @@
 JavaImportGroups.push_back(
 findJavaImportGroup(Style, Imports[i].Identifier));
   }
+  bool StaticImportAfterNormalImport = Style.JavaStaticImportAfterImport;
   llvm::sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
 // Negating IsStatic to push static imports above non-static imports.
-return std::make_tuple(!Imports[LHSI].IsStatic, JavaImportGroups[LHSI],
-   Imports[LHSI].Identifier) <
-   std::make_tuple(!Imports[RHSI].IsStatic, JavaImportGroups[RHSI],
-   Imports[RHSI].Identifier);
+return std::make_tuple(!Imports[LHSI].IsStatic ^
+   StaticImportAfterNormalImport,
+   JavaImportGroups[LHSI], Imports[LHSI].Identifier) <
+   std::make_tuple(!Imports[RHSI].IsStatic ^
+   StaticImportAfterNormalImport,
+   JavaImportGroups[RHSI], Imports[RHSI].Identifier);
   });
 
   // Deduplicate imports.
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1618,10 +1618,12 @@
 
   /// A vector of prefixes ordered by the desired groups for Java imports.
   ///
-  /// Each group is separated by a newline. Static imports will also follow the
-  /// same grouping convention above all non-static imports. One group's prefix
-  /// can be a subset of another - the longest prefix is always matched. Within
-  /// a group, the imports are ordered lexicographically.
+  /// One group's prefix can be a subset of another - the longest prefix is
+  /// always matched. Within a group, the imports 

[PATCH] D87253: [libTooling] Change CDB heuristic to look further for files in a given language.

2020-09-07 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
adamcz requested review of this revision.

When looking for compile commands for file of type X, other files of
type X will be preferred over files of any other type, regardless of
score.

However, when gathering the set of candidates, we only look for files
with similar name and files close to the requested one. If it happens
that none of them are in language X, we previously (before this change)
would choose one of the existing candidates of some other type.

This patch adds all files in language X (regardless of name and
location) to the list of candidates if the initial set of candidates did
not contain any files of type X. This means we will always choose a file
of type X if one exists anywhere in the project.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87253

Files:
  clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -755,6 +755,7 @@
 }
 
 TEST_F(InterpolateTest, Language) {
+  add("aaa/bbb/ccc/ddd/file.c", "");
   add("dir/foo.cpp", "-std=c++17");
   add("dir/bar.c", "");
   add("dir/baz.cee", "-x c");
@@ -774,7 +775,10 @@
   EXPECT_EQ(getCommand("baz.h"), "clang -D dir/baz.cee -x c-header");
   // prefer a worse match with the right extension.
   EXPECT_EQ(getCommand("foo.c"), "clang -D dir/bar.c");
+  // even when it is far away.
+  EXPECT_EQ(getCommand("aaa/bbb/ccc/ddd/file.hpp"), "clang -D dir/aux.cpp");
   Entries.erase(path(StringRef("dir/bar.c")));
+  Entries.erase(path(StringRef("aaa/bbb/ccc/ddd/file.c")));
   // Now we transfer across languages, so drop -std too.
   EXPECT_EQ(getCommand("foo.c"), "clang -D dir/foo.cpp");
   // Prefer -x over -std when overriding language.
Index: clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
===
--- clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
+++ clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -352,7 +352,7 @@
 types::ID PreferLanguage) const {
 assert(!empty() && "need at least one candidate!");
 std::string Filename = OriginalFilename.lower();
-auto Candidates = scoreCandidates(Filename);
+auto Candidates = scoreCandidates(Filename, PreferLanguage);
 std::pair Best =
 pickWinner(Candidates, Filename, PreferLanguage);
 
@@ -378,7 +378,8 @@
 
   // Award points to candidate entries that should be considered for the file.
   // Returned keys are indexes into paths, and the values are (nonzero) scores.
-  DenseMap scoreCandidates(StringRef Filename) const {
+  DenseMap scoreCandidates(StringRef Filename,
+types::ID PreferredLanguage) const {
 // Decompose Filename into the parts we care about.
 // /some/path/complicated/project/Interesting.h
 // [-prefix--][---dir---] [-dir-] [--stem---]
@@ -410,6 +411,25 @@
 // Award one more point if the whole rest of the path matches.
 if (sys::path::root_directory(Prefix) != Prefix)
   Award(1, indexLookup(Prefix, Paths));
+
+bool CandidateWithMatchingLanguageFound = false;
+for (const auto  : Candidates) {
+  if (Types[C.first] == PreferredLanguage) {
+CandidateWithMatchingLanguageFound = true;
+break;
+  }
+}
+if (!CandidateWithMatchingLanguageFound) {
+  // If none of the candidates we found so far use preferred language, try
+  // all other files, even if they are far away in the dir hierarchy.
+  for (size_t I = 0; I < OriginalPaths.size(); ++I) {
+// Increase score by one. The actual value doesn't matter, the point is
+// to have some candidates matching PreferredLanguage in the Candidates
+// set at all.
+if (Types[I] == PreferredLanguage)
+  Candidates[I] += 1;
+  }
+}
 return Candidates;
   }
 


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -755,6 +755,7 @@
 }
 
 TEST_F(InterpolateTest, Language) {
+  add("aaa/bbb/ccc/ddd/file.c", "");
   add("dir/foo.cpp", "-std=c++17");
   add("dir/bar.c", "");
   add("dir/baz.cee", "-x c");
@@ -774,7 +775,10 @@
   EXPECT_EQ(getCommand("baz.h"), "clang -D dir/baz.cee -x c-header");
   // prefer a worse match with the right extension.
   EXPECT_EQ(getCommand("foo.c"), "clang -D dir/bar.c");
+  // even when it is far away.
+  EXPECT_EQ(getCommand("aaa/bbb/ccc/ddd/file.hpp"), "clang -D dir/aux.cpp");
   Entries.erase(path(StringRef("dir/bar.c")));
+  

[PATCH] D82726: [PowerPC] Implement Vector Count Mask Bits builtins in LLVM/Clang

2020-09-07 Thread Qing Shan Zhang via Phabricator via cfe-commits
steven.zhang accepted this revision.
steven.zhang added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82726

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


[PATCH] D87249: [SyntaxTree] Fix crash on functions with default arguments.

2020-09-07 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

Please also add tests for calls to constructors without arguments and calls to 
implicit constructors 1 argument, as requested in 
https://reviews.llvm.org/D86700.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87249

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


[PATCH] D87218: [builtins] Inline __paritysi2 into __paritydi2 and inline __paritydi2 into __parityti2.

2020-09-07 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87218

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


[PATCH] D87249: [SyntaxTree] Fix crash on functions with default arguments.

2020-09-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
eduucaldas added a reviewer: gribozavr2.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

- Do not visit `CXXDefaultArgExpr`
- To build `CallArguments` nodes, just go through non-default arguments


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87249

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp

Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -2744,6 +2744,54 @@
 )txt"}));
 }
 
+TEST_P(SyntaxTreeTest, CallExpression_DefaultArguments) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+void f(int i = 1, char c = '2');
+void test() {
+  [[f()]];
+  [[f(1)]];
+  [[f(1, '2')]];
+}
+)cpp",
+  {R"txt(
+CallExpression Expression
+|-IdExpression Callee
+| `-UnqualifiedId UnqualifiedId
+|   `-'f'
+|-'(' OpenParen
+`-')' CloseParen
+  )txt",
+   R"txt(
+CallExpression Expression
+|-IdExpression Callee
+| `-UnqualifiedId UnqualifiedId
+|   `-'f'
+|-'(' OpenParen
+|-CallArguments Arguments
+| `-IntegerLiteralExpression ListElement
+|   `-'1' LiteralToken
+`-')' CloseParen
+  )txt",
+   R"txt(
+CallExpression Expression
+|-IdExpression Callee
+| `-UnqualifiedId UnqualifiedId
+|   `-'f'
+|-'(' OpenParen
+|-CallArguments Arguments
+| |-IntegerLiteralExpression ListElement
+| | `-'1' LiteralToken
+| |-',' ListDelimiter
+| `-CharacterLiteralExpression ListElement
+|   `-''2'' LiteralToken
+`-')' CloseParen
+)txt"}));
+}
+
 TEST_P(SyntaxTreeTest, MultipleDeclaratorsGrouping) {
   EXPECT_TRUE(treeDumpEqual(
   R"cpp(
@@ -4106,6 +4154,61 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, ParametersAndQualifiers_InFreeFunctions_Default_One) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+int func1([[int a = 1]]);
+)cpp",
+  {R"txt(
+ParameterDeclarationList Parameters
+`-SimpleDeclaration ListElement
+  |-'int'
+  `-SimpleDeclarator Declarator
+|-'a'
+|-'='
+`-IntegerLiteralExpression
+  `-'1' LiteralToken
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest,
+   ParametersAndQualifiers_InFreeFunctions_Default_Multiple) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+int func2([[int *ap, int a = 1, char c = '2']]);
+)cpp",
+  {R"txt(
+ParameterDeclarationList Parameters
+|-SimpleDeclaration ListElement
+| |-'int'
+| `-SimpleDeclarator Declarator
+|   |-'*'
+|   `-'ap'
+|-',' ListDelimiter
+|-SimpleDeclaration ListElement
+| |-'int'
+| `-SimpleDeclarator Declarator
+|   |-'a'
+|   |-'='
+|   `-IntegerLiteralExpression
+| `-'1' LiteralToken
+|-',' ListDelimiter
+`-SimpleDeclaration ListElement
+  |-'char'
+  `-SimpleDeclarator Declarator
+|-'c'
+|-'='
+`-CharacterLiteralExpression
+  `-''2'' LiteralToken
+)txt"}));
+}
+
 TEST_P(SyntaxTreeTest,
ParametersAndQualifiers_InVariadicFunctionTemplate_ParameterPack) {
   if (!GetParam().isCXX11OrLater() || GetParam().hasDelayedTemplateParsing()) {
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -116,6 +116,13 @@
 };
 } // namespace
 
+static CallExpr::arg_range dropDefaultArgs(CallExpr::arg_range Args) {
+  auto firstDefaultArg = std::find_if(Args.begin(), Args.end(), [](auto it) {
+return isa(it);
+  });
+  return llvm::make_range(Args.begin(), firstDefaultArg);
+}
+
 static syntax::NodeKind getOperatorNodeKind(const CXXOperatorCallExpr ) {
   switch (E.getOperator()) {
   // Comparison
@@ -1073,7 +1080,11 @@
 return true;
   }
 
-  syntax::CallArguments *buildCallArguments(CallExpr::arg_range Args) {
+  /// Builds `CallArguments` syntax node from arguments that appear in source
+  /// code, i.e. not default arguments.
+  syntax::CallArguments *
+  buildCallArguments(CallExpr::arg_range ArgsAndDefaultArgs) {
+auto Args = dropDefaultArgs(ArgsAndDefaultArgs);
 for (const auto  : Args) {
   Builder.markExprChild(Arg, syntax::NodeRole::ListElement);
   const auto *DelimiterToken =
@@ -1187,6 +1198,8 @@
 }
   }
 
+  bool WalkUpFromCXXDefaultArgExpr(CXXDefaultArgExpr *S) { return true; }
+
   bool WalkUpFromNamespaceDecl(NamespaceDecl *S) {
 auto Tokens = Builder.getDeclarationRange(S);
 if (Tokens.front().kind() == tok::coloncolon) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79279: Add overloaded versions of builtin mem* functions

2020-09-07 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79279

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


[PATCH] D86700: [SyntaxTree] Ignore leaf implicit `CXXConstructExpr`

2020-09-07 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:1137
+// Ignore the implicit default constructs.
+if ((S->getNumArgs() == 0 || isa(S->getArg(0))) &&
+S->getParenOrBraceRange().isInvalid())

eduucaldas wrote:
> gribozavr2 wrote:
> > I don't quite understand which test is checking the CXXDefaultArgExpr case 
> > -- could you help me?
> `CXXDefaultArgExpr` is in another [[ https://reviews.llvm.org/D87249 | patch 
> ]]. Although I discovered while working on this it is as linked to 
> Constructors as it is linked to function calls. As such I decided to add that 
> in a separate patch
OK, added a comment in that review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86700

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


[PATCH] D87218: [builtins] Inline __paritysi2 into __paritydi2 and inline __paritydi2 into __parityti2.

2020-09-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

LG. Please wait a bit for @efriedma's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87218

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


[PATCH] D86699: [SyntaxTree] Ignore implicit non-leaf `CXXConstructExpr`

2020-09-07 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:48
 
+// Ignores the implicit `CXXConstructExpr` for copy/move constructors generated
+// by the compiler, as well as in implicit conversions like the one wrapping 
`1`

eduucaldas wrote:
> Please give feedback on this comments and should I comment the rest of the 
> function?




Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:48-50
+// Ignores the implicit `CXXConstructExpr` for copy/move constructors generated
+// by the compiler, as well as in implicit conversions like the one wrapping 
`1`
+// in `X x = 1;`.

gribozavr2 wrote:
> eduucaldas wrote:
> > Please give feedback on this comments and should I comment the rest of the 
> > function?
> 
Seems straightforward to me.



Comment at: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp:4042
+
+TEST_P(SyntaxTreeTest, ExplicitConversion_ZeroArguments) {
+  if (!GetParam().isCXX()) {

This is not a conversion, this is an explicit constructor call 
(CXXTemporaryObjectExpr) -- so please rename the test. Same for other tests 
below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86699

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


[PATCH] D86369: [Sema][MSVC] warn at dynamic_cast when /GR- is given

2020-09-07 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.

LGTM

But please add a -triple parameter to the test files, and check the 
dynamic_cast behavior in each case before committing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86369

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


[PATCH] D85960: [AST][FPEnv] Keep FP options in trailing storage of CastExpr

2020-09-07 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Minor request, but otherwise LGTM.




Comment at: clang/lib/Analysis/BodyFarm.cpp:188
+  const_cast(Arg), nullptr, VK_RValue,
+  FPOptionsOverride());
 }

Can these call sites just be changed to use `makeImplicitCast`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85960

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


[PATCH] D86089: [flang][driver]Add experimental flang driver and frontend with help screen

2020-09-07 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 290337.
awarzynski marked 2 inline comments as done.
awarzynski added a comment.

- Adddressed comments from @richard.barton.arm
- Added FC1Option to ClangFlags (and made other related changes)
- Added missing code to check return codes from subcommands (flang-new)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86089

Files:
  clang/include/clang/Driver/Driver.h
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
  clang/lib/Tooling/Tooling.cpp
  clang/test/Driver/flang/flang.f90
  clang/test/Driver/flang/flang_ucase.F90
  clang/test/Driver/flang/multiple-inputs-mixed.f90
  clang/test/Driver/flang/multiple-inputs.f90
  clang/unittests/Driver/SanitizerArgsTest.cpp
  clang/unittests/Driver/ToolChainTest.cpp
  flang/CMakeLists.txt
  flang/README.md
  flang/include/flang/Frontend/CompilerInstance.h
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/include/flang/FrontendTool/Utils.h
  flang/lib/CMakeLists.txt
  flang/lib/Frontend/CMakeLists.txt
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendOptions.cpp
  flang/lib/FrontendTool/CMakeLists.txt
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/CMakeLists.txt
  flang/test/Flang-Driver/driver-error-cc1.c
  flang/test/Flang-Driver/driver-error-cc1.cpp
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/driver-version.f90
  flang/test/Flang-Driver/emit-obj.f90
  flang/test/Flang-Driver/missing-input.f90
  flang/test/lit.cfg.py
  flang/test/lit.site.cfg.py.in
  flang/tools/CMakeLists.txt
  flang/tools/flang-driver/CMakeLists.txt
  flang/tools/flang-driver/driver.cpp
  flang/tools/flang-driver/fc1_main.cpp
  flang/unittests/CMakeLists.txt
  flang/unittests/Frontend/CMakeLists.txt
  flang/unittests/Frontend/CompilerInstanceTest.cpp
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/Option/OptTable.cpp

Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -610,8 +610,10 @@
   continue;
 
 unsigned Flags = getInfo(Id).Flags;
+
 if (FlagsToInclude && !(Flags & FlagsToInclude))
   continue;
+
 if (Flags & FlagsToExclude)
   continue;
 
Index: llvm/include/llvm/Option/OptTable.h
===
--- llvm/include/llvm/Option/OptTable.h
+++ llvm/include/llvm/Option/OptTable.h
@@ -48,7 +48,7 @@
 unsigned ID;
 unsigned char Kind;
 unsigned char Param;
-unsigned short Flags;
+unsigned int Flags;
 unsigned short GroupID;
 unsigned short AliasID;
 const char *AliasArgs;
@@ -225,7 +225,8 @@
   /// \param Usage - USAGE: Usage
   /// \param Title - OVERVIEW: Title
   /// \param FlagsToInclude - If non-zero, only include options with any
-  /// of these flags set.
+  /// of these flags set. Takes precedence over
+  /// FlagsToExclude.
   /// \param FlagsToExclude - Exclude options with any of these flags set.
   /// \param ShowAllAliases - If true, display all options including aliases
   /// that don't have help texts. By default, we display
Index: flang/unittests/Frontend/CompilerInstanceTest.cpp
===
--- /dev/null
+++ flang/unittests/Frontend/CompilerInstanceTest.cpp
@@ -0,0 +1,52 @@
+//===- unittests/Frontend/CompilerInstanceTest.cpp - CI tests -===//
+//
+// 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 "flang/Frontend/CompilerInstance.h"
+#include "gtest/gtest.h"
+#include "flang/Frontend/CompilerInvocation.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Driver/Options.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+using namespace llvm;
+using namespace Fortran::frontend;
+
+namespace {
+
+TEST(CompilerInstance, AllowDiagnosticLogWithUnownedDiagnosticConsumer) {
+  // 1. Set-up a basic DiagnosticConsumer
+  std::string diagnosticOutput;
+  llvm::raw_string_ostream diagnosticsOS(diagnosticOutput);
+  auto diagPrinter = std::make_unique(
+  diagnosticsOS, new clang::DiagnosticOptions());
+
+  // 2. Create a CompilerInstance (to manage a DiagnosticEngine)
+  CompilerInstance compInst;
+
+  // 3. Set-up DiagnosticOptions
+  auto 

[PATCH] D84599: [Index/USRGeneration] Use NamedDecl::getDeclName() instead of NamedDecl::printName in USRGenerator::EmitDeclName

2020-09-07 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

To make this patch more acceptable I could also add a `Visit` function for 
`DecompositionDecl` and `MSGuidDecl` such that the current behaviour is 
preserved (I won't be able to test it though since these implicit AST nodes are 
not visited).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84599

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


[PATCH] D87218: [builtins] Inline __paritysi2 into __paritydi2 and inline __paritydi2 into __parityti2.

2020-09-07 Thread Craig Topper via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG35f708a3c9ff: [builtins] Inline __paritysi2 into __paritydi2 
and inline __paritydi2 into… (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87218

Files:
  compiler-rt/lib/builtins/paritydi2.c
  compiler-rt/lib/builtins/parityti2.c


Index: compiler-rt/lib/builtins/parityti2.c
===
--- compiler-rt/lib/builtins/parityti2.c
+++ compiler-rt/lib/builtins/parityti2.c
@@ -18,8 +18,14 @@
 
 COMPILER_RT_ABI int __parityti2(ti_int a) {
   twords x;
+  dwords x2;
   x.all = a;
-  return __paritydi2(x.s.high ^ x.s.low);
+  x2.all = x.s.high ^ x.s.low;
+  su_int x3 = x2.s.high ^ x2.s.low;
+  x3 ^= x3 >> 16;
+  x3 ^= x3 >> 8;
+  x3 ^= x3 >> 4;
+  return (0x6996 >> (x3 & 0xF)) & 1;
 }
 
 #endif // CRT_HAS_128BIT
Index: compiler-rt/lib/builtins/paritydi2.c
===
--- compiler-rt/lib/builtins/paritydi2.c
+++ compiler-rt/lib/builtins/paritydi2.c
@@ -17,5 +17,9 @@
 COMPILER_RT_ABI int __paritydi2(di_int a) {
   dwords x;
   x.all = a;
-  return __paritysi2(x.s.high ^ x.s.low);
+  su_int x2 = x.s.high ^ x.s.low;
+  x2 ^= x2 >> 16;
+  x2 ^= x2 >> 8;
+  x2 ^= x2 >> 4;
+  return (0x6996 >> (x2 & 0xF)) & 1;
 }


Index: compiler-rt/lib/builtins/parityti2.c
===
--- compiler-rt/lib/builtins/parityti2.c
+++ compiler-rt/lib/builtins/parityti2.c
@@ -18,8 +18,14 @@
 
 COMPILER_RT_ABI int __parityti2(ti_int a) {
   twords x;
+  dwords x2;
   x.all = a;
-  return __paritydi2(x.s.high ^ x.s.low);
+  x2.all = x.s.high ^ x.s.low;
+  su_int x3 = x2.s.high ^ x2.s.low;
+  x3 ^= x3 >> 16;
+  x3 ^= x3 >> 8;
+  x3 ^= x3 >> 4;
+  return (0x6996 >> (x3 & 0xF)) & 1;
 }
 
 #endif // CRT_HAS_128BIT
Index: compiler-rt/lib/builtins/paritydi2.c
===
--- compiler-rt/lib/builtins/paritydi2.c
+++ compiler-rt/lib/builtins/paritydi2.c
@@ -17,5 +17,9 @@
 COMPILER_RT_ABI int __paritydi2(di_int a) {
   dwords x;
   x.all = a;
-  return __paritysi2(x.s.high ^ x.s.low);
+  su_int x2 = x.s.high ^ x.s.low;
+  x2 ^= x2 >> 16;
+  x2 ^= x2 >> 8;
+  x2 ^= x2 >> 4;
+  return (0x6996 >> (x2 & 0xF)) & 1;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87253: [libTooling] Change CDB heuristic to look further for files in a given language.

2020-09-07 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added a reviewer: kadircet.
adamcz added a comment.

Hey Kadir

What do you think about this change? This addresses 
https://github.com/clangd/clangd/issues/519, but I'm not entirely convinced 
this is a good idea. Let me know if you have an opinion on this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87253

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


[clang] 3e782bf - [Sema][MSVC] warn at dynamic_cast when /GR- is given

2020-09-07 Thread Zequan Wu via cfe-commits

Author: Zequan Wu
Date: 2020-09-07T16:46:58-07:00
New Revision: 3e782bf8090c80e6d75e62cd52c9ed32715cbcdd

URL: 
https://github.com/llvm/llvm-project/commit/3e782bf8090c80e6d75e62cd52c9ed32715cbcdd
DIFF: 
https://github.com/llvm/llvm-project/commit/3e782bf8090c80e6d75e62cd52c9ed32715cbcdd.diff

LOG: [Sema][MSVC] warn at dynamic_cast when /GR- is given

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

Added: 
clang/test/SemaCXX/ms_no_dynamic_cast.cpp
clang/test/SemaCXX/no_dynamic_cast.cpp

Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaExprCXX.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6b4dcc850612..a9bd52b8afcd 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1235,3 +1235,5 @@ in addition with the pragmas or -fmax-tokens flag to get 
any warnings.
 }
 
 def WebAssemblyExceptionSpec : DiagGroup<"wasm-exception-spec">;
+
+def RTTI : DiagGroup<"rtti">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d856f784e0ee..e1601da74b73 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7438,6 +7438,12 @@ def err_no_typeid_with_fno_rtti : Error<
   "use of typeid requires -frtti">;
 def err_no_dynamic_cast_with_fno_rtti : Error<
   "use of dynamic_cast requires -frtti">;
+def warn_no_dynamic_cast_with_rtti_disabled: Warning<
+  "dynamic_cast will not work since RTTI data is disabled by " 
+  "%select{-fno-rtti-data|/GR-}0">, InGroup;
+def warn_no_typeid_with_rtti_disabled: Warning<
+  "typeid will not work since RTTI data is disabled by "
+  "%select{-fno-rtti-data|/GR-}0">, InGroup;
 
 def err_cannot_form_pointer_to_member_of_reference_type : Error<
   "cannot form a pointer-to-member to member %0 of reference type %1">;

diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 726900c59f20..b213fb756a65 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -890,6 +890,18 @@ void CastOperation::CheckDynamicCast() {
 return;
   }
 
+  // Warns when dynamic_cast is used with RTTI data disabled.
+  if (!Self.getLangOpts().RTTIData) {
+bool MicrosoftABI =
+Self.getASTContext().getTargetInfo().getCXXABI().isMicrosoft();
+bool isClangCL = Self.getDiagnostics().getDiagnosticOptions().getFormat() 
==
+ DiagnosticOptions::MSVC;
+if (MicrosoftABI || !DestPointee->isVoidType())
+  Self.Diag(OpRange.getBegin(),
+diag::warn_no_dynamic_cast_with_rtti_disabled)
+  << isClangCL;
+  }
+
   // Done. Everything else is run-time checks.
   Kind = CK_Dynamic;
 }

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d1fcdf354527..8f8847e63804 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -646,6 +646,12 @@ Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation 
LParenLoc,
 return ExprError(Diag(OpLoc, diag::err_no_typeid_with_fno_rtti));
   }
 
+  // Warns when typeid is used with RTTI data disabled.
+  if (!getLangOpts().RTTIData)
+Diag(OpLoc, diag::warn_no_typeid_with_rtti_disabled)
+<< (getDiagnostics().getDiagnosticOptions().getFormat() ==
+DiagnosticOptions::MSVC);
+
   QualType TypeInfoType = Context.getTypeDeclType(CXXTypeInfoDecl);
 
   if (isType) {

diff  --git a/clang/test/SemaCXX/ms_no_dynamic_cast.cpp 
b/clang/test/SemaCXX/ms_no_dynamic_cast.cpp
new file mode 100644
index ..d2c007fd8c29
--- /dev/null
+++ b/clang/test/SemaCXX/ms_no_dynamic_cast.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -triple x86_64-windows -fdiagnostics-format msvc 
-fno-rtti-data -fsyntax-only -verify
+
+namespace std {
+struct type_info {};
+} // namespace std
+class B {
+public:
+  virtual ~B() = default;
+};
+
+class D1 : public B {
+public:
+  ~D1() = default;
+};
+
+void f() {
+  B* b = new D1();
+  auto d = dynamic_cast(b); // expected-warning{{dynamic_cast will not 
work since RTTI data is disabled by /GR-}}
+  void* v = dynamic_cast(b); // expected-warning{{dynamic_cast will 
not work since RTTI data is disabled by /GR-}}
+  (void)typeid(int);  // expected-warning{{typeid will not work 
since RTTI data is disabled by /GR-}}
+}

diff  --git a/clang/test/SemaCXX/no_dynamic_cast.cpp 
b/clang/test/SemaCXX/no_dynamic_cast.cpp
new file mode 100644
index ..4db21d36f4a9
--- /dev/null
+++ b/clang/test/SemaCXX/no_dynamic_cast.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -fno-rtti-data -fsyntax-only -verify
+
+namespace std {
+struct type_info {};
+} // namespace std
+class B {
+public:
+  virtual 

[PATCH] D86369: [Sema][MSVC] warn at dynamic_cast when /GR- is given

2020-09-07 Thread Zequan Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3e782bf8090c: [Sema][MSVC] warn at dynamic_cast when /GR- is 
given (authored by zequanwu).

Changed prior to commit:
  https://reviews.llvm.org/D86369?vs=289802=290374#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86369

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/ms_no_dynamic_cast.cpp
  clang/test/SemaCXX/no_dynamic_cast.cpp

Index: clang/test/SemaCXX/no_dynamic_cast.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/no_dynamic_cast.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -fno-rtti-data -fsyntax-only -verify
+
+namespace std {
+struct type_info {};
+} // namespace std
+class B {
+public:
+  virtual ~B() = default;
+};
+
+class D1 : public B {
+public:
+  ~D1() = default;
+};
+
+void f() {
+  B* b = new D1();
+  auto d = dynamic_cast(b); // expected-warning{{dynamic_cast will not work since RTTI data is disabled by -fno-rtti-data}}
+  void* v = dynamic_cast(b);
+  (void)typeid(int);  // expected-warning{{typeid will not work since RTTI data is disabled by -fno-rtti-data}}
+}
Index: clang/test/SemaCXX/ms_no_dynamic_cast.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ms_no_dynamic_cast.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -triple x86_64-windows -fdiagnostics-format msvc -fno-rtti-data -fsyntax-only -verify
+
+namespace std {
+struct type_info {};
+} // namespace std
+class B {
+public:
+  virtual ~B() = default;
+};
+
+class D1 : public B {
+public:
+  ~D1() = default;
+};
+
+void f() {
+  B* b = new D1();
+  auto d = dynamic_cast(b); // expected-warning{{dynamic_cast will not work since RTTI data is disabled by /GR-}}
+  void* v = dynamic_cast(b); // expected-warning{{dynamic_cast will not work since RTTI data is disabled by /GR-}}
+  (void)typeid(int);  // expected-warning{{typeid will not work since RTTI data is disabled by /GR-}}
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -646,6 +646,12 @@
 return ExprError(Diag(OpLoc, diag::err_no_typeid_with_fno_rtti));
   }
 
+  // Warns when typeid is used with RTTI data disabled.
+  if (!getLangOpts().RTTIData)
+Diag(OpLoc, diag::warn_no_typeid_with_rtti_disabled)
+<< (getDiagnostics().getDiagnosticOptions().getFormat() ==
+DiagnosticOptions::MSVC);
+
   QualType TypeInfoType = Context.getTypeDeclType(CXXTypeInfoDecl);
 
   if (isType) {
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -890,6 +890,18 @@
 return;
   }
 
+  // Warns when dynamic_cast is used with RTTI data disabled.
+  if (!Self.getLangOpts().RTTIData) {
+bool MicrosoftABI =
+Self.getASTContext().getTargetInfo().getCXXABI().isMicrosoft();
+bool isClangCL = Self.getDiagnostics().getDiagnosticOptions().getFormat() ==
+ DiagnosticOptions::MSVC;
+if (MicrosoftABI || !DestPointee->isVoidType())
+  Self.Diag(OpRange.getBegin(),
+diag::warn_no_dynamic_cast_with_rtti_disabled)
+  << isClangCL;
+  }
+
   // Done. Everything else is run-time checks.
   Kind = CK_Dynamic;
 }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7438,6 +7438,12 @@
   "use of typeid requires -frtti">;
 def err_no_dynamic_cast_with_fno_rtti : Error<
   "use of dynamic_cast requires -frtti">;
+def warn_no_dynamic_cast_with_rtti_disabled: Warning<
+  "dynamic_cast will not work since RTTI data is disabled by " 
+  "%select{-fno-rtti-data|/GR-}0">, InGroup;
+def warn_no_typeid_with_rtti_disabled: Warning<
+  "typeid will not work since RTTI data is disabled by "
+  "%select{-fno-rtti-data|/GR-}0">, InGroup;
 
 def err_cannot_form_pointer_to_member_of_reference_type : Error<
   "cannot form a pointer-to-member to member %0 of reference type %1">;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1235,3 +1235,5 @@
 }
 
 def WebAssemblyExceptionSpec : DiagGroup<"wasm-exception-spec">;
+
+def RTTI : DiagGroup<"rtti">;
___
cfe-commits mailing list

[PATCH] D66564: [clang-tidy] new altera struct pack align check

2020-09-07 Thread Frank Derry Wanye via Phabricator via cfe-commits
ffrankies added a comment.

In D66564#2257635 , @aaron.ballman 
wrote:

> In D66564#2256482 , @ffrankies wrote:
>
>> In D66564#2256424 , @Eugene.Zelenko 
>> wrote:
>>
>>> In D66564#2256423 , @ffrankies 
>>> wrote:
>>>
 @Eugene.Zelenko I don't have commit access to the repository, could you 
 please commit this check on our behalf?
>>>
>>> Sorry, I don't have it either. @aaron.ballman or @njames93 could do this 
>>> for you.
>>
>> No problem. @aaron.ballman @njames93 Could one of you please commit this 
>> check on our behalf?
>
> Sorry for the hassle, but could you rebase again? I'm getting errors when I 
> try to apply the patch.

Done. After rebasing, fixing the include statement in `StructPackAlignCheck.h` 
got rid of the errors that I saw.


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

https://reviews.llvm.org/D66564

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


[PATCH] D66564: [clang-tidy] new altera struct pack align check

2020-09-07 Thread Frank Derry Wanye via Phabricator via cfe-commits
ffrankies updated this revision to Diff 290396.
ffrankies added a comment.

Rebased, changed import in `StructPackAlignCheck.h` from `../ClangTidy.h` to 
`../ClangTidyCheck.h`


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

https://reviews.llvm.org/D66564

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/altera/AlteraTidyModule.cpp
  clang-tools-extra/clang-tidy/altera/CMakeLists.txt
  clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
  clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/altera-struct-pack-align.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align.cpp
@@ -0,0 +1,101 @@
+// RUN: %check_clang_tidy %s altera-struct-pack-align %t -- -header-filter=.*
+
+// Struct needs both alignment and packing
+struct error {
+  char a;
+  double b;
+  char c;
+};
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'error' is inefficient due to padding; only needs 10 bytes but is using 24 bytes [altera-struct-pack-align]
+// CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((packed))" to reduce the amount of padding applied to struct 'error'
+// CHECK-MESSAGES: :[[@LINE-7]]:8: warning: accessing fields in struct 'error' is inefficient due to poor alignment; currently aligned to 8 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align]
+// CHECK-MESSAGES: :[[@LINE-8]]:8: note: use "__attribute__((aligned(16)))" to align struct 'error' to 16 bytes
+// CHECK-FIXES: __attribute__((packed))
+// CHECK-FIXES: __attribute__((aligned(16)));
+
+// Struct is explicitly packed, but needs alignment
+struct error_packed {
+  char a;
+  double b;
+  char c;
+} __attribute__((packed));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'error_packed' is inefficient due to poor alignment; currently aligned to 1 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align]
+// CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((aligned(16)))" to align struct 'error_packed' to 16 bytes
+// CHECK-FIXES: __attribute__((aligned(16)))
+
+// Struct is properly packed, but needs alignment
+struct align_only {
+  char a;
+  char b;
+  char c;
+  char d;
+  int e;
+  double f;
+};
+// CHECK-MESSAGES: :[[@LINE-8]]:8: warning: accessing fields in struct 'align_only' is inefficient due to poor alignment; currently aligned to 8 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align]
+// CHECK-MESSAGES: :[[@LINE-9]]:8: note: use "__attribute__((aligned(16)))" to align struct 'align_only' to 16 bytes
+// CHECK-FIXES: __attribute__((aligned(16)));
+
+// Struct is perfectly packed but wrongly aligned
+struct bad_align {
+  char a;
+  double b;
+  char c;
+} __attribute__((packed)) __attribute__((aligned(8)));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'bad_align' is inefficient due to poor alignment; currently aligned to 8 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align]
+// CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((aligned(16)))" to align struct 'bad_align' to 16 bytes
+// CHECK-FIXES: __attribute__((aligned(16)));
+
+struct bad_align2 {
+  char a;
+  double b;
+  char c;
+} __attribute__((packed)) __attribute__((aligned(32)));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'bad_align2' is inefficient due to poor alignment; currently aligned to 32 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align]
+// CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((aligned(16)))" to align struct 'bad_align2' to 16 bytes
+// CHECK-FIXES: __attribute__((aligned(16)));
+
+struct bad_align3 {
+  char a;
+  double b;
+  char c;
+} __attribute__((packed)) __attribute__((aligned(4)));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'bad_align3' is inefficient due to poor alignment; currently aligned to 4 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align]
+// CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((aligned(16)))" to align struct 'bad_align3' to 16 bytes
+// CHECK-FIXES: __attribute__((aligned(16)));
+
+// Struct is both perfectly packed and aligned
+struct success {
+  char a;
+  double b;
+  char c;
+} __attribute__((packed)) __attribute__((aligned(16)));
+//Should take 10 bytes and be aligned to 16 bytes
+
+// Struct is properly packed, and explicitly aligned
+struct success2 {
+  int a;
+  int b;
+  int c;
+} 

[clang] 7907e55 - [Sema] fix /gr warning test case

2020-09-07 Thread Zequan Wu via cfe-commits

Author: Zequan Wu
Date: 2020-09-07T20:55:11-07:00
New Revision: 7907e5516a418fec29137beed3ff985f40e04f17

URL: 
https://github.com/llvm/llvm-project/commit/7907e5516a418fec29137beed3ff985f40e04f17
DIFF: 
https://github.com/llvm/llvm-project/commit/7907e5516a418fec29137beed3ff985f40e04f17.diff

LOG: [Sema] fix /gr warning test case

Added: 


Modified: 
clang/test/SemaCXX/no-rtti.cpp
clang/test/SemaCXX/no_dynamic_cast.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/no-rtti.cpp b/clang/test/SemaCXX/no-rtti.cpp
index e0b57153c24c..f8487a0902dd 100644
--- a/clang/test/SemaCXX/no-rtti.cpp
+++ b/clang/test/SemaCXX/no-rtti.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -fno-rtti %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -verify -fno-rtti 
%s
 
 namespace std {
   class type_info;

diff  --git a/clang/test/SemaCXX/no_dynamic_cast.cpp 
b/clang/test/SemaCXX/no_dynamic_cast.cpp
index 4db21d36f4a9..074b02f4668b 100644
--- a/clang/test/SemaCXX/no_dynamic_cast.cpp
+++ b/clang/test/SemaCXX/no_dynamic_cast.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fno-rtti-data -fsyntax-only -verify
+// RUN: %clang_cc1 %s -triple x86_64-pc-linux-gnu -fno-rtti-data -fsyntax-only 
-verify
 
 namespace std {
 struct type_info {};



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


[PATCH] D87080: [AST] Reduce the size of TemplateArgumentLocInfo.

2020-09-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 290187.
hokein marked 2 inline comments as done.
hokein added a comment.

address review comments:

- use PointerUnion
- keep the TemplateArgumentLocInfo trivial, allocate from allocator, no 
deallocation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87080

Files:
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp

Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -7103,15 +7103,15 @@
 NestedNameSpecifierLoc QualifierLoc =
   readNestedNameSpecifierLoc();
 SourceLocation TemplateNameLoc = readSourceLocation();
-return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
-   SourceLocation());
+return TemplateArgumentLocInfo(getASTContext(), QualifierLoc,
+   TemplateNameLoc, SourceLocation());
   }
   case TemplateArgument::TemplateExpansion: {
 NestedNameSpecifierLoc QualifierLoc = readNestedNameSpecifierLoc();
 SourceLocation TemplateNameLoc = readSourceLocation();
 SourceLocation EllipsisLoc = readSourceLocation();
-return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
-   EllipsisLoc);
+return TemplateArgumentLocInfo(getASTContext(), QualifierLoc,
+   TemplateNameLoc, EllipsisLoc);
   }
   case TemplateArgument::Null:
   case TemplateArgument::Integral:
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3545,12 +3545,12 @@
 }
 
 case TemplateArgument::Template:
-  return TemplateArgumentLoc(TemplateArgument(
-  Pattern.getArgument().getAsTemplate(),
-  NumExpansions),
- Pattern.getTemplateQualifierLoc(),
- Pattern.getTemplateNameLoc(),
- EllipsisLoc);
+  return TemplateArgumentLoc(
+  SemaRef.Context,
+  TemplateArgument(Pattern.getArgument().getAsTemplate(),
+   NumExpansions),
+  Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
+  EllipsisLoc);
 
 case TemplateArgument::Null:
 case TemplateArgument::Integral:
@@ -4288,8 +4288,8 @@
 if (Template.isNull())
   return true;
 
-Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
- Input.getTemplateNameLoc());
+Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
+ QualifierLoc, Input.getTemplateNameLoc());
 return false;
   }
 
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1095,7 +1095,7 @@
   case TemplateArgument::TemplateExpansion:
 Ellipsis = OrigLoc.getTemplateEllipsisLoc();
 NumExpansions = Argument.getNumTemplateExpansions();
-return TemplateArgumentLoc(Argument.getPackExpansionPattern(),
+return TemplateArgumentLoc(Context, Argument.getPackExpansionPattern(),
OrigLoc.getTemplateQualifierLoc(),
OrigLoc.getTemplateNameLoc());
 
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2886,7 +2886,7 @@
 if (!TName.isNull())
   Param->setDefaultArgument(
   SemaRef.Context,
-  TemplateArgumentLoc(TemplateArgument(TName),
+  TemplateArgumentLoc(SemaRef.Context, TemplateArgument(TName),
   D->getDefaultArgument().getTemplateQualifierLoc(),
   D->getDefaultArgument().getTemplateNameLoc()));
   }
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2670,11 +2670,11 @@
 Builder.MakeTrivial(Context, QTN->getQualifier(), Loc);
 
   if (Arg.getKind() == TemplateArgument::Template)
-return TemplateArgumentLoc(Arg, 

[PATCH] D87080: [AST] Reduce the size of TemplateArgumentLocInfo.

2020-09-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 290188.
hokein added a comment.

format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87080

Files:
  clang/include/clang/AST/TemplateBase.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp

Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -7103,15 +7103,15 @@
 NestedNameSpecifierLoc QualifierLoc =
   readNestedNameSpecifierLoc();
 SourceLocation TemplateNameLoc = readSourceLocation();
-return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
-   SourceLocation());
+return TemplateArgumentLocInfo(getASTContext(), QualifierLoc,
+   TemplateNameLoc, SourceLocation());
   }
   case TemplateArgument::TemplateExpansion: {
 NestedNameSpecifierLoc QualifierLoc = readNestedNameSpecifierLoc();
 SourceLocation TemplateNameLoc = readSourceLocation();
 SourceLocation EllipsisLoc = readSourceLocation();
-return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc,
-   EllipsisLoc);
+return TemplateArgumentLocInfo(getASTContext(), QualifierLoc,
+   TemplateNameLoc, EllipsisLoc);
   }
   case TemplateArgument::Null:
   case TemplateArgument::Integral:
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3545,12 +3545,12 @@
 }
 
 case TemplateArgument::Template:
-  return TemplateArgumentLoc(TemplateArgument(
-  Pattern.getArgument().getAsTemplate(),
-  NumExpansions),
- Pattern.getTemplateQualifierLoc(),
- Pattern.getTemplateNameLoc(),
- EllipsisLoc);
+  return TemplateArgumentLoc(
+  SemaRef.Context,
+  TemplateArgument(Pattern.getArgument().getAsTemplate(),
+   NumExpansions),
+  Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
+  EllipsisLoc);
 
 case TemplateArgument::Null:
 case TemplateArgument::Integral:
@@ -4288,8 +4288,8 @@
 if (Template.isNull())
   return true;
 
-Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
- Input.getTemplateNameLoc());
+Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
+ QualifierLoc, Input.getTemplateNameLoc());
 return false;
   }
 
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1095,7 +1095,7 @@
   case TemplateArgument::TemplateExpansion:
 Ellipsis = OrigLoc.getTemplateEllipsisLoc();
 NumExpansions = Argument.getNumTemplateExpansions();
-return TemplateArgumentLoc(Argument.getPackExpansionPattern(),
+return TemplateArgumentLoc(Context, Argument.getPackExpansionPattern(),
OrigLoc.getTemplateQualifierLoc(),
OrigLoc.getTemplateNameLoc());
 
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2886,7 +2886,7 @@
 if (!TName.isNull())
   Param->setDefaultArgument(
   SemaRef.Context,
-  TemplateArgumentLoc(TemplateArgument(TName),
+  TemplateArgumentLoc(SemaRef.Context, TemplateArgument(TName),
   D->getDefaultArgument().getTemplateQualifierLoc(),
   D->getDefaultArgument().getTemplateNameLoc()));
   }
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2670,11 +2670,11 @@
 Builder.MakeTrivial(Context, QTN->getQualifier(), Loc);
 
   if (Arg.getKind() == TemplateArgument::Template)
-return TemplateArgumentLoc(Arg, Builder.getWithLocInContext(Context),
-   Loc);
+return TemplateArgumentLoc(Context, Arg,
+   

[PATCH] D78938: Fixing all comparisons for C++20 compilation.

2020-09-07 Thread James Henderson via Phabricator via cfe-commits
jhenderson added a comment.

Not that I have anything particularly against this, but won't this likely rot 
fairly rapidly? It's not like LLVM is even on C++17 let alone C++20 yet, so 
trying to make it work like the latter when it's just going to break again 
seems a bit like wasted effort to me.




Comment at: llvm/tools/llvm-objdump/llvm-objdump.cpp:805-817
+  return IsASCII ? "^" : (const char *)u8"\u2548";
 case LineChar::RangeMid:
-  return IsASCII ? "|" : u8"\u2503";
+  return IsASCII ? "|" : (const char *)u8"\u2503";
 case LineChar::RangeEnd:
-  return IsASCII ? "v" : u8"\u253b";
+  return IsASCII ? "v" : (const char *)u8"\u253b";
 case LineChar::LabelVert:
+  return IsASCII ? "|" : (const char *)u8"\u2502";

This seems unrelated to comparison checking?



Comment at: llvm/unittests/ADT/STLExtrasTest.cpp:465
   // Check fancy pointer overload for unique_ptr
+  // Parenthesizing to_address to avoid ADL finding std::to_address
   std::unique_ptr V2 = std::make_unique(0);

Nit: trailing full stop.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78938

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


[PATCH] D87081: [analyzer][StdLibraryFunctionsChecker] Elaborate the summary of fread and fwrite

2020-09-07 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D87081#2256636 , @balazske wrote:

> This checker will make an additional assumption on `fread` and `fwrite` with 
> the ReturnValueCondition.

There is nothing new in that. This assumption described by the `.Case` has been 
here since the inception of this Checker. This patch does not change it. This 
patch adds two new argument constraints.

> The return value is constrained by `StreamChecker` too but it splits the 
> error (if returned value is less that arg 3) and non-error cases into 
> separate branches. I think this causes no problem because it will refine the 
> assumption made here (if this assumption is made first) or the assumption 
> here has no effect (if the split happened already).

Either way, this is not a problem. However, in a similar case with the 
CallAndMessage Checker, we decided to list the more specific Checker as a 
dependency. We could do that with StreamChecker too, if you think that's better 
that way. But I'd rather keep that as it is now, since as you suggests, it 
works now and will work even after this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87081

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


[PATCH] D86137: Add ignore-unknown-options flag to clang-format.

2020-09-07 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added subscribers: sammccall, JDevlieghere, aaron.ballman.
MyDeveloperDay added a comment.

> Regarding not touching the LLVM support library: I'd love to find a way, but 
> as clang-format uses the >> operator

We need to find some reviewers who look after a wider area of LLVM, if you want 
to make a change out there in LLVM/support, but it above my pay grade to 
approve ;-) maybe one of the more experienced devs could help identify the 
correct person @aaron.ballman @sammccall or alternatively take a look via git 
log as to who has been maintaining that file @JDevlieghere, they may have an 
opinion about how this should be done.




Comment at: clang/tools/clang-format/ClangFormat.cpp:108
+static cl::opt
+IgnoreUnkownOptions("ignore-unknown-options",
+cl::desc("If set, unknown format options are 
ignored."),

feels like a mouthful is there nothing shorter we could use?  -Wignore (or 
something)



Comment at: llvm/include/llvm/Support/YAMLTraits.h:792
   virtual void setError(const Twine &) = 0;
+  virtual void setIgnoreUnknown(bool) = 0;
 

I'm not a massive fan of functions with out parameter names, but I see your 
following the local style.



Comment at: llvm/include/llvm/Support/YAMLTraits.h:1520
   boolScalarMatchFound = false;
+  bool IgnoreUnkown = false;
 };

is this clang-formatted?



Comment at: llvm/lib/Support/YAMLTraits.cpp:199
+  if (IgnoreUnkown)
+return;
   for (const auto  : MN->Mapping) {

do we want to flat out ignore or just report but not fatally. (just a thought) 
silent failures are hard to diagnose


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86137

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


[PATCH] D87007: [clang-format] Correctly parse function declarations with TypenameMacros

2020-09-07 Thread Alexander Richardson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG05147d330917: [clang-format] Correctly parse function 
declarations with TypenameMacros (authored by arichardson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87007

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -6681,9 +6681,12 @@
Style);
 
   // All declarations and definitions should have the return type moved to its
-  // own
-  // line.
+  // own line.
   Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
+  Style.TypenameMacros = {"LIST"};
+  verifyFormat("SomeType\n"
+   "funcdecl(LIST(uint64_t));",
+   Style);
   verifyFormat("class E {\n"
"  int\n"
"  f() {\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2400,6 +2400,8 @@
 return true;
   for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {
+if (Tok->is(TT_TypeDeclarationParen))
+  return true;
 if (Tok->isOneOf(tok::l_paren, TT_TemplateOpener) && Tok->MatchingParen) {
   Tok = Tok->MatchingParen;
   continue;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -6681,9 +6681,12 @@
Style);
 
   // All declarations and definitions should have the return type moved to its
-  // own
-  // line.
+  // own line.
   Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
+  Style.TypenameMacros = {"LIST"};
+  verifyFormat("SomeType\n"
+   "funcdecl(LIST(uint64_t));",
+   Style);
   verifyFormat("class E {\n"
"  int\n"
"  f() {\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2400,6 +2400,8 @@
 return true;
   for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {
+if (Tok->is(TT_TypeDeclarationParen))
+  return true;
 if (Tok->isOneOf(tok::l_paren, TT_TemplateOpener) && Tok->MatchingParen) {
   Tok = Tok->MatchingParen;
   continue;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86091: [cmake] Fix build of attribute plugin example on Windows

2020-09-07 Thread Kristina Bessonova via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG04ea680a8ccc: [cmake] Fix build of attribute plugin example 
on Windows (authored by krisb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86091

Files:
  clang/examples/Attribute/CMakeLists.txt


Index: clang/examples/Attribute/CMakeLists.txt
===
--- clang/examples/Attribute/CMakeLists.txt
+++ clang/examples/Attribute/CMakeLists.txt
@@ -1,7 +1,7 @@
 add_llvm_library(Attribute MODULE Attribute.cpp PLUGIN_TOOL clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
-  target_link_libraries(Attribute ${cmake_2_8_12_PRIVATE}
+  target_link_libraries(Attribute PRIVATE
 clangAST
 clangBasic
 clangFrontend


Index: clang/examples/Attribute/CMakeLists.txt
===
--- clang/examples/Attribute/CMakeLists.txt
+++ clang/examples/Attribute/CMakeLists.txt
@@ -1,7 +1,7 @@
 add_llvm_library(Attribute MODULE Attribute.cpp PLUGIN_TOOL clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
-  target_link_libraries(Attribute ${cmake_2_8_12_PRIVATE}
+  target_link_libraries(Attribute PRIVATE
 clangAST
 clangBasic
 clangFrontend
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85351: [Analyzer] Fix for `ExprEngine::computeObjectUnderConstruction()` for base and delegating consturctor initializers

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

The tests look great, thanks! I still lack the confidence to accept, 
unfortunately.


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

https://reviews.llvm.org/D85351

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


[clang] 70523ec - [Sparc] Select the UltraSPARC instruction set with the external assembler

2020-09-07 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2020-09-07T02:49:05-04:00
New Revision: 70523ecfaca692bf5d0192e466c34ae7514624ea

URL: 
https://github.com/llvm/llvm-project/commit/70523ecfaca692bf5d0192e466c34ae7514624ea
DIFF: 
https://github.com/llvm/llvm-project/commit/70523ecfaca692bf5d0192e466c34ae7514624ea.diff

LOG: [Sparc] Select the UltraSPARC instruction set with the external assembler

Select the UltraSPARC instruction set with the external assembler on
Linux / FreeBSD / OpenBSD, matches GCC.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/Sparc.cpp
clang/test/Driver/freebsd.c
clang/test/Driver/linux-as.c
clang/test/Driver/openbsd.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp 
b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
index 043b7f257c01..70ba8eb2a7d0 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -21,12 +21,19 @@ using namespace llvm::opt;
 const char *sparc::getSparcAsmModeForCPU(StringRef Name,
  const llvm::Triple ) {
   if (Triple.getArch() == llvm::Triple::sparcv9) {
+const char *DefV9CPU;
+
+if (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD())
+  DefV9CPU = "-Av9a";
+else
+  DefV9CPU = "-Av9";
+
 return llvm::StringSwitch(Name)
 .Case("niagara", "-Av9b")
 .Case("niagara2", "-Av9b")
 .Case("niagara3", "-Av9d")
 .Case("niagara4", "-Av9d")
-.Default("-Av9");
+.Default(DefV9CPU);
   } else {
 return llvm::StringSwitch(Name)
 .Case("v8", "-Av8")

diff  --git a/clang/test/Driver/freebsd.c b/clang/test/Driver/freebsd.c
index 769bb22da0dc..1bf6dab802a1 100644
--- a/clang/test/Driver/freebsd.c
+++ b/clang/test/Driver/freebsd.c
@@ -176,7 +176,7 @@
 // RUN: %clang -mcpu=ultrasparc -target sparc64-unknown-freebsd8 %s -### 
-no-integrated-as 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-SPARC-CPU %s
 // CHECK-SPARC-CPU: cc1{{.*}}" "-target-cpu" "ultrasparc"
-// CHECK-SPARC-CPU: as{{.*}}" "-Av9
+// CHECK-SPARC-CPU: as{{.*}}" "-Av9a
 
 // Check that -G flags are passed to the linker for mips
 // RUN: %clang -target mips-unknown-freebsd %s -### -G0 2>&1 \

diff  --git a/clang/test/Driver/linux-as.c b/clang/test/Driver/linux-as.c
index 77ac05f30942..0959bd7ba0a1 100644
--- a/clang/test/Driver/linux-as.c
+++ b/clang/test/Driver/linux-as.c
@@ -168,7 +168,7 @@
 // RUN:   | FileCheck -check-prefix=CHECK-SPARCV9 %s
 // CHECK-SPARCV9: as
 // CHECK-SPARCV9: -64
-// CHECK-SPARCV9: -Av9
+// CHECK-SPARCV9: -Av9a
 // CHECK-SPARCV9-NOT: -KPIC
 // CHECK-SPARCV9: -o
 //
@@ -177,7 +177,7 @@
 // RUN:   | FileCheck -check-prefix=CHECK-SPARCV9PIC %s
 // CHECK-SPARCV9PIC: as
 // CHECK-SPARCV9PIC: -64
-// CHECK-SPARCV9PIC: -Av9
+// CHECK-SPARCV9PIC: -Av9a
 // CHECK-SPARCV9PIC: -KPIC
 // CHECK-SPARCV9PIC: -o
 //

diff  --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index 203b4b4a2ff0..ae1aa6441690 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -70,7 +70,7 @@
 // RUN:   | FileCheck -check-prefix=CHECK-MIPS64EL-PIC %s
 // CHECK-AMD64-M32: as{{.*}}" "--32"
 // CHECK-POWERPC: as{{.*}}" "-mppc" "-many"
-// CHECK-SPARC64: as{{.*}}" "-64" "-Av9"
+// CHECK-SPARC64: as{{.*}}" "-64" "-Av9a"
 // CHECK-MIPS64: as{{.*}}" "-mabi" "64" "-EB"
 // CHECK-MIPS64-PIC: as{{.*}}" "-mabi" "64" "-EB" "-KPIC"
 // CHECK-MIPS64EL: as{{.*}}" "-mabi" "64" "-EL"



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


[PATCH] D86950: [clang-format] Check that */& after typename macros are pointers/references

2020-09-07 Thread Alexander Richardson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcd01eec14bc0: [clang-format] Check that */ after 
typename macros are pointers/references (authored by arichardson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86950

Files:
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8041,6 +8041,14 @@
   verifyFormat("vector v;");
   verifyFormat("vector v;");
   verifyFormat("vector v;");
+  FormatStyle TypeMacros = getLLVMStyle();
+  TypeMacros.TypenameMacros = {"LIST"};
+  verifyFormat("vector v;", TypeMacros);
+  verifyFormat("vector v;", TypeMacros);
+  verifyFormat("vector v;", TypeMacros);
+  verifyFormat("vector v;", TypeMacros);
+  verifyFormat("vector v;", TypeMacros); // multiplication
+
   FormatStyle CustomQualifier = getLLVMStyle();
   // Add indentifers that should not be parsed as a qualifier by default.
   CustomQualifier.AttributeMacros.push_back("__my_qualifier");
@@ -8105,6 +8113,9 @@
   // a type declaration:
   verifyFormat("MACRO(A *__my_qualifier);", CustomQualifier);
   verifyFormat("void f() { MACRO(A *__my_qualifier); }", CustomQualifier);
+  // Also check that TypenameMacros prevents parsing it as multiplication:
+  verifyIndependentOfContext("MACRO(LIST(uint64_t) * a);"); // multiplication
+  verifyIndependentOfContext("MACRO(LIST(uint64_t) *a);", TypeMacros); // type
 
   verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
   verifyFormat("void f() { f(float{1}, a * a); }");
@@ -16553,12 +16564,15 @@
   verifyFormat("STACK_OF(LIST(int)) a, b;", Macros);
   verifyFormat("for (LIST(int) *a = NULL; a;) {\n}", Macros);
   verifyFormat("STACK_OF(int) f(LIST(int) *arg);", Macros);
+  verifyFormat("vector x;", Macros);
+  verifyFormat("vector f(LIST(uint64_t) *arg);", 
Macros);
 
   Macros.PointerAlignment = FormatStyle::PAS_Left;
   verifyFormat("STACK_OF(int)* a;", Macros);
   verifyFormat("STACK_OF(int*)* a;", Macros);
   verifyFormat("x = (STACK_OF(uint64_t))*a;", Macros);
   verifyFormat("x = (STACK_OF(uint64_t))", Macros);
+  verifyFormat("vector x;", Macros);
 }
 
 TEST_F(FormatTest, AmbersandInLamda) {


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8041,6 +8041,14 @@
   verifyFormat("vector v;");
   verifyFormat("vector v;");
   verifyFormat("vector v;");
+  FormatStyle TypeMacros = getLLVMStyle();
+  TypeMacros.TypenameMacros = {"LIST"};
+  verifyFormat("vector v;", TypeMacros);
+  verifyFormat("vector v;", TypeMacros);
+  verifyFormat("vector v;", TypeMacros);
+  verifyFormat("vector v;", TypeMacros);
+  verifyFormat("vector v;", TypeMacros); // multiplication
+
   FormatStyle CustomQualifier = getLLVMStyle();
   // Add indentifers that should not be parsed as a qualifier by default.
   CustomQualifier.AttributeMacros.push_back("__my_qualifier");
@@ -8105,6 +8113,9 @@
   // a type declaration:
   verifyFormat("MACRO(A *__my_qualifier);", CustomQualifier);
   verifyFormat("void f() { MACRO(A *__my_qualifier); }", CustomQualifier);
+  // Also check that TypenameMacros prevents parsing it as multiplication:
+  verifyIndependentOfContext("MACRO(LIST(uint64_t) * a);"); // multiplication
+  verifyIndependentOfContext("MACRO(LIST(uint64_t) *a);", TypeMacros); // type
 
   verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
   verifyFormat("void f() { f(float{1}, a * a); }");
@@ -16553,12 +16564,15 @@
   verifyFormat("STACK_OF(LIST(int)) a, b;", Macros);
   verifyFormat("for (LIST(int) *a = NULL; a;) {\n}", Macros);
   verifyFormat("STACK_OF(int) f(LIST(int) *arg);", Macros);
+  verifyFormat("vector x;", Macros);
+  verifyFormat("vector f(LIST(uint64_t) *arg);", Macros);
 
   Macros.PointerAlignment = FormatStyle::PAS_Left;
   verifyFormat("STACK_OF(int)* a;", Macros);
   verifyFormat("STACK_OF(int*)* a;", Macros);
   verifyFormat("x = (STACK_OF(uint64_t))*a;", Macros);
   verifyFormat("x = (STACK_OF(uint64_t))", Macros);
+  verifyFormat("vector x;", Macros);
 }
 
 TEST_F(FormatTest, AmbersandInLamda) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86959: [clang-format] Fix formatting of _Atomic() qualifier

2020-09-07 Thread Alexander Richardson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG56fa7d1dc6a8: [clang-format] Fix formatting of _Atomic() 
qualifier (authored by arichardson).

Changed prior to commit:
  https://reviews.llvm.org/D86959?vs=289509=290211#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86959

Files:
  clang/lib/Format/FormatToken.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -168,6 +168,8 @@
   verifyFormat("vector<::Type> v;");
   verifyFormat("::ns::SomeFunction(::ns::SomeOtherFunction())");
   verifyFormat("static constexpr bool Bar = decltype(bar())::value;");
+  verifyFormat("static constexpr bool Bar = typeof(bar())::value;");
+  verifyFormat("static constexpr bool Bar = _Atomic(bar())::value;");
   verifyFormat("bool a = 2 < ::SomeFunction();");
   verifyFormat("ALWAYS_INLINE ::std::string getName();");
   verifyFormat("some::string getName();");
@@ -7904,7 +7906,10 @@
   verifyFormat("auto PointerBinding = [](const char *S) {};");
   verifyFormat("typedef typeof(int(int, int)) *MyFunc;");
   verifyFormat("[](const decltype(*a) ) {}");
+  verifyFormat("[](const typeof(*a) ) {}");
+  verifyFormat("[](const _Atomic(a *) ) {}");
   verifyFormat("decltype(a * b) F();");
+  verifyFormat("typeof(a * b) F();");
   verifyFormat("#define MACRO() [](A *a) { return 1; }");
   verifyFormat("Constructor() : member([](A *a, B *b) {}) {}");
   verifyIndependentOfContext("typedef void (*f)(int *a);");
@@ -7970,6 +7975,8 @@
   verifyFormat("delete *x;", Left);
   verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left);
   verifyFormat("[](const decltype(*a)* ptr) {}", Left);
+  verifyFormat("[](const typeof(*a)* ptr) {}", Left);
+  verifyFormat("[](const _Atomic(a*)* ptr) {}", Left);
   verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left);
   verifyFormat("auto x(A&&, B&&, C&&) -> D;", Left);
   verifyFormat("auto x = [](A&&, B&&, C&&) -> D {};", Left);
@@ -8066,6 +8073,8 @@
   verifyFormat("foo();");
   verifyFormat("foo();");
   verifyFormat("decltype(*::std::declval()) void F();");
+  verifyFormat("typeof(*::std::declval()) void F();");
+  verifyFormat("_Atomic(*::std::declval()) void F();");
   verifyFormat(
   "template ::value &&\n"
@@ -8089,6 +8098,9 @@
   verifyIndependentOfContext("MACRO(int *i);");
   verifyIndependentOfContext("MACRO(auto *a);");
   verifyIndependentOfContext("MACRO(const A *a);");
+  verifyIndependentOfContext("MACRO(_Atomic(A) *a);");
+  verifyIndependentOfContext("MACRO(decltype(A) *a);");
+  verifyIndependentOfContext("MACRO(typeof(A) *a);");
   verifyIndependentOfContext("MACRO(A *const a);");
   verifyIndependentOfContext("MACRO(A *restrict a);");
   verifyIndependentOfContext("MACRO(A *__restrict__ a);");
@@ -8639,6 +8651,10 @@
"LooongFunctionDefinition() {}");
   verifyFormat("decltype(LngName)\n"
"LooongFunctionDefinition() {}");
+  verifyFormat("typeof(LoongName)\n"
+   "LooongFunctionDefinition() {}");
+  verifyFormat("_Atomic(LongName)\n"
+   "LooongFunctionDefinition() {}");
   verifyFormat("LngReturnType\n"
"LooongFunctionDeclaration(T... t);");
   verifyFormat("LngReturnType\n"
@@ -8988,6 +9004,8 @@
   verifyFormat("int foo(int i) { return fo1{}(i); }");
   verifyFormat("int foo(int i) { return fo1{}(i); }");
   verifyFormat("auto i = decltype(x){};");
+  verifyFormat("auto i = typeof(x){};");
+  verifyFormat("auto i = _Atomic(x){};");
   verifyFormat("std::vector v = {1, 0 /* comment */};");
   verifyFormat("Node n{1, Node{1000}, //\n"
"   2};");
@@ -11580,6 +11598,8 @@
   verifyFormat("auto i = std::make_unique(5);", NoSpace);
   verifyFormat("size_t x = sizeof(x);", NoSpace);
   verifyFormat("auto f(int x) -> decltype(x);", NoSpace);
+  verifyFormat("auto f(int x) -> typeof(x);", NoSpace);
+  verifyFormat("auto f(int x) -> _Atomic(x);", NoSpace);
   verifyFormat("int f(T x) noexcept(x.create());", NoSpace);
   verifyFormat("alignas(128) char a[128];", NoSpace);
   verifyFormat("size_t x = alignof(MyType);", NoSpace);
@@ -11628,6 +11648,8 @@
   verifyFormat("auto i = std::make_unique (5);", Space);
   verifyFormat("size_t x = sizeof (x);", Space);
   verifyFormat("auto f (int x) -> decltype (x);", Space);
+  

[clang] e7bd058 - [clang-format] Allow configuring list of macros that map to attributes

2020-09-07 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2020-09-07T10:09:17+01:00
New Revision: e7bd058c7e2cb2c675a4b78ec770ea725bff8c64

URL: 
https://github.com/llvm/llvm-project/commit/e7bd058c7e2cb2c675a4b78ec770ea725bff8c64
DIFF: 
https://github.com/llvm/llvm-project/commit/e7bd058c7e2cb2c675a4b78ec770ea725bff8c64.diff

LOG: [clang-format] Allow configuring list of macros that map to attributes

This adds a `AttributeMacros` configuration option that causes certain
identifiers to be parsed like a __attribute__((foo)) annotation.
This is motivated by our CHERI C/C++ fork which adds a __capability
qualifier for pointer/reference. Without this change clang-format parses
many type declarations as multiplications/bitwise-and instead.
I initially considered adding "__capability" as a new clang-format keyword,
but having a list of macros that should be treated as attributes is more
flexible since it can be used e.g. for static analyzer annotations or other 
language
extensions.

Example: std::vector -> std::vector

Depends on D86775 (to apply cleanly)

Reviewed By: MyDeveloperDay, jrtc27

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index c35718b51248..72a25032151f 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -758,7 +758,24 @@ the configuration (without a prefix: ``Auto``).
  int b) {
}
 
+**AttributeMacros** (``std::vector``)
+  A vector of strings that should be interpreted as attributes/qualifiers
+  instead of identifiers. This can be useful for language extensions or
+  static analyzer annotations:
 
+  .. code-block:: c++
+
+x = (char *__capability)
+int function(void) __ununsed;
+void only_writes_to_buffer(char *__output buffer);
+
+  In the .clang-format configuration file, this can be configured like:
+
+  .. code-block:: yaml
+
+AttributeMacros: ['__capability', '__output', '__ununsed']
+
+  For example: __capability.
 
 **BinPackArguments** (``bool``)
   If ``false``, a function call's arguments will either be all on the

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 269eab971a2c..6bb828d60071 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -583,6 +583,24 @@ struct FormatStyle {
   /// The template declaration breaking style to use.
   BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;
 
+  /// A vector of strings that should be interpreted as attributes/qualifiers
+  /// instead of identifiers. This can be useful for language extensions or
+  /// static analyzer annotations.
+  ///
+  /// For example:
+  /// \code
+  ///   x = (char *__capability)
+  ///   int function(void) __ununsed;
+  ///   void only_writes_to_buffer(char *__output buffer);
+  /// \endcode
+  ///
+  /// In the .clang-format configuration file, this can be configured like:
+  /// \code{.yaml}
+  ///   AttributeMacros: ['__capability', '__output', '__ununsed']
+  /// \endcode
+  ///
+  std::vector AttributeMacros;
+
   /// If ``false``, a function call's arguments will either be all on the
   /// same line or will have one line each.
   /// \code
@@ -2351,6 +2369,7 @@ struct FormatStyle {
R.AlwaysBreakBeforeMultilineStrings &&
AlwaysBreakTemplateDeclarations ==
R.AlwaysBreakTemplateDeclarations &&
+   AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
BinPackParameters == R.BinPackParameters &&
BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index fe11cba9bfdf..5dda2bda06b5 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -475,6 +475,7 @@ template <> struct MappingTraits {
Style.AlwaysBreakBeforeMultilineStrings);
 IO.mapOptional("AlwaysBreakTemplateDeclarations",
Style.AlwaysBreakTemplateDeclarations);
+IO.mapOptional("AttributeMacros", Style.AttributeMacros);
 IO.mapOptional("BinPackArguments", Style.BinPackArguments);
 IO.mapOptional("BinPackParameters", Style.BinPackParameters);
 IO.mapOptional("BraceWrapping", Style.BraceWrapping);
@@ -842,6 +843,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
   LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
   

[PATCH] D86930: [clang-format] Handle typename macros inside cast expressions

2020-09-07 Thread Alexander Richardson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8aa3b8da5db2: [clang-format] Handle typename macros inside 
cast expressions (authored by arichardson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86930

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16557,6 +16557,8 @@
   Macros.PointerAlignment = FormatStyle::PAS_Left;
   verifyFormat("STACK_OF(int)* a;", Macros);
   verifyFormat("STACK_OF(int*)* a;", Macros);
+  verifyFormat("x = (STACK_OF(uint64_t))*a;", Macros);
+  verifyFormat("x = (STACK_OF(uint64_t))", Macros);
 }
 
 TEST_F(FormatTest, AmbersandInLamda) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -244,6 +244,8 @@
   Contexts.back().IsExpression = false;
 } else if (Left->Previous && Left->Previous->is(tok::kw___attribute)) {
   Left->setType(TT_AttributeParen);
+} else if (Left->Previous && Left->Previous->is(TT_TypenameMacro)) {
+  Left->setType(TT_TypenameMacroParen);
 } else if (Left->Previous && Left->Previous->is(TT_ForEachMacro)) {
   // The first argument to a foreach macro is a declaration.
   Contexts.back().IsForEachMacro = true;
@@ -335,6 +337,8 @@
 
 if (Left->is(TT_AttributeParen))
   CurrentToken->setType(TT_AttributeParen);
+if (Left->is(TT_TypenameMacroParen))
+  CurrentToken->setType(TT_TypenameMacroParen);
 if (Left->Previous && Left->Previous->is(TT_JavaAnnotation))
   CurrentToken->setType(TT_JavaAnnotation);
 if (Left->Previous && Left->Previous->is(TT_LeadingJavaAnnotation))
@@ -1855,9 +1859,11 @@
   }
   return T && T->is(TT_PointerOrReference);
 };
-bool ParensAreType = !Tok.Previous || Tok.Previous->is(TT_TemplateCloser) 
||
- Tok.Previous->isSimpleTypeSpecifier() ||
- IsQualifiedPointerOrReference(Tok.Previous);
+bool ParensAreType =
+!Tok.Previous ||
+Tok.Previous->isOneOf(TT_TemplateCloser, TT_TypenameMacroParen) ||
+Tok.Previous->isSimpleTypeSpecifier() ||
+IsQualifiedPointerOrReference(Tok.Previous);
 bool ParensCouldEndDecl =
 Tok.Next->isOneOf(tok::equal, tok::semi, tok::l_brace, tok::greater);
 if (ParensAreType && !ParensCouldEndDecl)
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -102,6 +102,7 @@
   TYPE(TrailingReturnArrow)
\
   TYPE(TrailingUnaryOperator)  
\
   TYPE(TypenameMacro)  
\
+  TYPE(TypenameMacroParen) 
\
   TYPE(UnaryOperator)  
\
   TYPE(UntouchableMacroFunc)   
\
   TYPE(CSharpStringLiteral)
\


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16557,6 +16557,8 @@
   Macros.PointerAlignment = FormatStyle::PAS_Left;
   verifyFormat("STACK_OF(int)* a;", Macros);
   verifyFormat("STACK_OF(int*)* a;", Macros);
+  verifyFormat("x = (STACK_OF(uint64_t))*a;", Macros);
+  verifyFormat("x = (STACK_OF(uint64_t))", Macros);
 }
 
 TEST_F(FormatTest, AmbersandInLamda) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -244,6 +244,8 @@
   Contexts.back().IsExpression = false;
 } else if (Left->Previous && Left->Previous->is(tok::kw___attribute)) {
   Left->setType(TT_AttributeParen);
+} else if (Left->Previous && Left->Previous->is(TT_TypenameMacro)) {
+  Left->setType(TT_TypenameMacroParen);
 } else if (Left->Previous && Left->Previous->is(TT_ForEachMacro)) {
   // The first argument to a foreach macro is a declaration.
   Contexts.back().IsForEachMacro = true;
@@ -335,6 +337,8 @@
 
 if (Left->is(TT_AttributeParen))
   CurrentToken->setType(TT_AttributeParen);
+if (Left->is(TT_TypenameMacroParen))
+  CurrentToken->setType(TT_TypenameMacroParen);
 if (Left->Previous 

[clang] 9a22eba - [clang-format] Parse __underlying_type(T) as a type

2020-09-07 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2020-09-07T10:09:18+01:00
New Revision: 9a22eba15091ea849fa78c09ac4c9f7260071790

URL: 
https://github.com/llvm/llvm-project/commit/9a22eba15091ea849fa78c09ac4c9f7260071790
DIFF: 
https://github.com/llvm/llvm-project/commit/9a22eba15091ea849fa78c09ac4c9f7260071790.diff

LOG: [clang-format] Parse __underlying_type(T) as a type

Before: MACRO(__underlying_type(A) * a);
After:  MACRO(__underlying_type(A) *a);

Reviewed By: MyDeveloperDay

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

Added: 


Modified: 
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 8253bf18fc66..76ef99e72d58 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -528,6 +528,7 @@ struct FormatToken {
 case tok::kw_static_assert:
 case tok::kw__Atomic:
 case tok::kw___attribute:
+case tok::kw___underlying_type:
   return true;
 default:
   return false;

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 0239dbd63d94..4867f9e3d6c1 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -247,7 +247,8 @@ class AnnotatingParser {
   Left->setType(TT_AttributeParen);
 } else if (PrevNonComment &&
PrevNonComment->isOneOf(TT_TypenameMacro, tok::kw_decltype,
-   tok::kw_typeof, tok::kw__Atomic)) {
+   tok::kw_typeof, tok::kw__Atomic,
+   tok::kw___underlying_type)) {
   Left->setType(TT_TypeDeclarationParen);
   // decltype() and typeof() usually contain expressions.
   if (PrevNonComment->isOneOf(tok::kw_decltype, tok::kw_typeof))

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index a5943847882f..b1d46a27ef43 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -169,6 +169,7 @@ TEST_F(FormatTest, NestedNameSpecifiers) {
   verifyFormat("::ns::SomeFunction(::ns::SomeOtherFunction())");
   verifyFormat("static constexpr bool Bar = decltype(bar())::value;");
   verifyFormat("static constexpr bool Bar = typeof(bar())::value;");
+  verifyFormat("static constexpr bool Bar = __underlying_type(bar())::value;");
   verifyFormat("static constexpr bool Bar = _Atomic(bar())::value;");
   verifyFormat("bool a = 2 < ::SomeFunction();");
   verifyFormat("ALWAYS_INLINE ::std::string getName();");
@@ -7908,6 +7909,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("[](const decltype(*a) ) {}");
   verifyFormat("[](const typeof(*a) ) {}");
   verifyFormat("[](const _Atomic(a *) ) {}");
+  verifyFormat("[](const __underlying_type(a) ) {}");
   verifyFormat("decltype(a * b) F();");
   verifyFormat("typeof(a * b) F();");
   verifyFormat("#define MACRO() [](A *a) { return 1; }");
@@ -7977,6 +7979,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("[](const decltype(*a)* ptr) {}", Left);
   verifyFormat("[](const typeof(*a)* ptr) {}", Left);
   verifyFormat("[](const _Atomic(a*)* ptr) {}", Left);
+  verifyFormat("[](const __underlying_type(a)* ptr) {}", Left);
   verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left);
   verifyFormat("auto x(A&&, B&&, C&&) -> D;", Left);
   verifyFormat("auto x = [](A&&, B&&, C&&) -> D {};", Left);
@@ -8075,6 +8078,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("decltype(*::std::declval()) void F();");
   verifyFormat("typeof(*::std::declval()) void F();");
   verifyFormat("_Atomic(*::std::declval()) void F();");
+  verifyFormat("__underlying_type(*::std::declval()) void F();");
   verifyFormat(
   "template ::value &&\n"
@@ -8101,6 +8105,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyIndependentOfContext("MACRO(_Atomic(A) *a);");
   verifyIndependentOfContext("MACRO(decltype(A) *a);");
   verifyIndependentOfContext("MACRO(typeof(A) *a);");
+  verifyIndependentOfContext("MACRO(__underlying_type(A) *a);");
   verifyIndependentOfContext("MACRO(A *const a);");
   verifyIndependentOfContext("MACRO(A *restrict a);");
   verifyIndependentOfContext("MACRO(A *__restrict__ a);");
@@ -8655,6 +8660,8 @@ TEST_F(FormatTest, BreaksLongDeclarations) {
"LooongFunctionDefinition() 
{}");
   verifyFormat("_Atomic(LongName)\n"
"LooongFunctionDefinition() 
{}");
+  verifyFormat("__underlying_type(LooongName)\n"
+   "LooongFunctionDefinition() 
{}");
   

[clang] cd01eec - [clang-format] Check that */& after typename macros are pointers/references

2020-09-07 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2020-09-07T10:09:18+01:00
New Revision: cd01eec14bc045a8616604cadf94dba025090ba5

URL: 
https://github.com/llvm/llvm-project/commit/cd01eec14bc045a8616604cadf94dba025090ba5
DIFF: 
https://github.com/llvm/llvm-project/commit/cd01eec14bc045a8616604cadf94dba025090ba5.diff

LOG: [clang-format] Check that */& after typename macros are pointers/references

Reviewed By: MyDeveloperDay

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

Added: 


Modified: 
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index be68da6f2ef6..978c22c6ee69 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8041,6 +8041,14 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("vector v;");
   verifyFormat("vector v;");
   verifyFormat("vector v;");
+  FormatStyle TypeMacros = getLLVMStyle();
+  TypeMacros.TypenameMacros = {"LIST"};
+  verifyFormat("vector v;", TypeMacros);
+  verifyFormat("vector v;", TypeMacros);
+  verifyFormat("vector v;", TypeMacros);
+  verifyFormat("vector v;", TypeMacros);
+  verifyFormat("vector v;", TypeMacros); // multiplication
+
   FormatStyle CustomQualifier = getLLVMStyle();
   // Add indentifers that should not be parsed as a qualifier by default.
   CustomQualifier.AttributeMacros.push_back("__my_qualifier");
@@ -8105,6 +8113,9 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   // a type declaration:
   verifyFormat("MACRO(A *__my_qualifier);", CustomQualifier);
   verifyFormat("void f() { MACRO(A *__my_qualifier); }", CustomQualifier);
+  // Also check that TypenameMacros prevents parsing it as multiplication:
+  verifyIndependentOfContext("MACRO(LIST(uint64_t) * a);"); // multiplication
+  verifyIndependentOfContext("MACRO(LIST(uint64_t) *a);", TypeMacros); // type
 
   verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
   verifyFormat("void f() { f(float{1}, a * a); }");
@@ -16553,12 +16564,15 @@ TEST_F(FormatTest, TypenameMacros) {
   verifyFormat("STACK_OF(LIST(int)) a, b;", Macros);
   verifyFormat("for (LIST(int) *a = NULL; a;) {\n}", Macros);
   verifyFormat("STACK_OF(int) f(LIST(int) *arg);", Macros);
+  verifyFormat("vector x;", Macros);
+  verifyFormat("vector f(LIST(uint64_t) *arg);", 
Macros);
 
   Macros.PointerAlignment = FormatStyle::PAS_Left;
   verifyFormat("STACK_OF(int)* a;", Macros);
   verifyFormat("STACK_OF(int*)* a;", Macros);
   verifyFormat("x = (STACK_OF(uint64_t))*a;", Macros);
   verifyFormat("x = (STACK_OF(uint64_t))", Macros);
+  verifyFormat("vector x;", Macros);
 }
 
 TEST_F(FormatTest, AmbersandInLamda) {



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


[clang] 05147d3 - [clang-format] Correctly parse function declarations with TypenameMacros

2020-09-07 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2020-09-07T10:09:18+01:00
New Revision: 05147d33091720e2df929d6fea3b0fd2a657ac61

URL: 
https://github.com/llvm/llvm-project/commit/05147d33091720e2df929d6fea3b0fd2a657ac61
DIFF: 
https://github.com/llvm/llvm-project/commit/05147d33091720e2df929d6fea3b0fd2a657ac61.diff

LOG: [clang-format] Correctly parse function declarations with TypenameMacros

When using the always break after return type setting:
Before:
SomeType funcdecl(LIST(uint64_t));
After:
SomeType
funcdecl(LIST(uint64_t));"

Reviewed By: MyDeveloperDay

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 4867f9e3d6c1..5dd6a7a9da40 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2400,6 +2400,8 @@ static bool isFunctionDeclarationName(const FormatToken 
,
 return true;
   for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {
+if (Tok->is(TT_TypeDeclarationParen))
+  return true;
 if (Tok->isOneOf(tok::l_paren, TT_TemplateOpener) && Tok->MatchingParen) {
   Tok = Tok->MatchingParen;
   continue;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b1d46a27ef43..b198efa4af9e 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6681,9 +6681,12 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
Style);
 
   // All declarations and definitions should have the return type moved to its
-  // own
-  // line.
+  // own line.
   Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
+  Style.TypenameMacros = {"LIST"};
+  verifyFormat("SomeType\n"
+   "funcdecl(LIST(uint64_t));",
+   Style);
   verifyFormat("class E {\n"
"  int\n"
"  f() {\n"



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


[clang] 8aa3b8d - [clang-format] Handle typename macros inside cast expressions

2020-09-07 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2020-09-07T10:09:17+01:00
New Revision: 8aa3b8da5db2ae73bf536b630915eb9f0ddc15cb

URL: 
https://github.com/llvm/llvm-project/commit/8aa3b8da5db2ae73bf536b630915eb9f0ddc15cb
DIFF: 
https://github.com/llvm/llvm-project/commit/8aa3b8da5db2ae73bf536b630915eb9f0ddc15cb.diff

LOG: [clang-format] Handle typename macros inside cast expressions

Before: x = (STACK_OF(uint64_t)) & a;
After:  x = (STACK_OF(uint64_t))

Reviewed By: MyDeveloperDay

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

Added: 


Modified: 
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 795c26889629..a9aeef5e9e52 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -102,6 +102,7 @@ namespace format {
   TYPE(TrailingReturnArrow)
\
   TYPE(TrailingUnaryOperator)  
\
   TYPE(TypenameMacro)  
\
+  TYPE(TypenameMacroParen) 
\
   TYPE(UnaryOperator)  
\
   TYPE(UntouchableMacroFunc)   
\
   TYPE(CSharpStringLiteral)
\

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index fc6a226dc4a1..097843bdca84 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -244,6 +244,8 @@ class AnnotatingParser {
   Contexts.back().IsExpression = false;
 } else if (Left->Previous && Left->Previous->is(tok::kw___attribute)) {
   Left->setType(TT_AttributeParen);
+} else if (Left->Previous && Left->Previous->is(TT_TypenameMacro)) {
+  Left->setType(TT_TypenameMacroParen);
 } else if (Left->Previous && Left->Previous->is(TT_ForEachMacro)) {
   // The first argument to a foreach macro is a declaration.
   Contexts.back().IsForEachMacro = true;
@@ -335,6 +337,8 @@ class AnnotatingParser {
 
 if (Left->is(TT_AttributeParen))
   CurrentToken->setType(TT_AttributeParen);
+if (Left->is(TT_TypenameMacroParen))
+  CurrentToken->setType(TT_TypenameMacroParen);
 if (Left->Previous && Left->Previous->is(TT_JavaAnnotation))
   CurrentToken->setType(TT_JavaAnnotation);
 if (Left->Previous && Left->Previous->is(TT_LeadingJavaAnnotation))
@@ -1855,9 +1859,11 @@ class AnnotatingParser {
   }
   return T && T->is(TT_PointerOrReference);
 };
-bool ParensAreType = !Tok.Previous || Tok.Previous->is(TT_TemplateCloser) 
||
- Tok.Previous->isSimpleTypeSpecifier() ||
- IsQualifiedPointerOrReference(Tok.Previous);
+bool ParensAreType =
+!Tok.Previous ||
+Tok.Previous->isOneOf(TT_TemplateCloser, TT_TypenameMacroParen) ||
+Tok.Previous->isSimpleTypeSpecifier() ||
+IsQualifiedPointerOrReference(Tok.Previous);
 bool ParensCouldEndDecl =
 Tok.Next->isOneOf(tok::equal, tok::semi, tok::l_brace, tok::greater);
 if (ParensAreType && !ParensCouldEndDecl)

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index f224ab03271d..be68da6f2ef6 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -16557,6 +16557,8 @@ TEST_F(FormatTest, TypenameMacros) {
   Macros.PointerAlignment = FormatStyle::PAS_Left;
   verifyFormat("STACK_OF(int)* a;", Macros);
   verifyFormat("STACK_OF(int*)* a;", Macros);
+  verifyFormat("x = (STACK_OF(uint64_t))*a;", Macros);
+  verifyFormat("x = (STACK_OF(uint64_t))", Macros);
 }
 
 TEST_F(FormatTest, AmbersandInLamda) {



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


[PATCH] D86782: [clang-format] Allow configuring list of macros that map to attributes

2020-09-07 Thread Alexander Richardson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe7bd058c7e2c: [clang-format] Allow configuring list of 
macros that map to attributes (authored by arichardson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86782

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8040,7 +8040,20 @@
   verifyFormat("vector v;");
   verifyFormat("vector v;");
   verifyFormat("vector v;");
+  verifyFormat("vector v;");
+  FormatStyle CustomQualifier = getLLVMStyle();
+  // Add indentifers that should not be parsed as a qualifier by default.
+  CustomQualifier.AttributeMacros.push_back("__my_qualifier");
+  CustomQualifier.AttributeMacros.push_back("_My_qualifier");
+  CustomQualifier.AttributeMacros.push_back("my_other_qualifier");
+  verifyFormat("vector parse_as_multiply;");
+  verifyFormat("vector v;", CustomQualifier);
+  verifyFormat("vector parse_as_multiply;");
+  verifyFormat("vector v;", CustomQualifier);
+  verifyFormat("vector parse_as_multiply;");
+  verifyFormat("vector v;", CustomQualifier);
   verifyFormat("vector v;");
+  verifyFormat("vector v;");
   verifyFormat("vector v;");
   verifyFormat("foo();");
   verifyFormat("foo();");
@@ -8084,10 +8097,23 @@
   verifyIndependentOfContext("MACRO(A *[[clang::attr(\"foo\")]] a);");
   verifyIndependentOfContext("MACRO(A *__ptr32 a);");
   verifyIndependentOfContext("MACRO(A *__ptr64 a);");
+  verifyIndependentOfContext("MACRO(A *__capability);");
+  verifyIndependentOfContext("MACRO(A &__capability);");
+  verifyFormat("MACRO(A *__my_qualifier);");   // type declaration
+  verifyFormat("void f() { MACRO(A * __my_qualifier); }"); // multiplication
+  // If we add __my_qualifier to AttributeMacros it should always be parsed as
+  // a type declaration:
+  verifyFormat("MACRO(A *__my_qualifier);", CustomQualifier);
+  verifyFormat("void f() { MACRO(A *__my_qualifier); }", CustomQualifier);
+
   verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
   verifyFormat("void f() { f(float{1}, a * a); }");
   // FIXME: Is there a way to make this work?
   // verifyIndependentOfContext("MACRO(A *a);");
+  verifyFormat("MACRO(A );");
+  verifyFormat("MACRO(A *B);");
+  verifyFormat("void f() { MACRO(A * B); }");
+  verifyFormat("void f() { MACRO(A & B); }");
 
   verifyFormat("DatumHandle const *operator->() const { return input_; }");
   verifyFormat("return options != nullptr && operator==(*options);");
@@ -8137,10 +8163,47 @@
   verifyFormat("a __attribute__((unused))\n"
"aaa(int i);");
   FormatStyle AfterType = getLLVMStyle();
-  AfterType.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  AfterType.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
   verifyFormat("__attribute__((nodebug)) void\n"
"foo() {}\n",
AfterType);
+  verifyFormat("__unused void\n"
+   "foo() {}",
+   AfterType);
+
+  FormatStyle CustomAttrs = getLLVMStyle();
+  CustomAttrs.AttributeMacros.push_back("__unused");
+  CustomAttrs.AttributeMacros.push_back("__attr1");
+  CustomAttrs.AttributeMacros.push_back("__attr2");
+  CustomAttrs.AttributeMacros.push_back("no_underscore_attr");
+  verifyFormat("vector v;");
+  verifyFormat("vector v;");
+  verifyFormat("vector v;");
+  // Check that it is parsed as a multiplication without AttributeMacros and
+  // as a pointer qualifier when we add __attr1/__attr2 to AttributeMacros.
+  verifyFormat("vector v;");
+  verifyFormat("vector v;");
+  verifyFormat("vector v;");
+  verifyFormat("vector v;");
+  verifyFormat("vector v;", CustomAttrs);
+  verifyFormat("vector v;", CustomAttrs);
+  verifyFormat("vector v;", CustomAttrs);
+  verifyFormat("vector v;", CustomAttrs);
+  verifyFormat("vector v;", CustomAttrs);
+  verifyFormat("vector v;", CustomAttrs);
+  verifyFormat("vector v;", CustomAttrs);
+
+  // Check that these are not parsed as function declarations:
+  CustomAttrs.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
+  CustomAttrs.BreakBeforeBraces = FormatStyle::BS_Allman;
+  verifyFormat("SomeType s(InitValue);", CustomAttrs);
+  verifyFormat("SomeType s{InitValue};", CustomAttrs);
+  verifyFormat("SomeType *__unused s(InitValue);", CustomAttrs);
+  verifyFormat("SomeType *__unused s{InitValue};", CustomAttrs);
+  verifyFormat("SomeType s __unused(InitValue);", CustomAttrs);
+  verifyFormat("SomeType s __unused{InitValue};", CustomAttrs);
+  

[PATCH] D86960: [clang-format] Parse __underlying_type(T) as a type

2020-09-07 Thread Alexander Richardson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9a22eba15091: [clang-format] Parse __underlying_type(T) as a 
type (authored by arichardson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86960

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -169,6 +169,7 @@
   verifyFormat("::ns::SomeFunction(::ns::SomeOtherFunction())");
   verifyFormat("static constexpr bool Bar = decltype(bar())::value;");
   verifyFormat("static constexpr bool Bar = typeof(bar())::value;");
+  verifyFormat("static constexpr bool Bar = __underlying_type(bar())::value;");
   verifyFormat("static constexpr bool Bar = _Atomic(bar())::value;");
   verifyFormat("bool a = 2 < ::SomeFunction();");
   verifyFormat("ALWAYS_INLINE ::std::string getName();");
@@ -7908,6 +7909,7 @@
   verifyFormat("[](const decltype(*a) ) {}");
   verifyFormat("[](const typeof(*a) ) {}");
   verifyFormat("[](const _Atomic(a *) ) {}");
+  verifyFormat("[](const __underlying_type(a) ) {}");
   verifyFormat("decltype(a * b) F();");
   verifyFormat("typeof(a * b) F();");
   verifyFormat("#define MACRO() [](A *a) { return 1; }");
@@ -7977,6 +7979,7 @@
   verifyFormat("[](const decltype(*a)* ptr) {}", Left);
   verifyFormat("[](const typeof(*a)* ptr) {}", Left);
   verifyFormat("[](const _Atomic(a*)* ptr) {}", Left);
+  verifyFormat("[](const __underlying_type(a)* ptr) {}", Left);
   verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left);
   verifyFormat("auto x(A&&, B&&, C&&) -> D;", Left);
   verifyFormat("auto x = [](A&&, B&&, C&&) -> D {};", Left);
@@ -8075,6 +8078,7 @@
   verifyFormat("decltype(*::std::declval()) void F();");
   verifyFormat("typeof(*::std::declval()) void F();");
   verifyFormat("_Atomic(*::std::declval()) void F();");
+  verifyFormat("__underlying_type(*::std::declval()) void F();");
   verifyFormat(
   "template ::value &&\n"
@@ -8101,6 +8105,7 @@
   verifyIndependentOfContext("MACRO(_Atomic(A) *a);");
   verifyIndependentOfContext("MACRO(decltype(A) *a);");
   verifyIndependentOfContext("MACRO(typeof(A) *a);");
+  verifyIndependentOfContext("MACRO(__underlying_type(A) *a);");
   verifyIndependentOfContext("MACRO(A *const a);");
   verifyIndependentOfContext("MACRO(A *restrict a);");
   verifyIndependentOfContext("MACRO(A *__restrict__ a);");
@@ -8655,6 +8660,8 @@
"LooongFunctionDefinition() {}");
   verifyFormat("_Atomic(LongName)\n"
"LooongFunctionDefinition() {}");
+  verifyFormat("__underlying_type(LooongName)\n"
+   "LooongFunctionDefinition() {}");
   verifyFormat("LngReturnType\n"
"LooongFunctionDeclaration(T... t);");
   verifyFormat("LngReturnType\n"
@@ -11600,6 +11607,7 @@
   verifyFormat("auto f(int x) -> decltype(x);", NoSpace);
   verifyFormat("auto f(int x) -> typeof(x);", NoSpace);
   verifyFormat("auto f(int x) -> _Atomic(x);", NoSpace);
+  verifyFormat("auto f(int x) -> __underlying_type(x);", NoSpace);
   verifyFormat("int f(T x) noexcept(x.create());", NoSpace);
   verifyFormat("alignas(128) char a[128];", NoSpace);
   verifyFormat("size_t x = alignof(MyType);", NoSpace);
@@ -11650,6 +11658,7 @@
   verifyFormat("auto f (int x) -> decltype (x);", Space);
   verifyFormat("auto f (int x) -> typeof (x);", Space);
   verifyFormat("auto f (int x) -> _Atomic (x);", Space);
+  verifyFormat("auto f (int x) -> __underlying_type (x);", Space);
   verifyFormat("int f (T x) noexcept (x.create ());", Space);
   verifyFormat("alignas (128) char a[128];", Space);
   verifyFormat("size_t x = alignof (MyType);", Space);
@@ -11704,6 +11713,7 @@
   verifyFormat("auto f (int x) -> decltype (x);", SomeSpace);
   verifyFormat("auto f (int x) -> typeof (x);", SomeSpace);
   verifyFormat("auto f (int x) -> _Atomic (x);", SomeSpace);
+  verifyFormat("auto f (int x) -> __underlying_type (x);", SomeSpace);
   verifyFormat("int f (T x) noexcept (x.create());", SomeSpace);
   verifyFormat("alignas (128) char a[128];", SomeSpace);
   verifyFormat("size_t x = alignof (MyType);", SomeSpace);
@@ -14960,6 +14970,7 @@
"  SomeFunction([](decltype(x), A *a) {});\n"
"  SomeFunction([](typeof(x), A *a) {});\n"
"  SomeFunction([](_Atomic(x), A *a) {});\n"
+   "  SomeFunction([](__underlying_type(x), A *a) {});\n"
"}");
   

[clang] 56fa7d1 - [clang-format] Fix formatting of _Atomic() qualifier

2020-09-07 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2020-09-07T10:09:18+01:00
New Revision: 56fa7d1dc6a8d23111ff84171036f333cf9cddf2

URL: 
https://github.com/llvm/llvm-project/commit/56fa7d1dc6a8d23111ff84171036f333cf9cddf2
DIFF: 
https://github.com/llvm/llvm-project/commit/56fa7d1dc6a8d23111ff84171036f333cf9cddf2.diff

LOG: [clang-format] Fix formatting of _Atomic() qualifier

Before: _Atomic(uint64_t) * a;
After: _Atomic(uint64_t) *a;

This treats _Atomic the same as the the TypenameMacros and decltype. It
also allows some cleanup by removing checks whether the token before a
paren is kw_decltype and instead checking for TT_TypeDeclarationParen.
While touching this code also extend the decltype test cases to also check
for typeof() and _Atomic(T).

Reviewed By: MyDeveloperDay

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

Added: 


Modified: 
clang/lib/Format/FormatToken.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.cpp 
b/clang/lib/Format/FormatToken.cpp
index 4bc865b043fd..8e4994f4c0d5 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -62,6 +62,7 @@ bool FormatToken::isSimpleTypeSpecifier() const {
   case tok::kw_char32_t:
   case tok::kw_typeof:
   case tok::kw_decltype:
+  case tok::kw__Atomic:
 return true;
   default:
 return false;

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index a9aeef5e9e52..8253bf18fc66 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -101,8 +101,8 @@ namespace format {
   TYPE(TrailingAnnotation) 
\
   TYPE(TrailingReturnArrow)
\
   TYPE(TrailingUnaryOperator)  
\
+  TYPE(TypeDeclarationParen)   
\
   TYPE(TypenameMacro)  
\
-  TYPE(TypenameMacroParen) 
\
   TYPE(UnaryOperator)  
\
   TYPE(UntouchableMacroFunc)   
\
   TYPE(CSharpStringLiteral)
\
@@ -526,6 +526,7 @@ struct FormatToken {
 case tok::kw_decltype:
 case tok::kw_noexcept:
 case tok::kw_static_assert:
+case tok::kw__Atomic:
 case tok::kw___attribute:
   return true;
 default:

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 097843bdca84..0239dbd63d94 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -185,6 +185,8 @@ class AnnotatingParser {
 if (!CurrentToken)
   return false;
 FormatToken *Left = CurrentToken->Previous;
+FormatToken *PrevNonComment =
+Left ? Left->getPreviousNonComment() : nullptr;
 Left->ParentBracket = Contexts.back().ContextKind;
 ScopedContextCreator ContextCreator(*this, tok::l_paren, 1);
 
@@ -216,9 +218,8 @@ class AnnotatingParser {
   // export type X = (...);
   Contexts.back().IsExpression = false;
 } else if (Left->Previous &&
-   (Left->Previous->isOneOf(tok::kw_static_assert, 
tok::kw_decltype,
-tok::kw_while, tok::l_paren,
-tok::comma) ||
+   (Left->Previous->isOneOf(tok::kw_static_assert, tok::kw_while,
+tok::l_paren, tok::comma) ||
 Left->Previous->isIf() ||
 Left->Previous->is(TT_BinaryOperator))) {
   // static_assert, if and while usually contain expressions.
@@ -242,10 +243,15 @@ class AnnotatingParser {
 } else if (Contexts[Contexts.size() - 2].CaretFound) {
   // This is the parameter list of an ObjC block.
   Contexts.back().IsExpression = false;
-} else if (Left->Previous && Left->Previous->is(tok::kw___attribute)) {
+} else if (PrevNonComment && PrevNonComment->is(tok::kw___attribute)) {
   Left->setType(TT_AttributeParen);
-} else if (Left->Previous && Left->Previous->is(TT_TypenameMacro)) {
-  Left->setType(TT_TypenameMacroParen);
+} else if (PrevNonComment &&
+   PrevNonComment->isOneOf(TT_TypenameMacro, tok::kw_decltype,
+   tok::kw_typeof, tok::kw__Atomic)) {
+  Left->setType(TT_TypeDeclarationParen);
+  // decltype() and typeof() usually contain expressions.
+  if (PrevNonComment->isOneOf(tok::kw_decltype, tok::kw_typeof))
+Contexts.back().IsExpression = true;
 } else if (Left->Previous && Left->Previous->is(TT_ForEachMacro)) {
   // The 

[PATCH] D87225: [clangd] When finding refs for a template specialization, do not return refs to other specializations

2020-09-07 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.
nridge requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

Fixes https://github.com/clangd/clangd/issues/515


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87225

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1570,7 +1570,7 @@
 
   R"cpp(
template 
-   class [[Foo]] {};
+   class Foo {};
void func([[Fo^o]]);
   )cpp",
   R"cpp(// Not touching any identifiers.
@@ -1582,6 +1582,13 @@
   f.[[^~]]Foo();
 }
   )cpp",
+  R"cpp(// Temlate specialization
+template  class Vector {};
+using [[^X]] = [[Vector]];
+[[X]] x1;
+[[Vector]] x2;
+Vector y;
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -767,7 +767,12 @@
index::IndexDataConsumer::ASTNodeInfo ASTNode) override 
{
 assert(D->isCanonicalDecl() && "expect D to be a canonical declaration");
 const SourceManager  = AST.getSourceManager();
-if (!CanonicalTargets.count(D) || !isInsideMainFile(Loc, SM))
+// For references to template specializations, `D` will contain the
+// template and `ASTNode.OrigD` the specialization. We want to find
+// references to specializations, to check `ASTNode.OrigD` as well.
+bool ReferencesCanonicalTarget =
+CanonicalTargets.count(D) || CanonicalTargets.count(ASTNode.OrigD);
+if (!ReferencesCanonicalTarget || !isInsideMainFile(Loc, SM))
   return true;
 const auto  = AST.getTokens();
 Loc = SM.getFileLoc(Loc);
@@ -1142,7 +1147,7 @@
 
 // We also show references to the targets of using-decls, so we include
 // DeclRelation::Underlying.
-DeclRelationSet Relations = DeclRelation::TemplatePattern |
+DeclRelationSet Relations = DeclRelation::TemplateInstantiation |
 DeclRelation::Alias | DeclRelation::Underlying;
 auto Decls = getDeclAtPosition(AST, *CurLoc, Relations);
 


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1570,7 +1570,7 @@
 
   R"cpp(
template 
-   class [[Foo]] {};
+   class Foo {};
void func([[Fo^o]]);
   )cpp",
   R"cpp(// Not touching any identifiers.
@@ -1582,6 +1582,13 @@
   f.[[^~]]Foo();
 }
   )cpp",
+  R"cpp(// Temlate specialization
+template  class Vector {};
+using [[^X]] = [[Vector]];
+[[X]] x1;
+[[Vector]] x2;
+Vector y;
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -767,7 +767,12 @@
index::IndexDataConsumer::ASTNodeInfo ASTNode) override {
 assert(D->isCanonicalDecl() && "expect D to be a canonical declaration");
 const SourceManager  = AST.getSourceManager();
-if (!CanonicalTargets.count(D) || !isInsideMainFile(Loc, SM))
+// For references to template specializations, `D` will contain the
+// template and `ASTNode.OrigD` the specialization. We want to find
+// references to specializations, to check `ASTNode.OrigD` as well.
+bool ReferencesCanonicalTarget =
+CanonicalTargets.count(D) || CanonicalTargets.count(ASTNode.OrigD);
+if (!ReferencesCanonicalTarget || !isInsideMainFile(Loc, SM))
   return true;
 const auto  = AST.getTokens();
 Loc = SM.getFileLoc(Loc);
@@ -1142,7 +1147,7 @@
 
 // We also show references to the targets of using-decls, so we include
 // DeclRelation::Underlying.
-DeclRelationSet Relations = DeclRelation::TemplatePattern |
+DeclRelationSet Relations = DeclRelation::TemplateInstantiation |
 DeclRelation::Alias | DeclRelation::Underlying;
 auto Decls = getDeclAtPosition(AST, *CurLoc, Relations);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87080: [AST] Reduce the size of TemplateArgumentLocInfo.

2020-09-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/AST/TemplateBase.h:429
+  auto *T = getTemplate();
+  T->Ctx->Deallocate(T);
+}

sammccall wrote:
> sammccall wrote:
> > this is a no-op, and thus not worth stashing a pointer to Ctx for!
> > 
> > It also doesn't delete T, and it's probably best to do that even if it's 
> > (currently) a no-op
> If you're going to destroy T in the destructor, then you can't have trivial 
> copies, as the second one is pointing at deallocated memory.
> (Well, apart from the fact that deallocation does nothing).
> 
> So I think we probably either want:
>  - allocation on ASTContext, trivial copies, no deallocation
>  - allocation on heap, copies reallocate
>  - allocation on heap using shared_ptr
>  - copies disallowed (but I think we rely on them being available)
chose the first one. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87080

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


[clang] b3205e2 - [scan-view] Explicitly use utf-8 in send_string

2020-09-07 Thread via cfe-commits

Author: Tomas Rix
Date: 2020-09-07T09:26:38+02:00
New Revision: b3205e2ace4378600dedba0cc5a42b481c4e22c9

URL: 
https://github.com/llvm/llvm-project/commit/b3205e2ace4378600dedba0cc5a42b481c4e22c9
DIFF: 
https://github.com/llvm/llvm-project/commit/b3205e2ace4378600dedba0cc5a42b481c4e22c9.diff

LOG: [scan-view] Explicitly use utf-8 in send_string

send_patched_file decodes with utf-8.
The default encoder for python 2 is ascii.

So it is necessary to also change send_string to use utf-8.

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

Added: 


Modified: 
clang/tools/scan-view/share/ScanView.py

Removed: 




diff  --git a/clang/tools/scan-view/share/ScanView.py 
b/clang/tools/scan-view/share/ScanView.py
index a6cc7692ffe0..5a5d15e85b30 100644
--- a/clang/tools/scan-view/share/ScanView.py
+++ b/clang/tools/scan-view/share/ScanView.py
@@ -744,7 +744,7 @@ def send_file(self, f, ctype):
 return f
 
 def send_string(self, s, ctype='text/html', headers=True, mtime=None):
-encoded_s = s.encode()
+encoded_s = s.encode('utf-8')
 if headers:
 self.send_response(200)
 self.send_header("Content-type", ctype)



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


[PATCH] D83984: Explicitly use utf-8 in send_string

2020-09-07 Thread serge via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb3205e2ace43: [scan-view] Explicitly use utf-8 in 
send_string (authored by Tomas Rix t...@juniper.net, committed by 
serge-sans-paille).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83984

Files:
  clang/tools/scan-view/share/ScanView.py


Index: clang/tools/scan-view/share/ScanView.py
===
--- clang/tools/scan-view/share/ScanView.py
+++ clang/tools/scan-view/share/ScanView.py
@@ -744,7 +744,7 @@
 return f
 
 def send_string(self, s, ctype='text/html', headers=True, mtime=None):
-encoded_s = s.encode()
+encoded_s = s.encode('utf-8')
 if headers:
 self.send_response(200)
 self.send_header("Content-type", ctype)


Index: clang/tools/scan-view/share/ScanView.py
===
--- clang/tools/scan-view/share/ScanView.py
+++ clang/tools/scan-view/share/ScanView.py
@@ -744,7 +744,7 @@
 return f
 
 def send_string(self, s, ctype='text/html', headers=True, mtime=None):
-encoded_s = s.encode()
+encoded_s = s.encode('utf-8')
 if headers:
 self.send_response(200)
 self.send_header("Content-type", ctype)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83984: Explicitly use utf-8 in send_string

2020-09-07 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

Commited on your behalf using what I expect to be your official email address 
:-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83984

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


[clang] 04ea680 - [cmake] Fix build of attribute plugin example on Windows

2020-09-07 Thread Kristina Bessonova via cfe-commits

Author: Kristina Bessonova
Date: 2020-09-07T10:04:32+02:00
New Revision: 04ea680a8ccc4f9a4d7333cd712333960348c35b

URL: 
https://github.com/llvm/llvm-project/commit/04ea680a8ccc4f9a4d7333cd712333960348c35b
DIFF: 
https://github.com/llvm/llvm-project/commit/04ea680a8ccc4f9a4d7333cd712333960348c35b.diff

LOG: [cmake] Fix build of attribute plugin example on Windows

Seems '${cmake_2_8_12_PRIVATE}' was removed a long time ago, so it should
be just PRIVATE keyword here.

Reviewed By: john.brawn

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

Added: 


Modified: 
clang/examples/Attribute/CMakeLists.txt

Removed: 




diff  --git a/clang/examples/Attribute/CMakeLists.txt 
b/clang/examples/Attribute/CMakeLists.txt
index ed02f5e5992f..42f04f5039bc 100644
--- a/clang/examples/Attribute/CMakeLists.txt
+++ b/clang/examples/Attribute/CMakeLists.txt
@@ -1,7 +1,7 @@
 add_llvm_library(Attribute MODULE Attribute.cpp PLUGIN_TOOL clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
-  target_link_libraries(Attribute ${cmake_2_8_12_PRIVATE}
+  target_link_libraries(Attribute PRIVATE
 clangAST
 clangBasic
 clangFrontend



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


[PATCH] D77491: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2020-09-07 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Headers/intrin.h:435
 #if defined(__i386__) || defined(__x86_64__)
-static __inline__ void __DEFAULT_FN_ATTRS
-__movsb(unsigned char *__dst, unsigned char const *__src, size_t __n) {
+void __DEFAULT_FN_ATTRS __movsb(unsigned char *__dst,
+unsigned char const *__src, size_t __n) {

The functions with inline definitions should still be `static inline` so that 
we don't emit them as strong external defintiions.



Comment at: clang/lib/Sema/SemaDecl.cpp:9672-9673
+  if (unsigned BuiltinID = II->getBuiltinID()) {
+const auto *LinkageDecl =
+dyn_cast(NewFD->getDeclContext());
+

This will give the wrong answer for
```
extern "C" {
namespace X {
void __builtin_foo();
}
}
```
... which does have C language linkage. Instead, please call 
`FunctionDecl::getLanguageLinkage()`, which knows how to handle these cases.



Comment at: clang/lib/Sema/SemaDecl.cpp:9690-9691
+if (!Error && !BuiltinType.isNull()) {
+  // We want noexcept declarations to match. Create an identical
+  // function type, but remove the exception spec.
+  const FunctionProtoType *Type =

Please use `ASTContext::hasSameTypeIgnoringExceptionSpec` instead.



Comment at: clang/lib/Serialization/ASTReader.cpp:914
+  return II.hadMacroDefinition() || II.isPoisoned() ||
+ II.getObjCOrBuiltinID() || II.hasRevertedTokenIDToIdentifier() ||
  (!(IsModule && Reader.getPreprocessor().getLangOpts().CPlusPlus) &&

We now consider `getObjCOrBuiltinID()` here for the `IsModule` case, where we 
didn't before. Is that an intentional change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491

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


[PATCH] D87081: [analyzer][StdLibraryFunctionsChecker] Elaborate the summary of fread and fwrite

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

The patch looks great, in fact, it demonstrates how well thought out your 
summary crafting machinery is.

In D87081#2258579 , @martong wrote:

> However, in a similar case with the CallAndMessage Checker, we decided to 
> list the more specific Checker as a dependency.

We got the answer to D77061#2057063 ! 
We should turn it into a weak dependency though (D80905 
).

In D87081#2256636 , @balazske wrote:

> This checker will make an additional assumption on `fread` and `fwrite` with 
> the ReturnValueCondition. The return value is constrained by `StreamChecker` 
> too but it splits the error (if returned value is less that arg 3) and 
> non-error cases into separate branches. I think this causes no problem 
> because it will refine the assumption made here (if this assumption is made 
> first) or the assumption here has no effect (if the split happened already).

Be sure to triple check whether the `ExplodedGraph` looks okay with both 
checkers enabled.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87081

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


[PATCH] D87028: [clang-format] Improve heuristic for detecting function declarations

2020-09-07 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Thanks for the patch, I think this looks like a comprehensive improvement, a 
new nits only




Comment at: clang/lib/Format/TokenAnnotator.cpp:2427
+  // inside a function this should always be treated as a variable.
+  return CouldBeTypeList && Line.Level == 0;
 }

how hard would it be to do the TODO?



Comment at: clang/unittests/Format/FormatTest.cpp:5507
+  Google);
   verifyGoogleFormat(
   "bool aa GUARDED_BY() =\n"

I want to approve this change, but I HATE changing unit tests (Beyonce rule), 
I'm struggling to see if we are changing anything here? or if you are just 
qualifying it a little better because the usage is different depending on where 
its used  (as a function,as a variable)




Comment at: clang/unittests/Format/FormatTest.cpp:6715
+   "funcdecl(SomeType param1, OtherType param2);\n"
+   // Also handle parameter lists declaration without names (but
+   // only at the top level, not inside functions

if you have to put a comment in the test then you probably should have broken 
the verifyFormat



Comment at: clang/unittests/Format/FormatTest.cpp:6730
+   "SomeType x = var * funcdecl(var, otherVar);\n"
+   "void\n"
+   "function_scope() {\n"

break it here



Comment at: clang/unittests/Format/FormatTest.cpp:6740
+   "  SomeType *funcdecl(SomeType, OtherType);\n"
+   "}\n"
+   "namespace namspace_scope {\n"

break it here.



Comment at: clang/unittests/Format/FormatTest.cpp:6762
+   "} // namespace namspace_scope\n",
+   Style);
   verifyFormat("class E {\n"

Nit that is a mother of an assert, but when it fails.. how easy is it going to 
be to debug where it goes wrong exactly.

Could we break it up a little?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87028

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


[PATCH] D87118: Add an explicit toggle for the static analyzer in clang-tidy

2020-09-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Cool!




Comment at: clang-tools-extra/CMakeLists.txt:4
+option(CLANG_TIDY_ENABLE_STATIC_ANALYZER
+  "Include static analyzer checks in clang-tidy" ON)
+

Should this default to CLANG_ENABLE_STATIC_ANALYZER instead of ON?



Comment at: clang/lib/CMakeLists.txt:24
 add_subdirectory(IndexSerialization)
-if(CLANG_ENABLE_STATIC_ANALYZER)
-  add_subdirectory(StaticAnalyzer)

Why does removing the condition here work?



Comment at: llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/BUILD.gn:18
+  } else {
+values += [ "CLANG_TIDY_ENABLE_STATIC_ANALYZER=" ]
+  }

Why not =0?


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

https://reviews.llvm.org/D87118

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


[PATCH] D87201: [clang-format] Add a option for the position of Java static import

2020-09-07 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay requested changes to this revision.
MyDeveloperDay added a comment.
This revision now requires changes to proceed.

Thanks for the patch, You need to generate a fill context diff (see 
Contributing to LLVM)

ensure the diff is clang-formatted itself (can't quite tell if it is or not)




Comment at: clang/docs/ClangFormatStyleOptions.rst:2027
+
+ .. code-block:: java
+ true:

The ClangFormatStyleOptions.rst is generated using 
doc/tools/dump_format_style.py which reads Format.h and generates this,

If this code block in not in the Format.h it will get removed the next time the 
script is run, please don't change ClangFormatStyleOption.rst by hand use the 
script, so add the code block to the Format.h file (see others options for now 
to do this)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87201

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


[PATCH] D87028: [clang-format] Improve heuristic for detecting function declarations

2020-09-07 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2427
+  // inside a function this should always be treated as a variable.
+  return CouldBeTypeList && Line.Level == 0;
 }

MyDeveloperDay wrote:
> how hard would it be to do the TODO?
I am not that familiar with the clang-format codebase yet, but it appears to me 
that this information is not tracked at all. It should be quite easy to add 
another `Scope` (or similar) member that is an enum for 
global/function/namespace/class/other and then update that in all cases that 
also change the level member.



Comment at: clang/unittests/Format/FormatTest.cpp:5507
+  Google);
   verifyGoogleFormat(
   "bool aa GUARDED_BY() =\n"

MyDeveloperDay wrote:
> I want to approve this change, but I HATE changing unit tests (Beyonce rule), 
> I'm struggling to see if we are changing anything here? or if you are just 
> qualifying it a little better because the usage is different depending on 
> where its used  (as a function,as a variable)
> 
Before a non-empty `()` with a single indentifier inside was always treated as 
a variable, with this change it's (in this case incorrectly) parsed as function.



Comment at: clang/unittests/Format/FormatTest.cpp:6762
+   "} // namespace namspace_scope\n",
+   Style);
   verifyFormat("class E {\n"

MyDeveloperDay wrote:
> Nit that is a mother of an assert, but when it fails.. how easy is it going 
> to be to debug where it goes wrong exactly.
> 
> Could we break it up a little?
`I agree this is too long. I was just trying to avoid repeating the `namespace 
{}/void fn()` prefix. Will try to break it up for next version of this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87028

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


[PATCH] D86699: [SyntaxTree] Ignore implicit non-leaf `CXXConstructExpr`

2020-09-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 290223.
eduucaldas added a comment.

Add more tests, not extract `IgnoreImplicitConstructorSingleStep`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86699

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp

Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -1745,19 +1745,15 @@
 struct X {
   friend X operator+(X, const X&);
 };
-// FIXME: Remove additional `UnknownExpression` wrapping `x`. For that, ignore
-// implicit copy constructor called on `x`. This should've been ignored already,
-// as we `IgnoreImplicit` when traversing an `Stmt`.
 void test(X x, X y) {
   [[x + y]];
 }
 )cpp",
   {R"txt(
 BinaryOperatorExpression Expression
-|-UnknownExpression LeftHandSide
-| `-IdExpression
-|   `-UnqualifiedId UnqualifiedId
-| `-'x'
+|-IdExpression LeftHandSide
+| `-UnqualifiedId UnqualifiedId
+|   `-'x'
 |-'+' OperatorToken
 `-IdExpression RightHandSide
   `-UnqualifiedId UnqualifiedId
@@ -3821,26 +3817,135 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, InitDeclarator_Equal) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S { S(int);};
+void test() {
+  [[S s = 1]];
+}
+)cpp",
+  {R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s'
+  |-'='
+  `-IntegerLiteralExpression
+`-'1' LiteralToken
+)txt"}));
+}
+
 TEST_P(SyntaxTreeTest, InitDeclarator_Brace) {
   if (!GetParam().isCXX11OrLater()) {
 return;
   }
-  EXPECT_TRUE(treeDumpEqual(
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
   R"cpp(
-int a {};
+struct S { 
+  S();
+  S(int);
+  S(int, float);
+};
+void test(){
+  [[S s0{}]];
+  [[S s1{1}]];
+  [[S s2{1, 2.}]];
+}
 )cpp",
-  R"txt(
-TranslationUnit Detached
-`-SimpleDeclaration
-  |-'int'
-  |-SimpleDeclarator Declarator
-  | |-'a'
-  | `-UnknownExpression
-  |   `-UnknownExpression
-  | |-'{'
-  | `-'}'
-  `-';'
-)txt"));
+  {R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  `-UnknownExpression
+|-'s0'
+|-'{'
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  `-UnknownExpression
+|-'s1'
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  `-UnknownExpression
+|-'s2'
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+|-','
+|-FloatingLiteralExpression
+| `-'2.' LiteralToken
+`-'}'
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, InitDeclarator_EqualBrace) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S { 
+  S();
+  S(int);
+  S(int, float);
+};
+void test() {
+  [[S s0 = {}]];
+  [[S s1 = {1}]];
+  [[S s2 = {1, 2.}]];
+}
+)cpp",
+  {R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s0'
+  |-'='
+  `-UnknownExpression
+|-'{'
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s1'
+  |-'='
+  `-UnknownExpression
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s2'
+  |-'='
+  `-UnknownExpression
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+|-','
+|-FloatingLiteralExpression
+| `-'2.' LiteralToken
+`-'}'
+)txt"}));
 }
 
 TEST_P(SyntaxTreeTest, InitDeclarator_Paren) {
@@ -3851,15 +3956,132 @@
   R"cpp(
 struct S {
   S(int);
+  S(int, float);
 };
-[[S s(1);]]
+[[S s1(1);]]
+[[S s2(1, 2.);]]
 )cpp",
   {R"txt(
 SimpleDeclaration
 |-'S'
 |-SimpleDeclarator Declarator
 | `-UnknownExpression
-|   |-'s'
+|   |-'s1'
+|   |-'('
+|   |-IntegerLiteralExpression
+|   | `-'1' LiteralToken
+|   `-')'
+`-';'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+|-SimpleDeclarator Declarator
+| `-UnknownExpression
+|   |-'s2'
+|   |-'('
+|   |-IntegerLiteralExpression
+|   | `-'1' LiteralToken
+|   |-','
+|   |-FloatingLiteralExpression
+|   | `-'2.' LiteralToken
+|   `-')'
+`-';'
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, ImplicitConversion_Argument) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct X {
+  X(int);
+};
+void TakeX(const X&);
+void test() {
+  [[TakeX(1)]];
+}
+)cpp",
+  {R"txt(
+CallExpression Expression
+|-IdExpression Callee
+| `-UnqualifiedId UnqualifiedId
+|   `-'TakeX'
+|-'(' OpenParen
+|-CallArguments Arguments
+| `-IntegerLiteralExpression ListElement
+|   `-'1' LiteralToken
+`-')' CloseParen
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, 

[PATCH] D86699: [SyntaxTree] Ignore implicit non-leaf `CXXConstructExpr`

2020-09-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 290227.
eduucaldas added a comment.

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86699

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp

Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -1745,19 +1745,15 @@
 struct X {
   friend X operator+(X, const X&);
 };
-// FIXME: Remove additional `UnknownExpression` wrapping `x`. For that, ignore
-// implicit copy constructor called on `x`. This should've been ignored already,
-// as we `IgnoreImplicit` when traversing an `Stmt`.
 void test(X x, X y) {
   [[x + y]];
 }
 )cpp",
   {R"txt(
 BinaryOperatorExpression Expression
-|-UnknownExpression LeftHandSide
-| `-IdExpression
-|   `-UnqualifiedId UnqualifiedId
-| `-'x'
+|-IdExpression LeftHandSide
+| `-UnqualifiedId UnqualifiedId
+|   `-'x'
 |-'+' OperatorToken
 `-IdExpression RightHandSide
   `-UnqualifiedId UnqualifiedId
@@ -3821,26 +3817,135 @@
 )txt"));
 }
 
+TEST_P(SyntaxTreeTest, InitDeclarator_Equal) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S { S(int);};
+void test() {
+  [[S s = 1]];
+}
+)cpp",
+  {R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s'
+  |-'='
+  `-IntegerLiteralExpression
+`-'1' LiteralToken
+)txt"}));
+}
+
 TEST_P(SyntaxTreeTest, InitDeclarator_Brace) {
   if (!GetParam().isCXX11OrLater()) {
 return;
   }
-  EXPECT_TRUE(treeDumpEqual(
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
   R"cpp(
-int a {};
+struct S { 
+  S();
+  S(int);
+  S(int, float);
+};
+void test(){
+  [[S s0{}]];
+  [[S s1{1}]];
+  [[S s2{1, 2.}]];
+}
 )cpp",
-  R"txt(
-TranslationUnit Detached
-`-SimpleDeclaration
-  |-'int'
-  |-SimpleDeclarator Declarator
-  | |-'a'
-  | `-UnknownExpression
-  |   `-UnknownExpression
-  | |-'{'
-  | `-'}'
-  `-';'
-)txt"));
+  {R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  `-UnknownExpression
+|-'s0'
+|-'{'
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  `-UnknownExpression
+|-'s1'
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  `-UnknownExpression
+|-'s2'
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+|-','
+|-FloatingLiteralExpression
+| `-'2.' LiteralToken
+`-'}'
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, InitDeclarator_EqualBrace) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct S { 
+  S();
+  S(int);
+  S(int, float);
+};
+void test() {
+  [[S s0 = {}]];
+  [[S s1 = {1}]];
+  [[S s2 = {1, 2.}]];
+}
+)cpp",
+  {R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s0'
+  |-'='
+  `-UnknownExpression
+|-'{'
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s1'
+  |-'='
+  `-UnknownExpression
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+`-'}'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+`-SimpleDeclarator Declarator
+  |-'s2'
+  |-'='
+  `-UnknownExpression
+|-'{'
+|-IntegerLiteralExpression
+| `-'1' LiteralToken
+|-','
+|-FloatingLiteralExpression
+| `-'2.' LiteralToken
+`-'}'
+)txt"}));
 }
 
 TEST_P(SyntaxTreeTest, InitDeclarator_Paren) {
@@ -3851,15 +3956,133 @@
   R"cpp(
 struct S {
   S(int);
+  S(int, float);
 };
-[[S s(1);]]
+[[S s1(1);]]
+[[S s2(1, 2.);]]
 )cpp",
   {R"txt(
 SimpleDeclaration
 |-'S'
 |-SimpleDeclarator Declarator
 | `-UnknownExpression
-|   |-'s'
+|   |-'s1'
+|   |-'('
+|   |-IntegerLiteralExpression
+|   | `-'1' LiteralToken
+|   `-')'
+`-';'
+  )txt",
+   R"txt(
+SimpleDeclaration
+|-'S'
+|-SimpleDeclarator Declarator
+| `-UnknownExpression
+|   |-'s2'
+|   |-'('
+|   |-IntegerLiteralExpression
+|   | `-'1' LiteralToken
+|   |-','
+|   |-FloatingLiteralExpression
+|   | `-'2.' LiteralToken
+|   `-')'
+`-';'
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, ImplicitConversion_Argument) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(treeDumpEqualOnAnnotations(
+  R"cpp(
+struct X {
+  X(int);
+};
+void TakeX(const X&);
+void test() {
+  [[TakeX(1)]];
+}
+)cpp",
+  {R"txt(
+CallExpression Expression
+|-IdExpression Callee
+| `-UnqualifiedId UnqualifiedId
+|   `-'TakeX'
+|-'(' OpenParen
+|-CallArguments Arguments
+| `-IntegerLiteralExpression ListElement
+|   `-'1' LiteralToken
+`-')' CloseParen
+)txt"}));
+}
+
+TEST_P(SyntaxTreeTest, ImplicitConversion_Return) {
+  if (!GetParam().isCXX()) {
+

[PATCH] D86700: [SyntaxTree] Ignore leaf implicit `CXXConstructExpr`

2020-09-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 290228.
eduucaldas added a comment.

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86700

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp


Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -548,9 +548,6 @@
   struct S { };
 }
 void test() {
-  // FIXME: Remove the `UnknownExpression` wrapping `s1` and `s2`. This
-  // `UnknownExpression` comes from a leaf `CXXConstructExpr` in the
-  // ClangAST. We need to ignore leaf implicit nodes.
   [[::n::S s1]];
   [[n::S s2]];
 }
@@ -564,8 +561,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s1'
+  `-'s1'
 )txt",
R"txt(
 SimpleDeclaration
@@ -575,8 +571,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s2'
+  `-'s2'
 )txt"}));
 }
 
@@ -608,8 +603,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s1'
+  `-'s1'
 )txt",
R"txt(
 SimpleDeclaration
@@ -623,8 +617,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s2'
+  `-'s2'
 )txt"}));
 }
 
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1129,6 +1129,12 @@
 return true;
   }
 
+  bool WalkUpFromCXXConstructExpr(CXXConstructExpr *S) {
+if (S->getParenOrBraceRange().isInvalid())
+  return true;
+return RecursiveASTVisitor::WalkUpFromCXXConstructExpr(S);
+  }
+
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
 // To construct a syntax tree of the same shape for calls to built-in and
 // user-defined operators, ignore the `DeclRefExpr` that refers to the


Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -548,9 +548,6 @@
   struct S { };
 }
 void test() {
-  // FIXME: Remove the `UnknownExpression` wrapping `s1` and `s2`. This
-  // `UnknownExpression` comes from a leaf `CXXConstructExpr` in the
-  // ClangAST. We need to ignore leaf implicit nodes.
   [[::n::S s1]];
   [[n::S s2]];
 }
@@ -564,8 +561,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s1'
+  `-'s1'
 )txt",
R"txt(
 SimpleDeclaration
@@ -575,8 +571,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s2'
+  `-'s2'
 )txt"}));
 }
 
@@ -608,8 +603,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s1'
+  `-'s1'
 )txt",
R"txt(
 SimpleDeclaration
@@ -623,8 +617,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s2'
+  `-'s2'
 )txt"}));
 }
 
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1129,6 +1129,12 @@
 return true;
   }
 
+  bool WalkUpFromCXXConstructExpr(CXXConstructExpr *S) {
+if (S->getParenOrBraceRange().isInvalid())
+  return true;
+return RecursiveASTVisitor::WalkUpFromCXXConstructExpr(S);
+  }
+
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
 // To construct a syntax tree of the same shape for calls to built-in and
 // user-defined operators, ignore the `DeclRefExpr` that refers to the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84415: [analyzer][StdLibraryFunctionsChecker] Add POSIX pthread handling functions

2020-09-07 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko accepted this revision.
vsavchenko added a comment.

LGTM!
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84415

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


[PATCH] D85424: [Analyzer] Crash fix for alpha.cplusplus.IteratorRange

2020-09-07 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

OK, after a few hours of debugging, the test code simplifies to this:

  // RUN: %clang_analyze_cc1 -std=c++11 
-analyzer-checker=core,cplusplus,alpha.cplusplus.IteratorRange -analyzer-config 
aggressive-binary-operation-simplification=true %s -verify
  
  void foo(int x) {
int uninit;
x - uninit; // will-crash
  }

The investigation showed that the 
`IteratorRangeChecker::verifyRandomIncrOrDecr` will get an `Undefined` sval for 
this example, resulting in a crash.
How should I continue this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85424

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


[PATCH] D76590: [Analyzer] Model `empty()` member function of containers

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

I'm in favor of most, if not all of the changes, though I will admit that this 
patch seems pretty cluttered, you are doing a lot of refactoring under the same 
hood. You're moving, adding, removing and changing helper functions and their 
invocations. Would be possible to make this patch a bit leaner?




Comment at: clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp:36
+  void handleAssignment(CheckerContext , const Expr *CE, SVal Cont,
+Optional = None) const;
+

Hmm, this was changed to an optional, unnamed parameter without docs... Might 
be a bit cryptic :) Also, this seems to be orthogonal to the patch, is it not? 
Does the modeling of `empty()` change something that affects this function?



Comment at: clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp:420
+
+  // We cannot make assumpotions on `UnknownVal`. Let us conjure a symbol
+  // instead.

assumpotions > assumptions



Comment at: clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp:420-427
+  // We cannot make assumpotions on `UnknownVal`. Let us conjure a symbol
+  // instead.
+  if (RetVal.isUnknown()) {
+auto  = C.getSymbolManager();
+RetVal = nonloc::SymbolVal(SymMgr.conjureSymbol(
+CE, LCtx, C.getASTContext().BoolTy, C.blockCount()));
+State = State->BindExpr(CE, LCtx, RetVal);

Szelethus wrote:
> assumpotions > assumptions
You will have to help me out here -- if the analyzer couldn't return a sensible 
symbol, is it okay to just create one? When does `UnknownVal` even happen, does 
it ever happen? Also, if we're doing this anyways, wouldn't using `evalCall` be 
more appropriate?



Comment at: 
clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp:71
+
+  EXPECT_TRUE(runCheckerOnCode(
+  R"(class C {

Did you mean to upload changed to this file from D85351 to this patch as well?


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

https://reviews.llvm.org/D76590

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


[PATCH] D86778: Extract infrastructure to ignore intermediate expressions into `clang/AST/IgnoreExpr.h`

2020-09-07 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG81aa66f65f50: Extract infrastructure to ignore intermediate 
expressions into… (authored by eduucaldas).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86778

Files:
  clang/include/clang/AST/IgnoreExpr.h
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Expr.cpp
  clang/lib/AST/IgnoreExpr.cpp

Index: clang/lib/AST/IgnoreExpr.cpp
===
--- /dev/null
+++ clang/lib/AST/IgnoreExpr.cpp
@@ -0,0 +1,129 @@
+//===--- IgnoreExpr.cpp - Ignore intermediate Expressions -===//
+//
+// 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
+//
+//===--===//
+//
+// This file implements common functions to ignore intermediate expression nodes
+//
+//===--===//
+
+#include "clang/AST/IgnoreExpr.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
+
+using namespace clang;
+
+Expr *clang::IgnoreImplicitCastsSingleStep(Expr *E) {
+  if (auto *ICE = dyn_cast(E))
+return ICE->getSubExpr();
+
+  if (auto *FE = dyn_cast(E))
+return FE->getSubExpr();
+
+  return E;
+}
+
+Expr *clang::IgnoreImplicitCastsExtraSingleStep(Expr *E) {
+  // FIXME: Skip MaterializeTemporaryExpr and SubstNonTypeTemplateParmExpr in
+  // addition to what IgnoreImpCasts() skips to account for the current
+  // behaviour of IgnoreParenImpCasts().
+  Expr *SubE = IgnoreImplicitCastsSingleStep(E);
+  if (SubE != E)
+return SubE;
+
+  if (auto *MTE = dyn_cast(E))
+return MTE->getSubExpr();
+
+  if (auto *NTTP = dyn_cast(E))
+return NTTP->getReplacement();
+
+  return E;
+}
+
+Expr *clang::IgnoreCastsSingleStep(Expr *E) {
+  if (auto *CE = dyn_cast(E))
+return CE->getSubExpr();
+
+  if (auto *FE = dyn_cast(E))
+return FE->getSubExpr();
+
+  if (auto *MTE = dyn_cast(E))
+return MTE->getSubExpr();
+
+  if (auto *NTTP = dyn_cast(E))
+return NTTP->getReplacement();
+
+  return E;
+}
+
+Expr *clang::IgnoreLValueCastsSingleStep(Expr *E) {
+  // Skip what IgnoreCastsSingleStep skips, except that only
+  // lvalue-to-rvalue casts are skipped.
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() != CK_LValueToRValue)
+  return E;
+
+  return IgnoreCastsSingleStep(E);
+}
+
+Expr *clang::IgnoreBaseCastsSingleStep(Expr *E) {
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_DerivedToBase ||
+CE->getCastKind() == CK_UncheckedDerivedToBase ||
+CE->getCastKind() == CK_NoOp)
+  return CE->getSubExpr();
+
+  return E;
+}
+
+Expr *clang::IgnoreImplicitSingleStep(Expr *E) {
+  Expr *SubE = IgnoreImplicitCastsSingleStep(E);
+  if (SubE != E)
+return SubE;
+
+  if (auto *MTE = dyn_cast(E))
+return MTE->getSubExpr();
+
+  if (auto *BTE = dyn_cast(E))
+return BTE->getSubExpr();
+
+  return E;
+}
+
+Expr *clang::IgnoreImplicitAsWrittenSingleStep(Expr *E) {
+  if (auto *ICE = dyn_cast(E))
+return ICE->getSubExprAsWritten();
+
+  return IgnoreImplicitSingleStep(E);
+}
+
+Expr *clang::IgnoreParensOnlySingleStep(Expr *E) {
+  if (auto *PE = dyn_cast(E))
+return PE->getSubExpr();
+  return E;
+}
+
+Expr *clang::IgnoreParensSingleStep(Expr *E) {
+  if (auto *PE = dyn_cast(E))
+return PE->getSubExpr();
+
+  if (auto *UO = dyn_cast(E)) {
+if (UO->getOpcode() == UO_Extension)
+  return UO->getSubExpr();
+  }
+
+  else if (auto *GSE = dyn_cast(E)) {
+if (!GSE->isResultDependent())
+  return GSE->getResultExpr();
+  }
+
+  else if (auto *CE = dyn_cast(E)) {
+if (!CE->isConditionDependent())
+  return CE->getChosenSubExpr();
+  }
+
+  return E;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -21,6 +21,7 @@
 #include "clang/AST/DependenceFlags.h"
 #include "clang/AST/EvaluatedExprVisitor.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/IgnoreExpr.h"
 #include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtVisitor.h"
@@ -2779,118 +2780,6 @@
   return QualType();
 }
 
-static Expr *IgnoreImpCastsSingleStep(Expr *E) {
-  if (auto *ICE = dyn_cast(E))
-return ICE->getSubExpr();
-
-  if (auto *FE = dyn_cast(E))
-return FE->getSubExpr();
-
-  return E;
-}
-
-static Expr *IgnoreImpCastsExtraSingleStep(Expr *E) {
-  // FIXME: Skip MaterializeTemporaryExpr and SubstNonTypeTemplateParmExpr in
-  // addition to what IgnoreImpCasts() skips to account for the current
-  // behaviour of IgnoreParenImpCasts().
-  Expr *SubE = IgnoreImpCastsSingleStep(E);
-  if (SubE != E)
-return SubE;
-
-  

[clang-tools-extra] 1a7a2cd - [Ignore Expressions][NFC] Refactor to better use `IgnoreExpr.h` and nits

2020-09-07 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-09-07T09:32:30Z
New Revision: 1a7a2cd7474e6d321120ffe7ca9c52163eb228f0

URL: 
https://github.com/llvm/llvm-project/commit/1a7a2cd7474e6d321120ffe7ca9c52163eb228f0
DIFF: 
https://github.com/llvm/llvm-project/commit/1a7a2cd7474e6d321120ffe7ca9c52163eb228f0.diff

LOG: [Ignore Expressions][NFC] Refactor to better use `IgnoreExpr.h` and nits

This change groups
* Rename: `ignoreParenBaseCasts` -> `IgnoreParenBaseCasts` for uniformity
* Rename: `IgnoreConversionOperator` -> `IgnoreConversionOperatorSingleStep` 
for uniformity
* Inline `IgnoreNoopCastsSingleStep` into a lambda inside `IgnoreNoopCasts`
* Refactor `IgnoreUnlessSpelledInSource` to make adequate use of 
`IgnoreExprNodes`

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
clang/include/clang/AST/Expr.h
clang/lib/AST/Expr.cpp
clang/lib/CodeGen/CGExprCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/StaticAnalyzer/Core/CallEvent.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
index 04dc61f02df1..44ae380b63b2 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
@@ -338,7 +338,7 @@ void UseAutoCheck::replaceIterators(const DeclStmt *D, 
ASTContext *Context) {
 
 // Drill down to the as-written initializer.
 const Expr *E = (*Construct->arg_begin())->IgnoreParenImpCasts();
-if (E != E->IgnoreConversionOperator()) {
+if (E != E->IgnoreConversionOperatorSingleStep()) {
   // We hit a conversion operator. Early-out now as they imply an implicit
   // conversion from a 
diff erent type. Could also mean an explicit
   // conversion from the same type but that's pretty rare.

diff  --git 
a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index 9dcb10b9d20c..7e8ba4eb90c6 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -205,7 +205,7 @@ std::string compareExpressionToZero(const 
MatchFinder::MatchResult ,
 
 std::string replacementExpression(const MatchFinder::MatchResult ,
   bool Negated, const Expr *E) {
-  E = E->ignoreParenBaseCasts();
+  E = E->IgnoreParenBaseCasts();
   if (const auto *EC = dyn_cast(E))
 E = EC->getSubExpr();
 

diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 5edca2593789..26e52ad367f8 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -867,9 +867,9 @@ class Expr : public ValueStmt {
 
   /// Skip conversion operators. If this Expr is a call to a conversion
   /// operator, return the argument.
-  Expr *IgnoreConversionOperator() LLVM_READONLY;
-  const Expr *IgnoreConversionOperator() const {
-return const_cast(this)->IgnoreConversionOperator();
+  Expr *IgnoreConversionOperatorSingleStep() LLVM_READONLY;
+  const Expr *IgnoreConversionOperatorSingleStep() const {
+return const_cast(this)->IgnoreConversionOperatorSingleStep();
   }
 
   /// Skip past any parentheses and lvalue casts which might surround this
@@ -901,9 +901,9 @@ class Expr : public ValueStmt {
   /// * What IgnoreParens() skips
   /// * CastExpr which represent a derived-to-base cast (CK_DerivedToBase,
   ///   CK_UncheckedDerivedToBase and CK_NoOp)
-  Expr *ignoreParenBaseCasts() LLVM_READONLY;
-  const Expr *ignoreParenBaseCasts() const {
-return const_cast(this)->ignoreParenBaseCasts();
+  Expr *IgnoreParenBaseCasts() LLVM_READONLY;
+  const Expr *IgnoreParenBaseCasts() const {
+return const_cast(this)->IgnoreParenBaseCasts();
   }
 
   /// Determine whether this expression is a default function argument.

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 1029acbf68cd..15f3df0fd216 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -40,7 +40,7 @@ using namespace clang;
 const Expr *Expr::getBestDynamicClassTypeExpr() const {
   const Expr *E = this;
   while (true) {
-E = E->ignoreParenBaseCasts();
+E = E->IgnoreParenBaseCasts();
 
 // Follow the RHS of a comma operator.
 if (auto *BO = dyn_cast(E)) {
@@ -2780,29 +2780,6 @@ QualType Expr::findBoundMemberType(const Expr *expr) {
   return QualType();
 }
 
-static Expr *IgnoreNoopCastsSingleStep(const ASTContext , Expr *E) {
-  if (auto *CE = dyn_cast(E)) {
-// We ignore integer <-> casts that are of the same width, ptr<->ptr and
-// ptr<->int casts of the same width. We also ignore all identity casts.
-Expr *SubExpr = CE->getSubExpr();
-

[clang] 81aa66f - Extract infrastructure to ignore intermediate expressions into `clang/AST/IgnoreExpr.h`

2020-09-07 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-09-07T09:32:30Z
New Revision: 81aa66f65f504af18982baa078a5f3f7d2aa88fa

URL: 
https://github.com/llvm/llvm-project/commit/81aa66f65f504af18982baa078a5f3f7d2aa88fa
DIFF: 
https://github.com/llvm/llvm-project/commit/81aa66f65f504af18982baa078a5f3f7d2aa88fa.diff

LOG: Extract infrastructure to ignore intermediate expressions into 
`clang/AST/IgnoreExpr.h`

Rationale:
This allows users to use `IgnoreExprNodes` and `Ignore*SingleStep` outside of
`clang/AST/Expr.cpp`.

Minor:
Rename `IgnoreImp...SingleStep`  into `IgnoreImplicit...SingleStep`.

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

Added: 
clang/include/clang/AST/IgnoreExpr.h
clang/lib/AST/IgnoreExpr.cpp

Modified: 
clang/lib/AST/CMakeLists.txt
clang/lib/AST/Expr.cpp

Removed: 




diff  --git a/clang/include/clang/AST/IgnoreExpr.h 
b/clang/include/clang/AST/IgnoreExpr.h
new file mode 100644
index ..15d31f3af995
--- /dev/null
+++ b/clang/include/clang/AST/IgnoreExpr.h
@@ -0,0 +1,61 @@
+//===--- IgnoreExpr.h - Ignore intermediate Expressions -===//
+//
+// 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
+//
+//===--===//
+//
+// This file defines common functions to ignore intermediate expression nodes
+//
+//===--===//
+
+#ifndef LLVM_CLANG_AST_IGNOREEXPR_H
+#define LLVM_CLANG_AST_IGNOREEXPR_H
+
+#include "clang/AST/Expr.h"
+
+namespace clang {
+namespace detail {
+/// Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *,
+/// Return Fn_n(...(Fn_1(E)))
+inline Expr *IgnoreExprNodesImpl(Expr *E) { return E; };
+template 
+Expr *IgnoreExprNodesImpl(Expr *E, FnTy &, FnTys &&... Fns) {
+  return IgnoreExprNodesImpl(Fn(E), std::forward(Fns)...);
+}
+} // namespace detail
+
+/// Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *,
+/// Recursively apply each of the functions to E until reaching a fixed point.
+/// Note that a null E is valid; in this case nothing is done.
+template  Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
+  Expr *LastE = nullptr;
+  while (E != LastE) {
+LastE = E;
+E = detail::IgnoreExprNodesImpl(E, std::forward(Fns)...);
+  }
+  return E;
+}
+
+Expr *IgnoreImplicitCastsSingleStep(Expr *E);
+
+Expr *IgnoreImplicitCastsExtraSingleStep(Expr *E);
+
+Expr *IgnoreCastsSingleStep(Expr *E);
+
+Expr *IgnoreLValueCastsSingleStep(Expr *E);
+
+Expr *IgnoreBaseCastsSingleStep(Expr *E);
+
+Expr *IgnoreImplicitSingleStep(Expr *E);
+
+Expr *IgnoreImplicitAsWrittenSingleStep(Expr *E);
+
+Expr *IgnoreParensOnlySingleStep(Expr *E);
+
+Expr *IgnoreParensSingleStep(Expr *E);
+
+} // namespace clang
+
+#endif // LLVM_CLANG_AST_IGNOREEXPR_H

diff  --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index 35099fd0dacf..dfd26fd97bc6 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -55,6 +55,7 @@ add_clang_library(clangAST
   ExternalASTMerger.cpp
   ExternalASTSource.cpp
   FormatString.cpp
+  IgnoreExpr.cpp
   InheritViz.cpp
   Interp/ByteCodeEmitter.cpp
   Interp/ByteCodeExprGen.cpp

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 8efd6837c541..1029acbf68cd 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -21,6 +21,7 @@
 #include "clang/AST/DependenceFlags.h"
 #include "clang/AST/EvaluatedExprVisitor.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/IgnoreExpr.h"
 #include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtVisitor.h"
@@ -2779,118 +2780,6 @@ QualType Expr::findBoundMemberType(const Expr *expr) {
   return QualType();
 }
 
-static Expr *IgnoreImpCastsSingleStep(Expr *E) {
-  if (auto *ICE = dyn_cast(E))
-return ICE->getSubExpr();
-
-  if (auto *FE = dyn_cast(E))
-return FE->getSubExpr();
-
-  return E;
-}
-
-static Expr *IgnoreImpCastsExtraSingleStep(Expr *E) {
-  // FIXME: Skip MaterializeTemporaryExpr and SubstNonTypeTemplateParmExpr in
-  // addition to what IgnoreImpCasts() skips to account for the current
-  // behaviour of IgnoreParenImpCasts().
-  Expr *SubE = IgnoreImpCastsSingleStep(E);
-  if (SubE != E)
-return SubE;
-
-  if (auto *MTE = dyn_cast(E))
-return MTE->getSubExpr();
-
-  if (auto *NTTP = dyn_cast(E))
-return NTTP->getReplacement();
-
-  return E;
-}
-
-static Expr *IgnoreCastsSingleStep(Expr *E) {
-  if (auto *CE = dyn_cast(E))
-return CE->getSubExpr();
-
-  if (auto *FE = dyn_cast(E))
-return FE->getSubExpr();
-
-  if (auto *MTE = dyn_cast(E))
-return MTE->getSubExpr();
-
-  if (auto *NTTP = dyn_cast(E))
-return NTTP->getReplacement();
-
-  return E;
-}
-
-static 

[PATCH] D86880: [Ignore Expressions][NFC] Refactor to better use `IgnoreExpr.h` and nits

2020-09-07 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1a7a2cd7474e: [Ignore Expressions][NFC] Refactor to better 
use `IgnoreExpr.h` and nits (authored by eduucaldas).

Changed prior to commit:
  https://reviews.llvm.org/D86880?vs=288961=290222#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86880

Files:
  clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
  clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
  clang/include/clang/AST/Expr.h
  clang/lib/AST/Expr.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp

Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -687,7 +687,7 @@
 // base class decl, rather than the class of the instance which needs to be
 // checked for mutable fields.
 // TODO: We might as well look at the dynamic type of the object.
-const Expr *Ex = getCXXThisExpr()->ignoreParenBaseCasts();
+const Expr *Ex = getCXXThisExpr()->IgnoreParenBaseCasts();
 QualType T = Ex->getType();
 if (T->isPointerType()) // Arrow or implicit-this syntax?
   T = T->getPointeeType();
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -8372,7 +8372,7 @@
Expr **RHSExprs) {
   // Don't strip parenthesis: we should not warn if E is in parenthesis.
   E = E->IgnoreImpCasts();
-  E = E->IgnoreConversionOperator();
+  E = E->IgnoreConversionOperatorSingleStep();
   E = E->IgnoreImpCasts();
   if (auto *MTE = dyn_cast(E)) {
 E = MTE->getSubExpr();
Index: clang/lib/CodeGen/CGExprCXX.cpp
===
--- clang/lib/CodeGen/CGExprCXX.cpp
+++ clang/lib/CodeGen/CGExprCXX.cpp
@@ -220,7 +220,7 @@
 DevirtualizedMethod = MD->getCorrespondingMethodInClass(BestDynamicDecl);
 assert(DevirtualizedMethod);
 const CXXRecordDecl *DevirtualizedClass = DevirtualizedMethod->getParent();
-const Expr *Inner = Base->ignoreParenBaseCasts();
+const Expr *Inner = Base->IgnoreParenBaseCasts();
 if (DevirtualizedMethod->getReturnType().getCanonicalType() !=
 MD->getReturnType().getCanonicalType())
   // If the return types are not the same, this might be a case where more
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -40,7 +40,7 @@
 const Expr *Expr::getBestDynamicClassTypeExpr() const {
   const Expr *E = this;
   while (true) {
-E = E->ignoreParenBaseCasts();
+E = E->IgnoreParenBaseCasts();
 
 // Follow the RHS of a comma operator.
 if (auto *BO = dyn_cast(E)) {
@@ -2780,29 +2780,6 @@
   return QualType();
 }
 
-static Expr *IgnoreNoopCastsSingleStep(const ASTContext , Expr *E) {
-  if (auto *CE = dyn_cast(E)) {
-// We ignore integer <-> casts that are of the same width, ptr<->ptr and
-// ptr<->int casts of the same width. We also ignore all identity casts.
-Expr *SubExpr = CE->getSubExpr();
-bool IsIdentityCast =
-Ctx.hasSameUnqualifiedType(E->getType(), SubExpr->getType());
-bool IsSameWidthCast =
-(E->getType()->isPointerType() || E->getType()->isIntegralType(Ctx)) &&
-(SubExpr->getType()->isPointerType() ||
- SubExpr->getType()->isIntegralType(Ctx)) &&
-(Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SubExpr->getType()));
-
-if (IsIdentityCast || IsSameWidthCast)
-  return SubExpr;
-  }
-
-  else if (auto *NTTP = dyn_cast(E))
-return NTTP->getReplacement();
-
-  return E;
-}
-
 Expr *Expr::IgnoreImpCasts() {
   return IgnoreExprNodes(this, IgnoreImplicitCastsSingleStep);
 }
@@ -2832,7 +2809,7 @@
   return IgnoreExprNodes(this, IgnoreParensSingleStep, IgnoreCastsSingleStep);
 }
 
-Expr *Expr::IgnoreConversionOperator() {
+Expr *Expr::IgnoreConversionOperatorSingleStep() {
   if (auto *MCE = dyn_cast(this)) {
 if (MCE->getMethodDecl() && isa(MCE->getMethodDecl()))
   return MCE->getImplicitObjectArgument();
@@ -2845,58 +2822,72 @@
  IgnoreLValueCastsSingleStep);
 }
 
-Expr *Expr::ignoreParenBaseCasts() {
+Expr *Expr::IgnoreParenBaseCasts() {
   return IgnoreExprNodes(this, IgnoreParensSingleStep,
  IgnoreBaseCastsSingleStep);
 }
 
 Expr *Expr::IgnoreParenNoopCasts(const ASTContext ) {
-  return IgnoreExprNodes(this, IgnoreParensSingleStep, [](Expr *E) {
-return IgnoreNoopCastsSingleStep(Ctx, E);
-  });
+  auto IgnoreNoopCastsSingleStep = [](Expr *E) {
+if (auto *CE = 

[PATCH] D86700: [SyntaxTree] Ignore leaf implicit `CXXConstructExpr`

2020-09-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp:552
   [[::n::S s1]];
   [[n::S s2]];
 }

gribozavr2 wrote:
> Do we have tests for calling constructors with arguments?
> 
> `n::S s3(1, 2, 3);`
> `n::S s3{1, 2, 3};`
> 
> If not, please add them.
We have. I improved their coverage in the parent patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86700

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


[PATCH] D77491: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2020-09-07 Thread Raul Tambre via Phabricator via cfe-commits
tambre updated this revision to Diff 290229.
tambre marked 3 inline comments as done.
tambre added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Headers/intrin.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/CodeGen/builtin-redeclaration.c
  clang/test/CodeGen/callback_pthread_create.c
  clang/test/CodeGenCXX/builtins.cpp
  clang/test/Sema/implicit-builtin-decl.c
  clang/test/Sema/warn-fortify-source.c
  clang/test/SemaCXX/cxx11-compat.cpp
  clang/test/SemaCXX/warn-unused-local-typedef.cpp

Index: clang/test/SemaCXX/warn-unused-local-typedef.cpp
===
--- clang/test/SemaCXX/warn-unused-local-typedef.cpp
+++ clang/test/SemaCXX/warn-unused-local-typedef.cpp
@@ -67,10 +67,10 @@
 
 void test() {
   typedef signed long int superint; // no diag
-  printf("%f", (superint) 42);
+  printf("%ld", (superint)42);
 
   typedef signed long int superint2; // no diag
-  printf("%f", static_cast(42));
+  printf("%ld", static_cast(42));
 
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wunused-local-typedef"
Index: clang/test/SemaCXX/cxx11-compat.cpp
===
--- clang/test/SemaCXX/cxx11-compat.cpp
+++ clang/test/SemaCXX/cxx11-compat.cpp
@@ -31,7 +31,7 @@
 s = { n }, // expected-warning {{non-constant-expression cannot be narrowed from type 'int' to 'char' in initializer list in C++11}} expected-note {{explicit cast}}
 t = { 1234 }; // expected-warning {{constant expression evaluates to 1234 which cannot be narrowed to type 'char' in C++11}} expected-warning {{changes value}} expected-note {{explicit cast}}
 
-#define PRIuS "uS"
+#define PRIuS "zu"
 int printf(const char *, ...);
 typedef __typeof(sizeof(int)) size_t;
 void h(size_t foo, size_t bar) {
Index: clang/test/Sema/warn-fortify-source.c
===
--- clang/test/Sema/warn-fortify-source.c
+++ clang/test/Sema/warn-fortify-source.c
@@ -1,8 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_PASS_OBJECT_SIZE
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_BUILTINS
 // RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify
-// RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_PASS_OBJECT_SIZE
 // RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_BUILTINS
 
 typedef unsigned long size_t;
@@ -13,13 +11,7 @@
 
 extern int sprintf(char *str, const char *format, ...);
 
-#if defined(USE_PASS_OBJECT_SIZE)
-void *memcpy(void *dst, const void *src, size_t c);
-static void *memcpy(void *dst __attribute__((pass_object_size(1))), const void *src, size_t c) __attribute__((overloadable)) __asm__("merp");
-static void *memcpy(void *const dst __attribute__((pass_object_size(1))), const void *src, size_t c) __attribute__((overloadable)) {
-  return 0;
-}
-#elif defined(USE_BUILTINS)
+#if defined(USE_BUILTINS)
 #define memcpy(x,y,z) __builtin_memcpy(x,y,z)
 #else
 void *memcpy(void *dst, const void *src, size_t c);
@@ -45,14 +37,7 @@
   };
   struct pair p;
   char buf[20];
-  memcpy(, buf, 20);
-#ifdef USE_PASS_OBJECT_SIZE
-  // Use the more strict checking mode on the pass_object_size attribute:
-  // expected-warning@-3 {{memcpy' will always overflow; destination buffer has size 4, but size argument is 20}}
-#else
-  // Or just fallback to type 0:
-  // expected-warning@-6 {{memcpy' will always overflow; destination buffer has size 8, but size argument is 20}}
-#endif
+  memcpy(, buf, 20); // expected-warning {{memcpy' will always overflow; destination buffer has size 8, but size argument is 20}}
 }
 
 void call_strncat() {
Index: clang/test/Sema/implicit-builtin-decl.c
===
--- clang/test/Sema/implicit-builtin-decl.c
+++ clang/test/Sema/implicit-builtin-decl.c
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// RUN: not %clang_cc1 -fsyntax-only -ast-dump %s | FileCheck %s
 
 void f() {
   int *ptr = malloc(sizeof(int) * 10); // expected-warning{{implicitly declaring library function 'malloc' with type}} \
@@ -63,9 +62,5 @@
 struct __jmp_buf_tag {};
 void sigsetjmp(struct __jmp_buf_tag[1], int); // expected-warning{{declaration of built-in function 'sigsetjmp' requires the declaration of the 'jmp_buf' type, commonly provided in the header .}}

[PATCH] D77491: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2020-09-07 Thread Raul Tambre via Phabricator via cfe-commits
tambre updated this revision to Diff 290232.
tambre marked an inline comment as done.
tambre added a comment.

Remove now obsolete FIXME.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Headers/intrin.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/CodeGen/builtin-redeclaration.c
  clang/test/CodeGen/callback_pthread_create.c
  clang/test/CodeGenCXX/builtins.cpp
  clang/test/Sema/implicit-builtin-decl.c
  clang/test/Sema/warn-fortify-source.c
  clang/test/SemaCXX/cxx11-compat.cpp
  clang/test/SemaCXX/warn-unused-local-typedef.cpp

Index: clang/test/SemaCXX/warn-unused-local-typedef.cpp
===
--- clang/test/SemaCXX/warn-unused-local-typedef.cpp
+++ clang/test/SemaCXX/warn-unused-local-typedef.cpp
@@ -67,10 +67,10 @@
 
 void test() {
   typedef signed long int superint; // no diag
-  printf("%f", (superint) 42);
+  printf("%ld", (superint)42);
 
   typedef signed long int superint2; // no diag
-  printf("%f", static_cast(42));
+  printf("%ld", static_cast(42));
 
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wunused-local-typedef"
Index: clang/test/SemaCXX/cxx11-compat.cpp
===
--- clang/test/SemaCXX/cxx11-compat.cpp
+++ clang/test/SemaCXX/cxx11-compat.cpp
@@ -31,7 +31,7 @@
 s = { n }, // expected-warning {{non-constant-expression cannot be narrowed from type 'int' to 'char' in initializer list in C++11}} expected-note {{explicit cast}}
 t = { 1234 }; // expected-warning {{constant expression evaluates to 1234 which cannot be narrowed to type 'char' in C++11}} expected-warning {{changes value}} expected-note {{explicit cast}}
 
-#define PRIuS "uS"
+#define PRIuS "zu"
 int printf(const char *, ...);
 typedef __typeof(sizeof(int)) size_t;
 void h(size_t foo, size_t bar) {
Index: clang/test/Sema/warn-fortify-source.c
===
--- clang/test/Sema/warn-fortify-source.c
+++ clang/test/Sema/warn-fortify-source.c
@@ -1,8 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_PASS_OBJECT_SIZE
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_BUILTINS
 // RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify
-// RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_PASS_OBJECT_SIZE
 // RUN: %clang_cc1 -xc++ -triple x86_64-apple-macosx10.14.0 %s -verify -DUSE_BUILTINS
 
 typedef unsigned long size_t;
@@ -13,13 +11,7 @@
 
 extern int sprintf(char *str, const char *format, ...);
 
-#if defined(USE_PASS_OBJECT_SIZE)
-void *memcpy(void *dst, const void *src, size_t c);
-static void *memcpy(void *dst __attribute__((pass_object_size(1))), const void *src, size_t c) __attribute__((overloadable)) __asm__("merp");
-static void *memcpy(void *const dst __attribute__((pass_object_size(1))), const void *src, size_t c) __attribute__((overloadable)) {
-  return 0;
-}
-#elif defined(USE_BUILTINS)
+#if defined(USE_BUILTINS)
 #define memcpy(x,y,z) __builtin_memcpy(x,y,z)
 #else
 void *memcpy(void *dst, const void *src, size_t c);
@@ -45,14 +37,7 @@
   };
   struct pair p;
   char buf[20];
-  memcpy(, buf, 20);
-#ifdef USE_PASS_OBJECT_SIZE
-  // Use the more strict checking mode on the pass_object_size attribute:
-  // expected-warning@-3 {{memcpy' will always overflow; destination buffer has size 4, but size argument is 20}}
-#else
-  // Or just fallback to type 0:
-  // expected-warning@-6 {{memcpy' will always overflow; destination buffer has size 8, but size argument is 20}}
-#endif
+  memcpy(, buf, 20); // expected-warning {{memcpy' will always overflow; destination buffer has size 8, but size argument is 20}}
 }
 
 void call_strncat() {
Index: clang/test/Sema/implicit-builtin-decl.c
===
--- clang/test/Sema/implicit-builtin-decl.c
+++ clang/test/Sema/implicit-builtin-decl.c
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// RUN: not %clang_cc1 -fsyntax-only -ast-dump %s | FileCheck %s
 
 void f() {
   int *ptr = malloc(sizeof(int) * 10); // expected-warning{{implicitly declaring library function 'malloc' with type}} \
@@ -63,9 +62,5 @@
 struct __jmp_buf_tag {};
 void sigsetjmp(struct __jmp_buf_tag[1], int); // expected-warning{{declaration of built-in function 'sigsetjmp' requires the declaration of the 'jmp_buf' type, commonly provided in the header 

[PATCH] D77491: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2020-09-07 Thread Raul Tambre via Phabricator via cfe-commits
tambre added a comment.

Thanks for the review. All tests still pass, should be good for another round.




Comment at: clang/lib/Sema/SemaDecl.cpp:9672-9673
+  if (unsigned BuiltinID = II->getBuiltinID()) {
+const auto *LinkageDecl =
+dyn_cast(NewFD->getDeclContext());
+

rsmith wrote:
> This will give the wrong answer for
> ```
> extern "C" {
> namespace X {
> void __builtin_foo();
> }
> }
> ```
> ... which does have C language linkage. Instead, please call 
> `FunctionDecl::getLanguageLinkage()`, which knows how to handle these cases.
Good suggestion. This fixes the long-standing FIXME inherited from 
`getBuiltinID()`. I've added a test for this.



Comment at: clang/lib/Serialization/ASTReader.cpp:914
+  return II.hadMacroDefinition() || II.isPoisoned() ||
+ II.getObjCOrBuiltinID() || II.hasRevertedTokenIDToIdentifier() ||
  (!(IsModule && Reader.getPreprocessor().getLangOpts().CPlusPlus) &&

rsmith wrote:
> We now consider `getObjCOrBuiltinID()` here for the `IsModule` case, where we 
> didn't before. Is that an intentional change?
Unintentional, fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491

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


[PATCH] D87118: Add an explicit toggle for the static analyzer in clang-tidy

2020-09-07 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a reviewer: NoQ.
Szelethus added a comment.
Herald added a subscriber: Charusso.

NoQ in particular has been working hard on the common infrastructure in between 
the static analyzer and clang-tidy, I'll add him :)


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

https://reviews.llvm.org/D87118

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


[PATCH] D87201: [clang-format] Add a option for the position of Java static import

2020-09-07 Thread Byoungchan Lee via Phabricator via cfe-commits
bc-lee updated this revision to Diff 290246.
bc-lee added a comment.

Modify the comment of Format.h to sync ClangFormatStyleOptions.rst


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87201

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/unittests/Format/SortImportsTestJava.cpp

Index: clang/unittests/Format/SortImportsTestJava.cpp
===
--- clang/unittests/Format/SortImportsTestJava.cpp
+++ clang/unittests/Format/SortImportsTestJava.cpp
@@ -250,6 +250,30 @@
  "import org.c;\n"));
 }
 
+TEST_F(SortImportsTestJava, FormatJavaStaticImportAfterImport) {
+  FmtStyle.JavaStaticImportAfterImport = true;
+
+  EXPECT_EQ("import com.test.b;\n"
+"import com.test.c;\n"
+"\n"
+"import org.b;\n"
+"\n"
+"import com.b;\n"
+"\n"
+"import static com.test.a;\n"
+"\n"
+"import static org.a;\n"
+"\n"
+"import static com.a;\n",
+sort("import static com.test.a;\n"
+ "import static org.a;\n"
+ "import static com.a;\n"
+ "import com.test.b;\n"
+ "import org.b;\n"
+ "import com.b;\n"
+ "import com.test.c;\n"));
+}
+
 TEST_F(SortImportsTestJava, DeduplicateImports) {
   EXPECT_EQ("import org.a;\n", sort("import org.a;\n"
 "import org.a;\n"));
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -544,6 +544,8 @@
 IO.mapOptional("JavaImportGroups", Style.JavaImportGroups);
 IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
+IO.mapOptional("JavaStaticImportAfterImport",
+   Style.JavaStaticImportAfterImport);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
@@ -901,6 +903,7 @@
   LLVMStyle.InsertTrailingCommas = FormatStyle::TCS_None;
   LLVMStyle.JavaScriptQuotes = FormatStyle::JSQS_Leave;
   LLVMStyle.JavaScriptWrapImports = true;
+  LLVMStyle.JavaStaticImportAfterImport = false;
   LLVMStyle.TabWidth = 8;
   LLVMStyle.MaxEmptyLinesToKeep = 1;
   LLVMStyle.KeepEmptyLinesAtTheStartOfBlocks = true;
@@ -2312,12 +2315,15 @@
 JavaImportGroups.push_back(
 findJavaImportGroup(Style, Imports[i].Identifier));
   }
+  bool StaticImportAfterNormalImport = Style.JavaStaticImportAfterImport;
   llvm::sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
 // Negating IsStatic to push static imports above non-static imports.
-return std::make_tuple(!Imports[LHSI].IsStatic, JavaImportGroups[LHSI],
-   Imports[LHSI].Identifier) <
-   std::make_tuple(!Imports[RHSI].IsStatic, JavaImportGroups[RHSI],
-   Imports[RHSI].Identifier);
+return std::make_tuple(!Imports[LHSI].IsStatic ^
+   StaticImportAfterNormalImport,
+   JavaImportGroups[LHSI], Imports[LHSI].Identifier) <
+   std::make_tuple(!Imports[RHSI].IsStatic ^
+   StaticImportAfterNormalImport,
+   JavaImportGroups[RHSI], Imports[RHSI].Identifier);
   });
 
   // Deduplicate imports.
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1689,6 +1689,21 @@
   bool JavaScriptWrapImports;
   // clang-format on
 
+  /// If true, clang-format will put Java static imports after all non-static
+  /// imports.
+  /// \code{.java}
+  ///   true:
+  ///   import static org.example.function1;
+  ///
+  ///   import org.example.ClassA;
+  ///
+  ///   false:
+  ///   import org.example.ClassA;
+  ///
+  ///   import static org.example.function1;
+  /// \endcode
+  bool JavaStaticImportAfterImport;
+
   /// If true, the empty line at the start of blocks is kept.
   /// \code
   ///true:  false:
@@ -2410,6 +2425,7 @@
JavaImportGroups == R.JavaImportGroups &&
JavaScriptQuotes == R.JavaScriptQuotes &&
JavaScriptWrapImports == R.JavaScriptWrapImports &&
+   JavaStaticImportAfterImport == R.JavaStaticImportAfterImport &&
KeepEmptyLinesAtTheStartOfBlocks ==
R.KeepEmptyLinesAtTheStartOfBlocks &&
MacroBlockBegin == R.MacroBlockBegin &&
Index: clang/docs/ClangFormatStyleOptions.rst

[PATCH] D86700: [SyntaxTree] Ignore leaf implicit `CXXConstructExpr`

2020-09-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 290224.
eduucaldas marked an inline comment as done.
eduucaldas added a comment.

Add FIXME for `CXXFunctionalCastExpr`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86700

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp


Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -548,9 +548,6 @@
   struct S { };
 }
 void test() {
-  // FIXME: Remove the `UnknownExpression` wrapping `s1` and `s2`. This
-  // `UnknownExpression` comes from a leaf `CXXConstructExpr` in the
-  // ClangAST. We need to ignore leaf implicit nodes.
   [[::n::S s1]];
   [[n::S s2]];
 }
@@ -564,8 +561,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s1'
+  `-'s1'
 )txt",
R"txt(
 SimpleDeclaration
@@ -575,8 +571,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s2'
+  `-'s2'
 )txt"}));
 }
 
@@ -608,8 +603,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s1'
+  `-'s1'
 )txt",
R"txt(
 SimpleDeclaration
@@ -623,8 +617,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s2'
+  `-'s2'
 )txt"}));
 }
 
@@ -4073,6 +4066,7 @@
   X(int);
 };
 X test() {
+  // FIXME: Remove `UnknownExpression` due to implicit `CXXFunctionalCastExpr`
   [[return X(1);]]
 }
 )cpp",
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1129,6 +1129,12 @@
 return true;
   }
 
+  bool WalkUpFromCXXConstructExpr(CXXConstructExpr *S) {
+if (S->getParenOrBraceRange().isInvalid())
+  return true;
+return RecursiveASTVisitor::WalkUpFromCXXConstructExpr(S);
+  }
+
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
 // To construct a syntax tree of the same shape for calls to built-in and
 // user-defined operators, ignore the `DeclRefExpr` that refers to the


Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -548,9 +548,6 @@
   struct S { };
 }
 void test() {
-  // FIXME: Remove the `UnknownExpression` wrapping `s1` and `s2`. This
-  // `UnknownExpression` comes from a leaf `CXXConstructExpr` in the
-  // ClangAST. We need to ignore leaf implicit nodes.
   [[::n::S s1]];
   [[n::S s2]];
 }
@@ -564,8 +561,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s1'
+  `-'s1'
 )txt",
R"txt(
 SimpleDeclaration
@@ -575,8 +571,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s2'
+  `-'s2'
 )txt"}));
 }
 
@@ -608,8 +603,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s1'
+  `-'s1'
 )txt",
R"txt(
 SimpleDeclaration
@@ -623,8 +617,7 @@
 | `-'::' ListDelimiter
 |-'S'
 `-SimpleDeclarator Declarator
-  `-UnknownExpression
-`-'s2'
+  `-'s2'
 )txt"}));
 }
 
@@ -4073,6 +4066,7 @@
   X(int);
 };
 X test() {
+  // FIXME: Remove `UnknownExpression` due to implicit `CXXFunctionalCastExpr`
   [[return X(1);]]
 }
 )cpp",
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -1129,6 +1129,12 @@
 return true;
   }
 
+  bool WalkUpFromCXXConstructExpr(CXXConstructExpr *S) {
+if (S->getParenOrBraceRange().isInvalid())
+  return true;
+return RecursiveASTVisitor::WalkUpFromCXXConstructExpr(S);
+  }
+
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
 // To construct a syntax tree of the same shape for calls to built-in and
 // user-defined operators, ignore the `DeclRefExpr` that refers to the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76590: [Analyzer] Model `empty()` member function of containers

2020-09-07 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 290248.
baloghadamsoftware added a comment.

Wrong diff uploaded previously. (Accidentally compared to //master// instead of 
the prerequisite.)


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

https://reviews.llvm.org/D76590

Files:
  clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
  clang/lib/StaticAnalyzer/Checkers/Iterator.h
  clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
  clang/test/Analysis/Inputs/system-header-simulator-cxx.h
  clang/test/Analysis/container-modeling.cpp
  clang/test/Analysis/diagnostics/explicit-suppression.cpp
  clang/test/Analysis/smart-ptr-text-output.cpp

Index: clang/test/Analysis/smart-ptr-text-output.cpp
===
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -80,7 +80,7 @@
 void derefOnStdSwappedNullPtr() {
   std::unique_ptr P; // expected-note {{Default constructed smart pointer 'P' is null}}
   std::unique_ptr PNull; // expected-note {{Default constructed smart pointer 'PNull' is null}}
-  std::swap(P, PNull); // expected-note@Inputs/system-header-simulator-cxx.h:979 {{Swapped null smart pointer 'PNull' with smart pointer 'P'}}
+  std::swap(P, PNull); // expected-note@Inputs/system-header-simulator-cxx.h:987 {{Swapped null smart pointer 'PNull' with smart pointer 'P'}}
   // expected-note@-1 {{Calling 'swap'}}
   // expected-note@-2 {{Returning from 'swap'}}
   P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
Index: clang/test/Analysis/diagnostics/explicit-suppression.cpp
===
--- clang/test/Analysis/diagnostics/explicit-suppression.cpp
+++ clang/test/Analysis/diagnostics/explicit-suppression.cpp
@@ -19,6 +19,6 @@
 void testCopyNull(C *I, C *E) {
   std::copy(I, E, (C *)0);
 #ifndef SUPPRESSED
-  // expected-warning@../Inputs/system-header-simulator-cxx.h:709 {{Called C++ object pointer is null}}
+  // expected-warning@../Inputs/system-header-simulator-cxx.h:717 {{Called C++ object pointer is null}}
 #endif
 }
Index: clang/test/Analysis/container-modeling.cpp
===
--- clang/test/Analysis/container-modeling.cpp
+++ clang/test/Analysis/container-modeling.cpp
@@ -16,6 +16,12 @@
 void clang_analyzer_eval(bool);
 void clang_analyzer_warnIfReached();
 
+extern void __assert_fail (__const char *__assertion, __const char *__file,
+unsigned int __line, __const char *__function)
+ __attribute__ ((__noreturn__));
+#define assert(expr) \
+  ((expr)  ? (void)(0)  : __assert_fail (#expr, __FILE__, __LINE__, __func__))
+
 void begin(const std::vector ) {
   V.begin();
 
@@ -56,6 +62,40 @@
// expected-note@-1{{TRUE}}
 }
 
+
+///
+/// C O N T A I N E R   C A P A C I T Y
+///
+
+
+/// empty()
+
+void empty(const std::vector ) {
+  for (auto n: V) {}
+  clang_analyzer_eval(clang_analyzer_container_begin(V) ==
+  clang_analyzer_container_end(V));
+  // expected-warning@-2{{TRUE}} expected-warning@-2{{FALSE}}
+  // expected-note@-3   {{TRUE}} expected-note@-3   {{FALSE}}
+}
+
+void non_empty1(const std::vector ) {
+  assert(!V.empty()); // expected-note{{'?' condition is true}}
+  for (auto n: V) {}
+  clang_analyzer_eval(clang_analyzer_container_begin(V) ==
+  clang_analyzer_container_end(V));
+  // expected-warning@-2{{FALSE}}
+  // expected-note@-3   {{FALSE}}
+}
+
+void non_empty2(const std::vector ) {
+  for (auto n: V) {}
+  assert(!V.empty()); // expected-note{{'?' condition is true}}
+  clang_analyzer_eval(clang_analyzer_container_begin(V) ==
+  clang_analyzer_container_end(V));
+  // expected-warning@-2{{FALSE}}
+  // expected-note@-3   {{FALSE}}
+}
+
 
 ///
 /// C O N T A I N E R   M O D I F I E R S
Index: clang/test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- clang/test/Analysis/Inputs/system-header-simulator-cxx.h
+++ clang/test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -344,6 +344,8 @@
 const T& front() const { return *begin(); }
 T& back() { return *(end() - 1); }
 const T& back() const { return *(end() - 1); }
+
+bool empty() const;
   };
   
   template
@@ -415,6 +417,8 @@
 const T& front() const { return *begin(); }
 T& back() { return *--end(); }
 const T& back() const { return *--end(); }
+
+bool empty() const;
   };
 
   template
@@ -496,6 +500,8 @@
 const T& front() const { 

[PATCH] D84415: [analyzer][StdLibraryFunctionsChecker] Add POSIX pthread handling functions

2020-09-07 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

@balazske seems to be very involved, he might have some closing words -- from 
my end, LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84415

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


[PATCH] D87229: [SyntaxTree] Ignore implicit `CXXFunctionalCastExpr` wrapping constructor

2020-09-07 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87229

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp


Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -4066,7 +4066,6 @@
   X(int);
 };
 X test() {
-  // FIXME: Remove `UnknownExpression` due to implicit `CXXFunctionalCastExpr`
   [[return X(1);]]
 }
 )cpp",
@@ -4074,12 +4073,11 @@
 ReturnStatement Statement
 |-'return' IntroducerKeyword
 |-UnknownExpression ReturnValue
-| `-UnknownExpression
-|   |-'X'
-|   |-'('
-|   |-IntegerLiteralExpression
-|   | `-'1' LiteralToken
-|   `-')'
+| |-'X'
+| |-'('
+| |-IntegerLiteralExpression
+| | `-'1' LiteralToken
+| `-')'
 `-';'
 )txt"}));
 }
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -14,6 +14,7 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/IgnoreExpr.h"
+#include "clang/AST/OperationKinds.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/TypeLoc.h"
@@ -57,9 +58,18 @@
   return E;
 }
 
+static Expr *IgnoreCXXFunctionalCastExprWrappingConstructor(Expr *E) {
+  if (auto *F = dyn_cast(E)) {
+if (F->getCastKind() == CK_ConstructorConversion)
+  return F->getSubExpr();
+  }
+  return E;
+}
+
 static Expr *IgnoreImplicit(Expr *E) {
   return IgnoreExprNodes(E, IgnoreImplicitSingleStep,
- IgnoreImplicitConstructorSingleStep);
+ IgnoreImplicitConstructorSingleStep,
+ IgnoreCXXFunctionalCastExprWrappingConstructor);
 }
 
 LLVM_ATTRIBUTE_UNUSED


Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -4066,7 +4066,6 @@
   X(int);
 };
 X test() {
-  // FIXME: Remove `UnknownExpression` due to implicit `CXXFunctionalCastExpr`
   [[return X(1);]]
 }
 )cpp",
@@ -4074,12 +4073,11 @@
 ReturnStatement Statement
 |-'return' IntroducerKeyword
 |-UnknownExpression ReturnValue
-| `-UnknownExpression
-|   |-'X'
-|   |-'('
-|   |-IntegerLiteralExpression
-|   | `-'1' LiteralToken
-|   `-')'
+| |-'X'
+| |-'('
+| |-IntegerLiteralExpression
+| | `-'1' LiteralToken
+| `-')'
 `-';'
 )txt"}));
 }
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -14,6 +14,7 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/IgnoreExpr.h"
+#include "clang/AST/OperationKinds.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/TypeLoc.h"
@@ -57,9 +58,18 @@
   return E;
 }
 
+static Expr *IgnoreCXXFunctionalCastExprWrappingConstructor(Expr *E) {
+  if (auto *F = dyn_cast(E)) {
+if (F->getCastKind() == CK_ConstructorConversion)
+  return F->getSubExpr();
+  }
+  return E;
+}
+
 static Expr *IgnoreImplicit(Expr *E) {
   return IgnoreExprNodes(E, IgnoreImplicitSingleStep,
- IgnoreImplicitConstructorSingleStep);
+ IgnoreImplicitConstructorSingleStep,
+ IgnoreCXXFunctionalCastExprWrappingConstructor);
 }
 
 LLVM_ATTRIBUTE_UNUSED
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80878: [clang] Prevent that Decl::dump on a CXXRecordDecl deserialises further declarations.

2020-09-07 Thread Raphael Isemann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0478720157f6: [clang] Prevent that Decl::dump on a 
CXXRecordDecl deserialises further… (authored by teemperor).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80878

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-lambda.cpp
  clang/test/AST/ast-dump-records.cpp
  clang/unittests/AST/ASTDumpTest.cpp
  clang/unittests/AST/CMakeLists.txt

Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -6,6 +6,7 @@
 
 add_clang_unittest(ASTTests
   ASTContextParentMapTest.cpp
+  ASTDumpTest.cpp
   ASTImporterFixtures.cpp
   ASTImporterTest.cpp
   ASTImporterGenericRedeclTest.cpp
Index: clang/unittests/AST/ASTDumpTest.cpp
===
--- /dev/null
+++ clang/unittests/AST/ASTDumpTest.cpp
@@ -0,0 +1,140 @@
+//===- unittests/AST/ASTDumpTest.cpp --- Declaration tests ===//
+//
+// 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
+//
+//===--===//
+//
+// Tests Decl::dump().
+//
+//===--===//
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclObjC.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceManager.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+namespace clang {
+namespace ast {
+
+namespace {
+/// An ExternalASTSource that asserts if it is queried for information about
+/// any declaration.
+class TrappingExternalASTSource : public ExternalASTSource {
+  ~TrappingExternalASTSource() override = default;
+  bool FindExternalVisibleDeclsByName(const DeclContext *,
+  DeclarationName) override {
+assert(false && "Unexpected call to FindExternalVisibleDeclsByName");
+return true;
+  }
+
+  void FindExternalLexicalDecls(const DeclContext *,
+llvm::function_ref,
+SmallVectorImpl &) override {
+assert(false && "Unexpected call to FindExternalLexicalDecls");
+  }
+
+  void completeVisibleDeclsMap(const DeclContext *) override {
+assert(false && "Unexpected call to completeVisibleDeclsMap");
+  }
+
+  void CompleteRedeclChain(const Decl *) override {
+assert(false && "Unexpected call to CompleteRedeclChain");
+  }
+
+  void CompleteType(TagDecl *) override {
+assert(false && "Unexpected call to CompleteType(Tag Decl*)");
+  }
+
+  void CompleteType(ObjCInterfaceDecl *) override {
+assert(false && "Unexpected call to CompleteType(ObjCInterfaceDecl *)");
+  }
+};
+
+/// Tests that Decl::dump doesn't load additional declarations from the
+/// ExternalASTSource.
+class ExternalASTSourceDumpTest : public ::testing::Test {
+protected:
+  ExternalASTSourceDumpTest()
+  : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
+Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
+SourceMgr(Diags, FileMgr), Idents(LangOpts, nullptr),
+Ctxt(LangOpts, SourceMgr, Idents, Sels, Builtins) {
+Ctxt.setExternalSource(new TrappingExternalASTSource());
+  }
+
+  FileSystemOptions FileMgrOpts;
+  FileManager FileMgr;
+  IntrusiveRefCntPtr DiagID;
+  DiagnosticsEngine Diags;
+  SourceManager SourceMgr;
+  LangOptions LangOpts;
+  IdentifierTable Idents;
+  SelectorTable Sels;
+  Builtin::Context Builtins;
+  ASTContext Ctxt;
+};
+} // unnamed namespace
+
+/// Set all flags that activate queries to the ExternalASTSource.
+static void setExternalStorageFlags(DeclContext *DC) {
+  DC->setHasExternalLexicalStorage();
+  DC->setHasExternalVisibleStorage();
+  DC->setMustBuildLookupTable();
+}
+
+/// Dumps the given Decl.
+static void dumpDecl(Decl *D) {
+  // Try dumping the decl which shouldn't trigger any calls to the
+  // ExternalASTSource.
+
+  std::string Out;
+  llvm::raw_string_ostream OS(Out);
+  D->dump(OS);
+}
+
+TEST_F(ExternalASTSourceDumpTest, DumpObjCInterfaceDecl) {
+  // Define an Objective-C interface.
+  ObjCInterfaceDecl *I = ObjCInterfaceDecl::Create(
+  Ctxt, Ctxt.getTranslationUnitDecl(), SourceLocation(),
+  ("c"), nullptr, nullptr);
+  Ctxt.getTranslationUnitDecl()->addDecl(I);
+
+  setExternalStorageFlags(I);
+  dumpDecl(I);
+}
+
+TEST_F(ExternalASTSourceDumpTest, DumpRecordDecl) {
+  // Define a struct.
+  RecordDecl *R = RecordDecl::Create(
+  Ctxt, TagDecl::TagKind::TTK_Class, 

[clang] 0478720 - [clang] Prevent that Decl::dump on a CXXRecordDecl deserialises further declarations.

2020-09-07 Thread Raphael Isemann via cfe-commits

Author: Raphael Isemann
Date: 2020-09-07T12:31:30+02:00
New Revision: 0478720157f6413fad7595b8eff9c70d2d99b637

URL: 
https://github.com/llvm/llvm-project/commit/0478720157f6413fad7595b8eff9c70d2d99b637
DIFF: 
https://github.com/llvm/llvm-project/commit/0478720157f6413fad7595b8eff9c70d2d99b637.diff

LOG: [clang] Prevent that Decl::dump on a CXXRecordDecl deserialises further 
declarations.

Decl::dump is primarily used for debugging to visualise the current state of a
declaration. Usually Decl::dump just displays the current state of the Decl and
doesn't actually change any of its state, however since commit
457226e02a6e8533eaaa864a3fd7c8eeccd2bf58 the method actually started loading
additional declarations from the ExternalASTSource. This causes that calling
Decl::dump during a debugging session now actually does permanent changes to the
AST and will cause the debugged program run to deviate from the original run.

The change that caused this behaviour is the addition of
`hasConstexprDestructor` (which is called from the TextNodeDumper) which
performs a lookup into the current CXXRecordDecl to find the destructor. All
other similar methods just return their respective bit in the DefinitionData
(which obviously doesn't have such side effects).

This just changes the node printer to emit "unknown_constexpr" in case a
CXXRecordDecl is dumped that could potentially call into the ExternalASTSource
instead of the usually empty string/"constexpr". For CXXRecordDecls that can
safely be dumped the old behaviour is preserved

Reviewed By: bruno

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

Added: 
clang/unittests/AST/ASTDumpTest.cpp

Modified: 
clang/lib/AST/TextNodeDumper.cpp
clang/test/AST/ast-dump-lambda.cpp
clang/test/AST/ast-dump-records.cpp
clang/unittests/AST/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/AST/TextNodeDumper.cpp 
b/clang/lib/AST/TextNodeDumper.cpp
index 16c4c3736a4a..19b7b4c801d5 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1960,7 +1960,11 @@ void TextNodeDumper::VisitCXXRecordDecl(const 
CXXRecordDecl *D) {
   FLAG(hasTrivialDestructor, trivial);
   FLAG(hasNonTrivialDestructor, non_trivial);
   FLAG(hasUserDeclaredDestructor, user_declared);
-  FLAG(hasConstexprDestructor, constexpr);
+  // Avoid calls to the external source.
+  if (!D->hasExternalVisibleStorage()) {
+FLAG(hasConstexprDestructor, constexpr);
+  } else
+OS << " maybe_constexpr";
   FLAG(needsImplicitDestructor, needs_implicit);
   FLAG(needsOverloadResolutionForDestructor, needs_overload_resolution);
   if (!D->needsOverloadResolutionForDestructor())

diff  --git a/clang/test/AST/ast-dump-lambda.cpp 
b/clang/test/AST/ast-dump-lambda.cpp
index 37fb62ef9930..302b93734459 100644
--- a/clang/test/AST/ast-dump-lambda.cpp
+++ b/clang/test/AST/ast-dump-lambda.cpp
@@ -48,7 +48,7 @@ template  void test(Ts... a) {
 // CHECK-NEXT:|   | |-MoveConstructor exists simple trivial needs_implicit
 // CHECK-NEXT:|   | |-CopyAssignment simple trivial has_const_param 
needs_implicit implicit_has_const_param
 // CHECK-NEXT:|   | |-MoveAssignment exists simple trivial needs_implicit
-// CHECK-NEXT:|   | `-Destructor simple irrelevant trivial needs_implicit
+// CHECK-NEXT:|   | `-Destructor simple irrelevant trivial{{( 
maybe_constexpr)?}} needs_implicit
 // CHECK-NEXT:|   |-CXXRecordDecl {{.*}}  col:10{{( 
imported)?}} implicit struct V
 // CHECK-NEXT:|   `-CXXMethodDecl {{.*}}  
line:17:10{{( imported)?}} f 'void ()'
 // CHECK-NEXT:| `-CompoundStmt {{.*}} 
@@ -60,7 +60,7 @@ template  void test(Ts... a) {
 // CHECK-NEXT:|   | | | |-MoveConstructor exists simple trivial 
needs_implicit
 // CHECK-NEXT:|   | | | |-CopyAssignment trivial has_const_param 
needs_implicit implicit_has_const_param
 // CHECK-NEXT:|   | | | |-MoveAssignment
-// CHECK-NEXT:|   | | | `-Destructor simple irrelevant trivial 
needs_implicit
+// CHECK-NEXT:|   | | | `-Destructor simple irrelevant trivial{{( 
maybe_constexpr)?}} needs_implicit
 // CHECK-NEXT:|   | | |-CXXMethodDecl {{.*}}  col:7{{( 
imported)?}} operator() 'auto () const -> auto' inline
 // CHECK-NEXT:|   | | | `-CompoundStmt {{.*}} 
 // CHECK-NEXT:|   | | `-FieldDecl {{.*}}  col:8{{( imported)?}} 
implicit 'V *'
@@ -75,7 +75,7 @@ template  void test(Ts... a) {
 // CHECK-NEXT:| | | |-MoveConstructor exists simple trivial 
needs_implicit
 // CHECK-NEXT:| | | |-CopyAssignment trivial has_const_param 
needs_implicit implicit_has_const_param
 // CHECK-NEXT:| | | |-MoveAssignment
-// CHECK-NEXT:| | | `-Destructor simple irrelevant trivial 
needs_implicit
+// CHECK-NEXT:| | | `-Destructor simple irrelevant trivial{{( 
maybe_constexpr)?}} 

[PATCH] D80878: [clang] Prevent that Decl::dump on a CXXRecordDecl deserialises further declarations.

2020-09-07 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

And what if deserialization is forced?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80878

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


[PATCH] D86632: [Fixed Point] Add codegen for conversion between fixed-point and floating point.

2020-09-07 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan updated this revision to Diff 290245.
ebevhan added a comment.

Added promotion mechanism.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86632

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/Frontend/fixed_point_compound.c
  clang/test/Frontend/fixed_point_conversions.c
  clang/test/Frontend/fixed_point_conversions_half.c
  llvm/include/llvm/IR/FixedPointBuilder.h

Index: llvm/include/llvm/IR/FixedPointBuilder.h
===
--- llvm/include/llvm/IR/FixedPointBuilder.h
+++ llvm/include/llvm/IR/FixedPointBuilder.h
@@ -120,6 +120,17 @@
 C.isSigned(), C.isSaturated(), BothPadded);
   }
 
+  /// Given a floating point type and a fixed-point semantic, return a floating
+  /// point type which can accommodate the fixed-point semantic. This is either
+  /// \p Ty, or a floating point type with a larger exponent than Ty.
+  Type *getAccommodatingFloatType(Type *Ty, const FixedPointSemantics ) {
+const fltSemantics *FloatSema = >getFltSemantics();
+while (!Sema.canAccommodateFloatSemantics(*FloatSema))
+  FloatSema = APFixedPoint::promoteFloatSemantics(FloatSema);
+// There's seemingly no way to convert fltSemantics to Type.
+return ConstantFP::get(Ty->getContext(), APFloat(*FloatSema))->getType();
+  }
+
 public:
   FixedPointBuilder(IRBuilderTy ) : B(Builder) {}
 
@@ -159,6 +170,55 @@
DstSema, false);
   }
 
+  Value *CreateFixedToFloating(Value *Src, const FixedPointSemantics ,
+   Type *DstTy) {
+Value *Result;
+Type *OpTy = getAccommodatingFloatType(DstTy, SrcSema);
+// Convert the raw fixed-point value directly to floating point. If the
+// value is too large to fit, it will be rounded, not truncated.
+Result = SrcSema.isSigned() ? B.CreateSIToFP(Src, OpTy)
+: B.CreateUIToFP(Src, OpTy);
+// Rescale the integral-in-floating point by the scaling factor. This is
+// lossless, except for overflow to infinity which is unlikely.
+Result = B.CreateFMul(Result,
+ConstantFP::get(OpTy, std::pow(2, -(int)SrcSema.getScale(;
+if (OpTy != DstTy)
+  Result = B.CreateFPTrunc(Result, DstTy);
+return Result;
+  }
+
+  Value *CreateFloatingToFixed(Value *Src, const FixedPointSemantics ) {
+bool UseSigned = DstSema.isSigned() || DstSema.hasUnsignedPadding();
+Value *Result = Src;
+Type *OpTy = getAccommodatingFloatType(Src->getType(), DstSema);
+if (OpTy != Src->getType())
+  Result = B.CreateFPExt(Result, OpTy);
+// Rescale the floating point value so that its significant bits (for the
+// purposes of the conversion) are in the integral range.
+Result = B.CreateFMul(Result,
+ConstantFP::get(OpTy, std::pow(2, DstSema.getScale(;
+
+Type *ResultTy = B.getIntNTy(DstSema.getWidth());
+if (DstSema.isSaturated()) {
+  Intrinsic::ID IID =
+  UseSigned ? Intrinsic::fptosi_sat : Intrinsic::fptoui_sat;
+  Result = B.CreateIntrinsic(IID, {ResultTy, OpTy}, {Result});
+} else {
+  Result = UseSigned ? B.CreateFPToSI(Result, ResultTy)
+ : B.CreateFPToUI(Result, ResultTy);
+}
+
+// When saturating unsigned-with-padding using signed operations, we may
+// get negative values. Emit an extra clamp to zero.
+if (DstSema.isSaturated() && DstSema.hasUnsignedPadding()) {
+  Constant *Zero = Constant::getNullValue(Result->getType());
+  Result =
+  B.CreateSelect(B.CreateICmpSLT(Result, Zero), Zero, Result, "satmin");
+}
+
+return Result;
+  }
+
   /// Add two fixed-point values and return the result in their common semantic.
   /// \p LHS - The left hand side
   /// \p LHSSema - The semantic of the left hand side
Index: clang/test/Frontend/fixed_point_conversions_half.c
===
--- /dev/null
+++ clang/test/Frontend/fixed_point_conversions_half.c
@@ -0,0 +1,309 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -ffixed-point -triple arm64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
+// RUN: %clang_cc1 -ffixed-point -triple arm64-unknown-linux-gnu -S -emit-llvm %s -o - -fpadding-on-unsigned-fixed-point | FileCheck %s --check-prefixes=CHECK,UNSIGNED
+
+short _Fract sf;
+long _Fract lf;
+
+short _Accum sa;
+long _Accum la;
+
+unsigned short _Accum usa;
+unsigned long _Accum ula;
+
+_Sat short _Fract sf_sat;
+_Sat long _Fract lf_sat;
+
+_Sat short _Accum sa_sat;
+_Sat long _Accum la_sat;
+
+_Sat unsigned short _Accum usa_sat;
+_Sat unsigned long _Accum ula_sat;
+
+_Float16 h;
+
+
+// CHECK-LABEL: @half_fix1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = load half, half* @h, align 2
+// CHECK-NEXT:[[TMP1:%.*]] = fmul half [[TMP0]], 

[PATCH] D76590: [Analyzer] Model `empty()` member function of containers

2020-09-07 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp:36
+  void handleAssignment(CheckerContext , const Expr *CE, SVal Cont,
+Optional = None) const;
+

Szelethus wrote:
> Hmm, this was changed to an optional, unnamed parameter without docs... Might 
> be a bit cryptic :) Also, this seems to be orthogonal to the patch, is it 
> not? Does the modeling of `empty()` change something that affects this 
> function?
We discussed with @NoQ a few patches earlier that `UnknownVal` is not a 
`nullptr`-like value for `SVal`s. That time I changed this bad practice in my 
code everywhere, only forgot this particular place. I do not think that this 
deserves its own patch, it is really a tiny thing.



Comment at: clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp:420-427
+  // We cannot make assumpotions on `UnknownVal`. Let us conjure a symbol
+  // instead.
+  if (RetVal.isUnknown()) {
+auto  = C.getSymbolManager();
+RetVal = nonloc::SymbolVal(SymMgr.conjureSymbol(
+CE, LCtx, C.getASTContext().BoolTy, C.blockCount()));
+State = State->BindExpr(CE, LCtx, RetVal);

Szelethus wrote:
> Szelethus wrote:
> > assumpotions > assumptions
> You will have to help me out here -- if the analyzer couldn't return a 
> sensible symbol, is it okay to just create one? When does `UnknownVal` even 
> happen, does it ever happen? Also, if we're doing this anyways, wouldn't 
> using `evalCall` be more appropriate?
Actually, both `UnknownVal` and `SymbolVal` containing a `SymbolConjured` 
without constraints are unknown. The main difference (for us) is that we cannot 
assign constraints to `UnknownVal` but we can for `SymbolConjured`. This is the 
reason for replacing it. However, this is not new. We do it in comparison too. 
The best would be to change the infrastructure to never return `UnknownVal` but 
conjure a new symbol instead if we known nothing about the return value. Maybe 
I will put a `FIXME` there. `evalCall()` is not an option, because we do not 
want to lose the possibility that the implementation of `empty()` is inlined by 
the engine.



Comment at: 
clang/unittests/StaticAnalyzer/TestReturnValueUnderConstruction.cpp:71
+
+  EXPECT_TRUE(runCheckerOnCode(
+  R"(class C {

Szelethus wrote:
> Did you mean to upload changed to this file from D85351 to this patch as well?
No, I just uploaded the wrong diff here.


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

https://reviews.llvm.org/D76590

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


  1   2   >