[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-16 Thread Tom Roeder 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 rG1844ab770cb9: [ASTImporter] Add support for importing 
GenericSelectionExpr AST nodes. (authored by tmroeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.cpp
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/test/ASTMerge/generic-selection-expr/test.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -982,6 +982,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1598,6 +1598,72 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, unsigned int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSignsDiffer) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0, int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprOrderDiffers) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, float: 1, unsigned int: 0)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprDependentResultSame) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  void g() { f(); }
+  )",
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  void g() { f(); }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest,
+   GenericSelectionExprDependentResultOrderDiffers) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, float: 1, int: 0);
+  }
+  void g() { f(); }
+  )",
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  void g() { f(); }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+
+  EXPECT_FALSE(testStructuralMatch(t));
+}
 TEST_F(StructuralEquivalenceStmtTest, IntegerLiteral) {
   auto t = makeWrappedStmts("1", "1", Lang_CXX03, integerLiteral());
   EXPECT_TRUE(testStructuralMatch(t));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -279,6 +279,15 @@
  functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger());
 }
 
+TEST_P(ImportExpr, ImportGenericSelectionExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+  "void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
+  Lang_C99, "", Lang_C99, Verifier,
+  functionDecl(hasDescendant(genericSelectionExpr(;
+}
+
 TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -1087,6 +1096,36 @@
 ToChooseExpr->isConditionDependent());
 }
 

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-16 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder added a comment.

In D92600#2458715 , @tmroeder wrote:

> Looks like I missed the transition of my credentials from SVN from github, so 
> I can't currently commit this.
>
> How do I go about getting those credentials restored?

Never mind, I found it in the Developer Policy document


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-16 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder added a comment.

Looks like I missed the transition of my credentials from SVN from github, so I 
can't currently commit this.

How do I go about getting those credentials restored?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-16 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 312256.
tmroeder added a comment.

Rebase to the latest head, mostly to force the CI infrastructure to run again 
now that it is said to work again: 
https://github.com/google/llvm-premerge-checks/issues/268#issuecomment-745979134.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.cpp
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/test/ASTMerge/generic-selection-expr/test.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -982,6 +982,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1598,6 +1598,72 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, unsigned int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSignsDiffer) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0, int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprOrderDiffers) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, float: 1, unsigned int: 0)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprDependentResultSame) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  void g() { f(); }
+  )",
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  void g() { f(); }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest,
+   GenericSelectionExprDependentResultOrderDiffers) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, float: 1, int: 0);
+  }
+  void g() { f(); }
+  )",
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  void g() { f(); }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+
+  EXPECT_FALSE(testStructuralMatch(t));
+}
 TEST_F(StructuralEquivalenceStmtTest, IntegerLiteral) {
   auto t = makeWrappedStmts("1", "1", Lang_CXX03, integerLiteral());
   EXPECT_TRUE(testStructuralMatch(t));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -279,6 +279,15 @@
  functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger());
 }
 
+TEST_P(ImportExpr, ImportGenericSelectionExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+  "void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
+  Lang_C99, "", Lang_C99, Verifier,
+  functionDecl(hasDescendant(genericSelectionExpr(;
+}
+
 TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -1087,6 +1096,36 @@
 ToChooseExpr->isConditionDependent());
 }
 

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-15 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

Thanks for your work, I am glad that finally the Window bug is fixed with a 
simple solution.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-15 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 311961.
tmroeder added a comment.

Explicitly instantiate the templates in the structural-equivalence test.

This seems to work correctly on Windows, and it avoids the need for the extra 
hooks in the test framework. So, this diff removes those hooks as well as the 
nullptr test. The latter is no longer needed either because the templates get 
explicitly instantiated, even under delayed template expansion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.cpp
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/test/ASTMerge/generic-selection-expr/test.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -982,6 +982,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1598,6 +1598,72 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, unsigned int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSignsDiffer) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0, int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprOrderDiffers) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, float: 1, unsigned int: 0)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprDependentResultSame) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  void g() { f(); }
+  )",
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  void g() { f(); }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest,
+   GenericSelectionExprDependentResultOrderDiffers) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, float: 1, int: 0);
+  }
+  void g() { f(); }
+  )",
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  void g() { f(); }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+
+  EXPECT_FALSE(testStructuralMatch(t));
+}
 TEST_F(StructuralEquivalenceStmtTest, IntegerLiteral) {
   auto t = makeWrappedStmts("1", "1", Lang_CXX03, integerLiteral());
   EXPECT_TRUE(testStructuralMatch(t));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -279,6 +279,15 @@
  functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger());
 }
 
+TEST_P(ImportExpr, ImportGenericSelectionExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+  "void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
+  Lang_C99, "", Lang_C99, Verifier,
+  functionDecl(hasDescendant(genericSelectionExpr(;
+}
+
 TEST_P(ImportExpr, 

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-15 Thread Gabor Marton via Phabricator via cfe-commits
martong requested changes to this revision.
martong added inline comments.
This revision now requires changes to proceed.



Comment at: clang/unittests/AST/StructuralEquivalenceTest.cpp:1656-1662
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, float: 1, int: 0);
+  }
+  )",

> Change the DeclMatcher.h test code to expose the ability to not assert on 
> null Nodes from a match.

The original idea was to assert in the DeclMatcher to indicate a failure in the 
test itself. In the past it happened to me often that I wrote a wrong matcher 
and that assertion indicated it and that was really helpful.

So, I'd suggest an alternative approach instead of this change in the 
DeclMatcher: Try to instantiate the template function itself, so even if the 
delayed template instantiation option is set, the compiler must instantiate. 

Related code in other ASTImporter tests:
https://github.com/llvm/llvm-project/blob/bd0709266911bce2f1e8a875f9ed49d56953f323/clang/unittests/AST/ASTImporterGenericRedeclTest.cpp#L60


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-14 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 311738.
tmroeder added a comment.

Update to the latest head. No changes from previous diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.cpp
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/test/ASTMerge/generic-selection-expr/test.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/DeclMatcher.h
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -982,6 +982,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -92,23 +92,34 @@
 
   // Get a pair of node pointers into the synthesized AST from the given code
   // snippets. To determine the returned node, a separate matcher is specified
-  // for both snippets. The first matching node is returned.
+  // for both snippets. The first matching node is returned. AssertNonNull
+  // controls whether or not to assert that the return nodes are not null.
   template 
   std::tuple
   makeStmts(const std::string , const std::string ,
 TestLanguage Lang, const MatcherType ,
-const MatcherType ) {
+const MatcherType , bool AssertNonNull) {
 makeASTUnits(SrcCode0, SrcCode1, Lang);
 
 Stmt *S0 = FirstDeclMatcher().match(
-AST0->getASTContext().getTranslationUnitDecl(), Matcher0);
+AST0->getASTContext().getTranslationUnitDecl(), Matcher0,
+AssertNonNull);
 Stmt *S1 = FirstDeclMatcher().match(
-AST1->getASTContext().getTranslationUnitDecl(), Matcher1);
+AST1->getASTContext().getTranslationUnitDecl(), Matcher1,
+AssertNonNull);
 
 return std::make_tuple(StmtWithASTContext(*S0, AST0->getASTContext()),
StmtWithASTContext(*S1, AST1->getASTContext()));
   }
 
+  template 
+  std::tuple
+  makeStmts(const std::string , const std::string ,
+TestLanguage Lang, const MatcherType ,
+const MatcherType ) {
+return makeStmts(SrcCode0, SrcCode1, Lang, Matcher0, Matcher1, true);
+  }
+
   // Get a pair of node pointers into the synthesized AST from the given code
   // snippets. The same matcher is used for both snippets.
   template 
@@ -1598,6 +1609,73 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, unsigned int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSignsDiffer) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0, int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprOrderDiffers) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, float: 1, unsigned int: 0)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprDependentResultSame) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr(), genericSelectionExpr(), false);
+  

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-14 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder added a comment.

In D92600#2453124 , @tmroeder wrote:

> Change the DeclMatcher.h test code to expose the ability to not assert on 
> null Nodes from a match.
>
> This allows the tests for GenericSelectionExpr to handle the null case on 
> Windows themselves without crashing, and to still work correctly and test the 
> appropriate functionality on Linux.

It looks like this change finally fixed the Windows tests that I was breaking. 
However, I'm now touching new parts of the test framework to make this work. 
Please take a look at and let me know what you think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-14 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 311706.
tmroeder added a comment.

Change the DeclMatcher.h test code to expose the ability to not assert on null 
Nodes from a match.

This allows the tests for GenericSelectionExpr to handle the null case on 
Windows themselves without crashing, and to still work correctly and test the 
appropriate functionality on Linux.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.cpp
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/test/ASTMerge/generic-selection-expr/test.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/DeclMatcher.h
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -985,6 +985,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -92,23 +92,34 @@
 
   // Get a pair of node pointers into the synthesized AST from the given code
   // snippets. To determine the returned node, a separate matcher is specified
-  // for both snippets. The first matching node is returned.
+  // for both snippets. The first matching node is returned. AssertNonNull
+  // controls whether or not to assert that the return nodes are not null.
   template 
   std::tuple
   makeStmts(const std::string , const std::string ,
 TestLanguage Lang, const MatcherType ,
-const MatcherType ) {
+const MatcherType , bool AssertNonNull) {
 makeASTUnits(SrcCode0, SrcCode1, Lang);
 
 Stmt *S0 = FirstDeclMatcher().match(
-AST0->getASTContext().getTranslationUnitDecl(), Matcher0);
+AST0->getASTContext().getTranslationUnitDecl(), Matcher0,
+AssertNonNull);
 Stmt *S1 = FirstDeclMatcher().match(
-AST1->getASTContext().getTranslationUnitDecl(), Matcher1);
+AST1->getASTContext().getTranslationUnitDecl(), Matcher1,
+AssertNonNull);
 
 return std::make_tuple(StmtWithASTContext(*S0, AST0->getASTContext()),
StmtWithASTContext(*S1, AST1->getASTContext()));
   }
 
+  template 
+  std::tuple
+  makeStmts(const std::string , const std::string ,
+TestLanguage Lang, const MatcherType ,
+const MatcherType ) {
+return makeStmts(SrcCode0, SrcCode1, Lang, Matcher0, Matcher1, true);
+  }
+
   // Get a pair of node pointers into the synthesized AST from the given code
   // snippets. The same matcher is used for both snippets.
   template 
@@ -1598,6 +1609,73 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, unsigned int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSignsDiffer) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0, int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprOrderDiffers) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, float: 1, unsigned int: 0)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprDependentResultSame) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, 

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-14 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder added a comment.

In D92600#2452174 , @martong wrote:

> Thanks for the update. I checked it, still looks good to me.
>
> Some notes in parenthesis:
>
>> It looks like the problem is again due to delayed template parsing: the 
>> templatized functions in the test both came out as nullptr. So, I added a 
>> check for nullptr in the case that expects the two values to be different. 
>> The test only tries to compare them if at least one is not null.
>
> Ideally, we should have parameterized structural equivalency tests (similarly 
> to what we have in ASTImporterTest with INSTANTIATE_TEST_CASE_P). The 
> parameters could be the compiler options, i.e. in this case I think we would 
> be able to explicitly emit the delayed template parsing option. Anyway, let's 
> keep that as a future update if we bump into more similar cases.

Thanks! Unfortunately, my fix didn't solve the whole problem on Windows, 
because I forgot to build with assertions when repro'ing the failure, so I 
fixed one problem but not the other. I'm now working on fixing the test under 
assertions as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-14 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.

Thanks for the update. I checked it, still looks good to me.

Some notes in parenthesis:

> It looks like the problem is again due to delayed template parsing: the 
> templatized functions in the test both came out as nullptr. So, I added a 
> check for nullptr in the case that expects the two values to be different. 
> The test only tries to compare them if at least one is not null.

Ideally, we should have parameterized structural equivalency tests (similarly 
to what we have in ASTImporterTest with INSTANTIATE_TEST_CASE_P). The 
parameters could be the compiler options, i.e. in this case I think we would be 
able to explicitly emit the delayed template parsing option. Anyway, let's keep 
that as a future update if we bump into more similar cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-10 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 311081.
tmroeder added a comment.

Removed an unintentionally added extra line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.cpp
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/test/ASTMerge/generic-selection-expr/test.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -985,6 +985,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1598,6 +1598,73 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, unsigned int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSignsDiffer) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0, int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprOrderDiffers) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, float: 1, unsigned int: 0)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprDependentResultSame) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest,
+   GenericSelectionExprDependentResultOrderDiffers) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, float: 1, int: 0);
+  }
+  )",
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+
+  // On Windows, delayed template processing means that both functions become
+  // null ASTs, so the EXPECT_FALSE does not hold. So, this test only checks for
+  // differing ASTs if at least one of the cases is not nullptr.
+  if (std::get<0>(t).S != nullptr || std::get<1>(t).S != nullptr) {
+EXPECT_FALSE(testStructuralMatch(t));
+  }
+}
 TEST_F(StructuralEquivalenceStmtTest, IntegerLiteral) {
   auto t = makeWrappedStmts("1", "1", Lang_CXX03, integerLiteral());
   EXPECT_TRUE(testStructuralMatch(t));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -279,6 +279,15 @@
  functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger());
 }
 
+TEST_P(ImportExpr, ImportGenericSelectionExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+  "void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
+  Lang_C99, "", Lang_C99, Verifier,
+  functionDecl(hasDescendant(genericSelectionExpr(;
+}
+
 TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -1088,6 +1097,36 @@
 

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-10 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 311079.
tmroeder added a comment.

I think I've fixed the Windows tests; I got a build working on a Windows 
machine and was able to debug.

It looks like the problem is again due to delayed template parsing: the 
templatized functions in the test both came out as nullptr. So, I added a check 
for nullptr in the case that expects the two values to be different. The test 
only tries to compare them if at least one is not null.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.cpp
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/test/ASTMerge/generic-selection-expr/test.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -985,6 +985,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1355,6 +1355,7 @@
   Lang_CXX03, classTemplateSpecializationDecl(hasName("Primary")));
   EXPECT_FALSE(testStructuralMatch(t));
 }
+
 struct StructuralEquivalenceCacheTest : public StructuralEquivalenceTest {
   llvm::DenseSet> NonEquivalentDecls;
 
@@ -1598,6 +1599,73 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, unsigned int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSignsDiffer) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0, int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprOrderDiffers) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, float: 1, unsigned int: 0)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprDependentResultSame) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest,
+   GenericSelectionExprDependentResultOrderDiffers) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, float: 1, int: 0);
+  }
+  )",
+  R"(
+  template 
+  void f() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+
+  // On Windows, delayed template processing means that both functions become
+  // null ASTs, so the EXPECT_FALSE does not hold. So, this test only checks for
+  // differing ASTs if at least one of the cases is not nullptr.
+  if (std::get<0>(t).S != nullptr || std::get<1>(t).S != nullptr) {
+EXPECT_FALSE(testStructuralMatch(t));
+  }
+}
 TEST_F(StructuralEquivalenceStmtTest, IntegerLiteral) {
   auto t = makeWrappedStmts("1", "1", Lang_CXX03, integerLiteral());
   EXPECT_TRUE(testStructuralMatch(t));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- 

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-10 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 310974.
tmroeder added a comment.

Rebased to the latest head version.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.cpp
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/test/ASTMerge/generic-selection-expr/test.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -985,6 +985,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1355,6 +1355,49 @@
   Lang_CXX03, classTemplateSpecializationDecl(hasName("Primary")));
   EXPECT_FALSE(testStructuralMatch(t));
 }
+
+TEST_F(StructuralEquivalenceTemplateTest,
+   GenericSelectionExprDependentResultSame) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceTemplateTest,
+   GenericSelectionExprDependentResultOrderDiffers) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, float: 1, int: 0);
+  }
+  )",
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 struct StructuralEquivalenceCacheTest : public StructuralEquivalenceTest {
   llvm::DenseSet> NonEquivalentDecls;
 
@@ -1598,6 +1641,27 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, unsigned int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSignsDiffer) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0, int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprOrderDiffers) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, float: 1, unsigned int: 0)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceStmtTest, IntegerLiteral) {
   auto t = makeWrappedStmts("1", "1", Lang_CXX03, integerLiteral());
   EXPECT_TRUE(testStructuralMatch(t));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -279,6 +279,15 @@
  functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger());
 }
 
+TEST_P(ImportExpr, ImportGenericSelectionExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+  "void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
+  Lang_C99, "", Lang_C99, Verifier,
+  functionDecl(hasDescendant(genericSelectionExpr(;
+}
+
 TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -1088,6 +1097,36 @@
 

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-10 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder added a comment.

In D92600#2445612 , @martong wrote:

> I wouldn't worry much about the `ASTMerge` tests, those are mostly legacy and 
> not actively used nowadays. (At one point we were thinking even to remove 
> them because we could got rid of the `ASTMergeAction` which is exclusively 
> used for testing.)
> The main test infrastructure for the ASTImporter is in the `unittests`. Those 
> tests are exercised even with `-fdelayed-template-parsing` and with 
> `-fms-compatibility`. So I am fine with marking the ASTMerge tests with XFAIL 
> on windows.

Sorry for the confusion: I uploaded a change to try to fix the real test 
failure and there turned out to be a clang-format problem in my ASTMerge tests 
as well. The problems I was referring to were not in ASTMerge but rather from 
the unit tests in a previous diff: 
https://buildkite.com/llvm-project/premerge-checks/builds/19205#4f1d9b0a-16bf-401d-b07e-cceb29612fd0

Is there a way to mark unit tests as failing on a particular architecture?

The answer might not matter, because I've moved those unit tests into a 
different unit-test class, one that only has templates, and I hope that that 
means it will work correctly or be skipped correct in cases where template 
processing is a problem.

I haven't so far been able to get my Windows box to build LLVM (still working 
through some problems like atlbase.h), so I'll have to wait for the CI to tell 
me if x64 windows works with the diff I just uploaded: it fixes the trivial 
clang-format problem in the ASTMerge tests and it keeps the Structural 
Equivalence unit tests in the unit-test class I just mentioned.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-10 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 310930.
tmroeder added a comment.

Fixed a formatting problem brought up by clang-format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.cpp
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/test/ASTMerge/generic-selection-expr/test.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -985,6 +985,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1355,6 +1355,49 @@
   Lang_CXX03, classTemplateSpecializationDecl(hasName("Primary")));
   EXPECT_FALSE(testStructuralMatch(t));
 }
+
+TEST_F(StructuralEquivalenceTemplateTest,
+   GenericSelectionExprDependentResultSame) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceTemplateTest,
+   GenericSelectionExprDependentResultOrderDiffers) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, float: 1, int: 0);
+  }
+  )",
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 struct StructuralEquivalenceCacheTest : public StructuralEquivalenceTest {
   llvm::DenseSet> NonEquivalentDecls;
 
@@ -1598,6 +1641,27 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, unsigned int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSignsDiffer) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0, int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprOrderDiffers) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, float: 1, unsigned int: 0)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceStmtTest, IntegerLiteral) {
   auto t = makeWrappedStmts("1", "1", Lang_CXX03, integerLiteral());
   EXPECT_TRUE(testStructuralMatch(t));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -279,6 +279,15 @@
  functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger());
 }
 
+TEST_P(ImportExpr, ImportGenericSelectionExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+  "void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
+  Lang_C99, "", Lang_C99, Verifier,
+  functionDecl(hasDescendant(genericSelectionExpr(;
+}
+
 TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -1088,6 +1097,36 @@
 

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-10 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

I wouldn't worry much about the `ASTMerge` tests, those are mostly legacy and 
not actively used nowadays. (At one point we were thinking even to remove them 
because we could got rid of the `ASTMergeAction` which is exclusively used for 
testing.)
The main test infrastructure for the ASTImporter is in the `unittests`. Those 
tests are exercised even with `-fdelayed-template-parsing` and with 
`-fms-compatibility`. So I am fine with marking the ASTMerge tests with XFAIL 
on windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D92600#2443716 , @tmroeder wrote:

> @aaron.ballman It looks like those template tests fail on x64 windows; this 
> is a problem that came up with D58292  as 
> well. It ended up getting rolled back because template-based tests failed on 
> windows, and I had to remove the tests and resubmit.
>
> I'm not sure what the right way is to fix these tests: skip them on Windows? 
> If so, then can you please tell me how to do that?

Looking at the changes you made, I'm not certain why one test would work and 
one test would fail -- however, the usual issue with template tests on Windows 
is that the default behavior on Windows is to match the MSVC template behavior 
and so you sometimes need to pass `-fno-delayed-template-parsing` to those 
tests to get the same behavior as on other platforms.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-10 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
Herald added a subscriber: rnkovacs.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-09 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 310701.
tmroeder added a comment.

Moved the result-dependent tests into a different test class, one that 
explicitly uses templates already.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.cpp
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/test/ASTMerge/generic-selection-expr/test.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -985,6 +985,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1355,6 +1355,49 @@
   Lang_CXX03, classTemplateSpecializationDecl(hasName("Primary")));
   EXPECT_FALSE(testStructuralMatch(t));
 }
+
+TEST_F(StructuralEquivalenceTemplateTest,
+   GenericSelectionExprDependentResultSame) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceTemplateTest,
+   GenericSelectionExprDependentResultOrderDiffers) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, float: 1, int: 0);
+  }
+  )",
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 struct StructuralEquivalenceCacheTest : public StructuralEquivalenceTest {
   llvm::DenseSet> NonEquivalentDecls;
 
@@ -1598,6 +1641,27 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, unsigned int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSignsDiffer) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0, int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprOrderDiffers) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, float: 1, unsigned int: 0)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceStmtTest, IntegerLiteral) {
   auto t = makeWrappedStmts("1", "1", Lang_CXX03, integerLiteral());
   EXPECT_TRUE(testStructuralMatch(t));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -279,6 +279,15 @@
  functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger());
 }
 
+TEST_P(ImportExpr, ImportGenericSelectionExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+  "void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
+  Lang_C99, "", Lang_C99, Verifier,
+  functionDecl(hasDescendant(genericSelectionExpr(;
+}
+
 TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
   MatchVerifier Verifier;
   testImport(

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-09 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder added a comment.

@aaron.ballman It looks like those template tests fail on x64 windows; this is 
a problem that came up with D58292  as well. 
It ended up getting rolled back because template-based tests failed on windows, 
and I had to remove the tests and resubmit.

I'm not sure what the right way is to fix these tests: skip them on Windows? If 
so, then can you please tell me how to do that?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

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

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-08 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder marked 2 inline comments as done.
tmroeder added inline comments.



Comment at: clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c:1
+void f() {
+  int x;

aaron.ballman wrote:
> Should we also have a C++ test for a result-dependent use of _Generic? (We 
> support use of _Generic in C++ as an extension.)
Added in a new file test.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-08 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 310394.
tmroeder edited the summary of this revision.
tmroeder added a comment.

Added C++ tests for result-dependent uses, and added that fact to the 
description as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.cpp
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/test/ASTMerge/generic-selection-expr/test.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -985,6 +985,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1598,6 +1598,68 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, unsigned int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSignsDiffer) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0, int: 0, float: 1)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprOrderDiffers) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, float: 1, unsigned int: 0)", Lang_C99,
+genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprDependentResultSame) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest,
+   GenericSelectionExprDependentResultOrderDiffers) {
+  auto t = makeStmts(
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, float: 1, int: 0);
+  }
+  )",
+  R"(
+  template 
+  void wrapped() {
+T x;
+(void)_Generic(x, int: 0, float: 1);
+  }
+  )",
+  Lang_CXX03, genericSelectionExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceStmtTest, IntegerLiteral) {
   auto t = makeWrappedStmts("1", "1", Lang_CXX03, integerLiteral());
   EXPECT_TRUE(testStructuralMatch(t));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -279,6 +279,15 @@
  functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger());
 }
 
+TEST_P(ImportExpr, ImportGenericSelectionExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+  "void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
+  Lang_C99, "", Lang_C99, Verifier,
+  functionDecl(hasDescendant(genericSelectionExpr(;
+}
+
 TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -1088,6 +1097,36 @@
 ToChooseExpr->isConditionDependent());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportGenericSelectionExpr) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"(
+  int 

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2366
+/// Matches C11 _Generic expression.
+extern const internal::VariadicDynCastAllOfMatcher
+genericSelectionExpr;

tmroeder wrote:
> aaron.ballman wrote:
> > Do we have a use case for adding this as an AST matcher? For instance, one 
> > of the first things I'd want to do with such a matcher is traverse down to 
> > the association list, but I don't think that's possible currently. Should 
> > we add all of the AST functionality or just wait until there's a concrete 
> > use case and add the AST matchers bits at that point?
> I mostly did this because that's what I did in the previous case from Feb 
> 2019: reviews.llvm.org/D58292, for ChooseExpr, and I was cribbing off my old 
> code.
> 
> However, on further reflection, I remembered that this patch actually removes 
> a case that was locally defining this matcher already: see the removed lines 
> in clang/lib/Analysis/ExprMutationAnalyzer.cpp in this patch. So, I think 
> that is enough of a case for adding this.
Okay, fair enough. Thanks!



Comment at: clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c:1
+void f() {
+  int x;

Should we also have a C++ test for a result-dependent use of _Generic? (We 
support use of _Generic in C++ as an extension.)



Comment at: clang/unittests/AST/StructuralEquivalenceTest.cpp:1601
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",

Should we add a structural equivalence test for a dependent result type in C++?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-07 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 310050.
tmroeder added a comment.

Fixed the clang-tidy warning as suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -985,6 +985,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1598,6 +1598,27 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, unsigned int: 0, float: 1)", Lang_C99,
+fallbackExprMatcher());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSignsDiffer) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0, int: 0, float: 1)", Lang_C99,
+fallbackExprMatcher());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprOrderDiffers) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, float: 1, unsigned int: 0)", Lang_C99,
+fallbackExprMatcher());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceStmtTest, IntegerLiteral) {
   auto t = makeWrappedStmts("1", "1", Lang_CXX03, integerLiteral());
   EXPECT_TRUE(testStructuralMatch(t));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -279,6 +279,15 @@
  functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger());
 }
 
+TEST_P(ImportExpr, ImportGenericSelectionExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+  "void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
+  Lang_C99, "", Lang_C99, Verifier,
+  functionDecl(hasDescendant(genericSelectionExpr(;
+}
+
 TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -1088,6 +1097,36 @@
 ToChooseExpr->isConditionDependent());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportGenericSelectionExpr) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"(
+  int declToImport() {
+int x;
+return _Generic(x, int: 0, default: 1);
+  }
+  )",
+  Lang_C99, "", Lang_C99);
+
+  auto ToResults =
+  match(genericSelectionExpr().bind("expr"), To->getASTContext());
+  auto FromResults =
+  match(genericSelectionExpr().bind("expr"), From->getASTContext());
+
+  const GenericSelectionExpr *FromGenericSelectionExpr =
+  selectFirst("expr", FromResults);
+  ASSERT_TRUE(FromGenericSelectionExpr);
+
+  const GenericSelectionExpr *ToGenericSelectionExpr =
+  selectFirst("expr", ToResults);
+  ASSERT_TRUE(ToGenericSelectionExpr);
+
+  EXPECT_EQ(FromGenericSelectionExpr->isResultDependent(),
+ToGenericSelectionExpr->isResultDependent());
+  EXPECT_EQ(FromGenericSelectionExpr->getResultIndex(),
+ToGenericSelectionExpr->getResultIndex());
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ImportFunctionWithBackReferringParameter) {
   Decl *From, *To;
Index: clang/test/ASTMerge/generic-selection-expr/test.c
===
--- /dev/null
+++ clang/test/ASTMerge/generic-selection-expr/test.c
@@ 

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-07 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 310047.
tmroeder added a comment.

Added structural equivalence and a few tests for it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -985,6 +985,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1598,6 +1598,27 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSame) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, unsigned int: 0, float: 1)", Lang_C99,
+fallbackExprMatcher());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprSignsDiffer) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0, int: 0, float: 1)", Lang_C99,
+fallbackExprMatcher());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, GenericSelectionExprOrderDiffers) {
+  auto t = makeWrappedStmts("_Generic(0u, unsigned int: 0, float: 1)",
+"_Generic(0u, float: 1, unsigned int: 0)", Lang_C99,
+fallbackExprMatcher());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceStmtTest, IntegerLiteral) {
   auto t = makeWrappedStmts("1", "1", Lang_CXX03, integerLiteral());
   EXPECT_TRUE(testStructuralMatch(t));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -279,6 +279,15 @@
  functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger());
 }
 
+TEST_P(ImportExpr, ImportGenericSelectionExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+  "void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
+  Lang_C99, "", Lang_C99, Verifier,
+  functionDecl(hasDescendant(genericSelectionExpr(;
+}
+
 TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -1088,6 +1097,36 @@
 ToChooseExpr->isConditionDependent());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportGenericSelectionExpr) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"(
+  int declToImport() {
+int x;
+return _Generic(x, int: 0, default: 1);
+  }
+  )",
+  Lang_C99, "", Lang_C99);
+
+  auto ToResults =
+  match(genericSelectionExpr().bind("expr"), To->getASTContext());
+  auto FromResults =
+  match(genericSelectionExpr().bind("expr"), From->getASTContext());
+
+  const GenericSelectionExpr *FromGenericSelectionExpr =
+  selectFirst("expr", FromResults);
+  ASSERT_TRUE(FromGenericSelectionExpr);
+
+  const GenericSelectionExpr *ToGenericSelectionExpr =
+  selectFirst("expr", ToResults);
+  ASSERT_TRUE(ToGenericSelectionExpr);
+
+  EXPECT_EQ(FromGenericSelectionExpr->isResultDependent(),
+ToGenericSelectionExpr->isResultDependent());
+  EXPECT_EQ(FromGenericSelectionExpr->getResultIndex(),
+ToGenericSelectionExpr->getResultIndex());
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ImportFunctionWithBackReferringParameter) {
   Decl *From, *To;
Index: clang/test/ASTMerge/generic-selection-expr/test.c
===
--- /dev/null
+++ 

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-07 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2366
+/// Matches C11 _Generic expression.
+extern const internal::VariadicDynCastAllOfMatcher
+genericSelectionExpr;

aaron.ballman wrote:
> Do we have a use case for adding this as an AST matcher? For instance, one of 
> the first things I'd want to do with such a matcher is traverse down to the 
> association list, but I don't think that's possible currently. Should we add 
> all of the AST functionality or just wait until there's a concrete use case 
> and add the AST matchers bits at that point?
I mostly did this because that's what I did in the previous case from Feb 2019: 
reviews.llvm.org/D58292, for ChooseExpr, and I was cribbing off my old code.

However, on further reflection, I remembered that this patch actually removes a 
case that was locally defining this matcher already: see the removed lines in 
clang/lib/Analysis/ExprMutationAnalyzer.cpp in this patch. So, I think that is 
enough of a case for adding this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:2366
+/// Matches C11 _Generic expression.
+extern const internal::VariadicDynCastAllOfMatcher
+genericSelectionExpr;

Do we have a use case for adding this as an AST matcher? For instance, one of 
the first things I'd want to do with such a matcher is traverse down to the 
association list, but I don't think that's possible currently. Should we add 
all of the AST functionality or just wait until there's a concrete use case and 
add the AST matchers bits at that point?



Comment at: clang/lib/AST/ASTImporter.cpp:6509
+  auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
+  auto ToControllingExpr = importChecked(Err, E->getControllingExpr());
+  auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-04 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

Having the comparison code would be nice. The custom types in the associated 
types aren't compared by the generic code, so an overload like this in the 
`StmtComparer` class should be enough:

  bool IsStmtEquivalent(const GenericSelectionExpr *E1, const 
GenericSelectionExpr *E2) {
for (auto Pair : zip_longest(E1->getAssocTypeSourceInfos(),
 E2->getAssocTypeSourceInfos())) {
  Optional Child1 = std::get<0>(Pair);
  Optional Child2 = std::get<1>(Pair);
  // Different number of associated types.
  if (!Child1 || !Child2)
return false;
  
  if (!IsStructurallyEquivalent(Context, (*Child1)->getType(),
(*Child2)->getType()))
return false;
}
return true;
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-04 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D92600#2433263 , @martong wrote:

> It might be worth to extend StmtComparer 
> 
>  as well with this Expr. I mean, probably two selections exprs should be 
> considered equal if their assoc exprs are equal too...

@teemperor , WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-04 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

It might be worth to extend StmtComparer 

 as well with this Expr. I mean, probably two selections exprs should be 
considered equal if their assoc exprs are equal too...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-03 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 309406.
tmroeder added a comment.

Renamed context to ToCtx as suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -985,6 +985,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -279,6 +279,15 @@
  functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger());
 }
 
+TEST_P(ImportExpr, ImportGenericSelectionExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+  "void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
+  Lang_C99, "", Lang_C99, Verifier,
+  functionDecl(hasDescendant(genericSelectionExpr(;
+}
+
 TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -1088,6 +1097,36 @@
 ToChooseExpr->isConditionDependent());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportGenericSelectionExpr) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"(
+  int declToImport() {
+int x;
+return _Generic(x, int: 0, default: 1);
+  }
+  )",
+  Lang_C99, "", Lang_C99);
+
+  auto ToResults =
+  match(genericSelectionExpr().bind("expr"), To->getASTContext());
+  auto FromResults =
+  match(genericSelectionExpr().bind("expr"), From->getASTContext());
+
+  const GenericSelectionExpr *FromGenericSelectionExpr =
+  selectFirst("expr", FromResults);
+  ASSERT_TRUE(FromGenericSelectionExpr);
+
+  const GenericSelectionExpr *ToGenericSelectionExpr =
+  selectFirst("expr", ToResults);
+  ASSERT_TRUE(ToGenericSelectionExpr);
+
+  EXPECT_EQ(FromGenericSelectionExpr->isResultDependent(),
+ToGenericSelectionExpr->isResultDependent());
+  EXPECT_EQ(FromGenericSelectionExpr->getResultIndex(),
+ToGenericSelectionExpr->getResultIndex());
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ImportFunctionWithBackReferringParameter) {
   Decl *From, *To;
Index: clang/test/ASTMerge/generic-selection-expr/test.c
===
--- /dev/null
+++ clang/test/ASTMerge/generic-selection-expr/test.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -std=c11 -emit-pch -o %t.ast %S/Inputs/generic.c
+// RUN: %clang_cc1 -std=c11 -ast-merge %t.ast -fsyntax-only -verify %s
+// expected-no-diagnostics
+
Index: clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
===
--- /dev/null
+++ clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
@@ -0,0 +1,7 @@
+void f() {
+  int x;
+  float y;
+  _Static_assert(_Generic(x, float: 0, int: 1), "Incorrect semantics of _Generic");
+  _Static_assert(_Generic(y, float: 1, int: 0), "Incorrect semantics of _Generic");
+}
+
Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -95,10 +95,6 @@
   return Node.isPotentiallyEvaluated();
 }
 
-const ast_matchers::internal::VariadicDynCastAllOfMatcher
-genericSelectionExpr;
-
 AST_MATCHER_P(GenericSelectionExpr, hasControllingExpr,
   ast_matchers::internal::Matcher, InnerMatcher) {
   return InnerMatcher.matches(*Node.getControllingExpr(), Finder, Builder);
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -241,6 +241,7 @@
   REGISTER_MATCHER(functionProtoType);
   REGISTER_MATCHER(functionTemplateDecl);
   

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-03 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

`ASTImporter` changes looks good to me.




Comment at: clang/lib/AST/ASTImporter.cpp:6525
+
+  const ASTContext  = Importer.getToContext();
+  if (E->isResultDependent()) {

nitpick `context` -> `ToCtx` to be consistent with other code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

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


[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-03 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder updated this revision to Diff 309344.
tmroeder edited the summary of this revision.
tmroeder added a comment.

Fix a typo in the summary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -985,6 +985,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -279,6 +279,15 @@
  functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger());
 }
 
+TEST_P(ImportExpr, ImportGenericSelectionExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+  "void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
+  Lang_C99, "", Lang_C99, Verifier,
+  functionDecl(hasDescendant(genericSelectionExpr(;
+}
+
 TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -1088,6 +1097,36 @@
 ToChooseExpr->isConditionDependent());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportGenericSelectionExpr) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"(
+  int declToImport() {
+int x;
+return _Generic(x, int: 0, default: 1);
+  }
+  )",
+  Lang_C99, "", Lang_C99);
+
+  auto ToResults =
+  match(genericSelectionExpr().bind("expr"), To->getASTContext());
+  auto FromResults =
+  match(genericSelectionExpr().bind("expr"), From->getASTContext());
+
+  const GenericSelectionExpr *FromGenericSelectionExpr =
+  selectFirst("expr", FromResults);
+  ASSERT_TRUE(FromGenericSelectionExpr);
+
+  const GenericSelectionExpr *ToGenericSelectionExpr =
+  selectFirst("expr", ToResults);
+  ASSERT_TRUE(ToGenericSelectionExpr);
+
+  EXPECT_EQ(FromGenericSelectionExpr->isResultDependent(),
+ToGenericSelectionExpr->isResultDependent());
+  EXPECT_EQ(FromGenericSelectionExpr->getResultIndex(),
+ToGenericSelectionExpr->getResultIndex());
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ImportFunctionWithBackReferringParameter) {
   Decl *From, *To;
Index: clang/test/ASTMerge/generic-selection-expr/test.c
===
--- /dev/null
+++ clang/test/ASTMerge/generic-selection-expr/test.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -std=c11 -emit-pch -o %t.ast %S/Inputs/generic.c
+// RUN: %clang_cc1 -std=c11 -ast-merge %t.ast -fsyntax-only -verify %s
+// expected-no-diagnostics
+
Index: clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
===
--- /dev/null
+++ clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
@@ -0,0 +1,7 @@
+void f() {
+  int x;
+  float y;
+  _Static_assert(_Generic(x, float: 0, int: 1), "Incorrect semantics of _Generic");
+  _Static_assert(_Generic(y, float: 1, int: 0), "Incorrect semantics of _Generic");
+}
+
Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -95,10 +95,6 @@
   return Node.isPotentiallyEvaluated();
 }
 
-const ast_matchers::internal::VariadicDynCastAllOfMatcher
-genericSelectionExpr;
-
 AST_MATCHER_P(GenericSelectionExpr, hasControllingExpr,
   ast_matchers::internal::Matcher, InnerMatcher) {
   return InnerMatcher.matches(*Node.getControllingExpr(), Finder, Builder);
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -241,6 +241,7 @@
   REGISTER_MATCHER(functionProtoType);
   REGISTER_MATCHER(functionTemplateDecl);

[PATCH] D92600: [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-03 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder created this revision.
tmroeder added reviewers: aaron.ballman, klimek.
Herald added subscribers: teemperor, martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
tmroeder requested review of this revision.
Herald added a project: clang.

This allows ASTs to be merged when they contain GenericSelectionExpr
nodes (this is _Generic from C11). This is needed, for example, for
cross-CTU analysis of C code that makes use of _Generic, like the Linux
kernel.

The node is already supported in the AST, but it didn't have a matcher
in ASTMatchers. So, this change adds the matcher and adds support to
ASTImporter.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92600

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
  clang/test/ASTMerge/generic-selection-expr/test.c
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -985,6 +985,11 @@
   EXPECT_TRUE(matches("int* i = __null;", gnuNullExpr()));
 }
 
+TEST_P(ASTMatchersTest, GenericSelectionExpr) {
+  EXPECT_TRUE(matches("void f() { (void)_Generic(1, int: 1, float: 2.0); }",
+  genericSelectionExpr()));
+}
+
 TEST_P(ASTMatchersTest, AtomicExpr) {
   EXPECT_TRUE(matches("void foo() { int *ptr; __atomic_load_n(ptr, 1); }",
   atomicExpr()));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -279,6 +279,15 @@
  functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger());
 }
 
+TEST_P(ImportExpr, ImportGenericSelectionExpr) {
+  MatchVerifier Verifier;
+
+  testImport(
+  "void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
+  Lang_C99, "", Lang_C99, Verifier,
+  functionDecl(hasDescendant(genericSelectionExpr(;
+}
+
 TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -1088,6 +1097,36 @@
 ToChooseExpr->isConditionDependent());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportGenericSelectionExpr) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"(
+  int declToImport() {
+int x;
+return _Generic(x, int: 0, default: 1);
+  }
+  )",
+  Lang_C99, "", Lang_C99);
+
+  auto ToResults =
+  match(genericSelectionExpr().bind("expr"), To->getASTContext());
+  auto FromResults =
+  match(genericSelectionExpr().bind("expr"), From->getASTContext());
+
+  const GenericSelectionExpr *FromGenericSelectionExpr =
+  selectFirst("expr", FromResults);
+  ASSERT_TRUE(FromGenericSelectionExpr);
+
+  const GenericSelectionExpr *ToGenericSelectionExpr =
+  selectFirst("expr", ToResults);
+  ASSERT_TRUE(ToGenericSelectionExpr);
+
+  EXPECT_EQ(FromGenericSelectionExpr->isResultDependent(),
+ToGenericSelectionExpr->isResultDependent());
+  EXPECT_EQ(FromGenericSelectionExpr->getResultIndex(),
+ToGenericSelectionExpr->getResultIndex());
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase,
ImportFunctionWithBackReferringParameter) {
   Decl *From, *To;
Index: clang/test/ASTMerge/generic-selection-expr/test.c
===
--- /dev/null
+++ clang/test/ASTMerge/generic-selection-expr/test.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -std=c11 -emit-pch -o %t.ast %S/Inputs/generic.c
+// RUN: %clang_cc1 -std=c11 -ast-merge %t.ast -fsyntax-only -verify %s
+// expected-no-diagnostics
+
Index: clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
===
--- /dev/null
+++ clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
@@ -0,0 +1,7 @@
+void f() {
+  int x;
+  float y;
+  _Static_assert(_Generic(x, float: 0, int: 1), "Incorrect semantics of _Generic");
+  _Static_assert(_Generic(y, float: 1, int: 0), "Incorrect semantics of _Generic");
+}
+
Index: clang/lib/Analysis/ExprMutationAnalyzer.cpp
===
--- clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -95,10 +95,6 @@
   return Node.isPotentiallyEvaluated();
 }
 
-const ast_matchers::internal::VariadicDynCastAllOfMatcher
-genericSelectionExpr;
-
 AST_MATCHER_P(GenericSelectionExpr, hasControllingExpr,