r354832 - [ASTImporter] Add support for importing ChooseExpr AST nodes.

2019-02-25 Thread Tom Roeder via cfe-commits
Author: tmroeder
Date: Mon Feb 25 15:24:58 2019
New Revision: 354832

URL: http://llvm.org/viewvc/llvm-project?rev=354832&view=rev
Log:
[ASTImporter] Add support for importing ChooseExpr AST nodes.

Summary:
This allows ASTs to be merged when they contain ChooseExpr (the GNU
__builtin_choose_expr construction). This is needed, for example, for
cross-CTU analysis of C code that makes use of __builtin_choose_expr.

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.

Reviewers: shafik, a_sidorin, martong, aaron.ballman

Subscribers: aaron.ballman, rnkovacs, jdoerfert, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/ASTMerge/choose-expr/
cfe/trunk/test/ASTMerge/choose-expr/Inputs/
cfe/trunk/test/ASTMerge/choose-expr/Inputs/choose.c
cfe/trunk/test/ASTMerge/choose-expr/test.c
Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/AST/ASTImporterTest.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=354832&r1=354831&r2=354832&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Mon Feb 25 15:24:58 2019
@@ -788,6 +788,11 @@ Example matches 'a', L'a'
 
 
 
+MatcherStmt>chooseExprMatcherChooseExpr>...
+Matches GNU 
__builtin_choose_expr.
+
+
+
 MatcherStmt>compoundLiteralExprMatcherCompoundLiteralExpr>...
 Matches 
compound (i.e. non-scalar) literals
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=354832&r1=354831&r2=354832&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Mon Feb 25 15:24:58 2019
@@ -2158,6 +2158,10 @@ extern const internal::VariadicDynCastAl
 extern const internal::VariadicDynCastAllOfMatcher
 cxxNullPtrLiteralExpr;
 
+/// Matches GNU __builtin_choose_expr.
+extern const internal::VariadicDynCastAllOfMatcher
+chooseExpr;
+
 /// Matches GNU __null expression.
 extern const internal::VariadicDynCastAllOfMatcher
 gnuNullExpr;

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=354832&r1=354831&r2=354832&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Feb 25 15:24:58 2019
@@ -552,6 +552,7 @@ namespace clang {
 // Importing expressions
 ExpectedStmt VisitExpr(Expr *E);
 ExpectedStmt VisitVAArgExpr(VAArgExpr *E);
+ExpectedStmt VisitChooseExpr(ChooseExpr *E);
 ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E);
 ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E);
 ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E);
@@ -6135,6 +6136,33 @@ ExpectedStmt ASTNodeImporter::VisitVAArg
   E->isMicrosoftABI());
 }
 
+ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) {
+  auto Imp = importSeq(E->getCond(), E->getLHS(), E->getRHS(),
+   E->getBuiltinLoc(), E->getRParenLoc(), E->getType());
+  if (!Imp)
+return Imp.takeError();
+
+  Expr *ToCond;
+  Expr *ToLHS;
+  Expr *ToRHS;
+  SourceLocation ToBuiltinLoc, ToRParenLoc;
+  QualType ToType;
+  std::tie(ToCond, ToLHS, ToRHS, ToBuiltinLoc, ToRParenLoc, ToType) = *Imp;
+
+  ExprValueKind VK = E->getValueKind();
+  ExprObjectKind OK = E->getObjectKind();
+
+  bool TypeDependent = ToCond->isTypeDependent();
+  bool ValueDependent = ToCond->isValueDependent();
+
+  // The value of CondIsTrue only matters if the value is not
+  // condition-dependent.
+  bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
+
+  return new (Importer.getToContext())
+  ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
+ ToRParenLoc, CondIsTrue, TypeDependent, ValueDependent);
+}
 
 ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) {
   ExpectedType TypeOrErr = import(E->getType());

Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: 
http://llvm.

r354916 - [ASTImporter] Add support for importing ChooseExpr AST nodes.

2019-02-26 Thread Tom Roeder via cfe-commits
Author: tmroeder
Date: Tue Feb 26 11:26:41 2019
New Revision: 354916

URL: http://llvm.org/viewvc/llvm-project?rev=354916&view=rev
Log:
[ASTImporter] Add support for importing ChooseExpr AST nodes.

Summary:
This allows ASTs to be merged when they contain ChooseExpr (the GNU
__builtin_choose_expr construction). This is needed, for example, for
cross-CTU analysis of C code that makes use of __builtin_choose_expr.

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.

This was originally reviewed and approved in
https://reviews.llvm.org/D58292 and submitted as r354832. It was
reverted in r354839 due to failures on the Windows CI builds.

This version fixes the test failures on Windows, which were caused by
differences in template expansion between versions of clang on different
OSes. The version of clang built with MSVC and running on Windows never
expands the template in the C++ test in ImportExpr.ImportChooseExpr in
clang/unittests/AST/ASTImporter.cpp, but the version on Linux does for
the empty arguments and -fms-compatibility.

So, this version of the patch drops the C++ test for
__builtin_choose_expr, since that version was written to catch
regressions of the logic for isConditionTrue() in the AST import code
for ChooseExpr, and those regressions are also caught by
ASTImporterOptionSpecificTestBase.ImportChooseExpr, which does work on
Windows.

Reviewers: shafik, a_sidorin, martong, aaron.ballman, rnk, a.sidorin

Subscribers: cfe-commits, jdoerfert, rnkovacs, aaron.ballman

Tags: #clang

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

Added:
cfe/trunk/test/ASTMerge/
cfe/trunk/test/ASTMerge/choose-expr/
cfe/trunk/test/ASTMerge/choose-expr/Inputs/
cfe/trunk/test/ASTMerge/choose-expr/Inputs/choose.c
cfe/trunk/test/ASTMerge/choose-expr/test.c
Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/AST/ASTImporterTest.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=354916&r1=354915&r2=354916&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Tue Feb 26 11:26:41 2019
@@ -788,6 +788,11 @@ Example matches 'a', L'a'
 
 
 
+MatcherStmt>chooseExprMatcherChooseExpr>...
+Matches GNU 
__builtin_choose_expr.
+
+
+
 MatcherStmt>compoundLiteralExprMatcherCompoundLiteralExpr>...
 Matches 
compound (i.e. non-scalar) literals
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=354916&r1=354915&r2=354916&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue Feb 26 11:26:41 2019
@@ -2158,6 +2158,10 @@ extern const internal::VariadicDynCastAl
 extern const internal::VariadicDynCastAllOfMatcher
 cxxNullPtrLiteralExpr;
 
+/// Matches GNU __builtin_choose_expr.
+extern const internal::VariadicDynCastAllOfMatcher
+chooseExpr;
+
 /// Matches GNU __null expression.
 extern const internal::VariadicDynCastAllOfMatcher
 gnuNullExpr;

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=354916&r1=354915&r2=354916&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Feb 26 11:26:41 2019
@@ -552,6 +552,7 @@ namespace clang {
 // Importing expressions
 ExpectedStmt VisitExpr(Expr *E);
 ExpectedStmt VisitVAArgExpr(VAArgExpr *E);
+ExpectedStmt VisitChooseExpr(ChooseExpr *E);
 ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E);
 ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E);
 ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E);
@@ -6135,6 +6136,33 @@ ExpectedStmt ASTNodeImporter::VisitVAArg
   E->isMicrosoftABI());
 }
 
+ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) {
+  auto Imp = importSeq(E->getCond(), E->getLHS(), E->getRHS(),
+   E->getBuiltinLoc(), E->getRParenLoc(), E->getType());
+  if (!Imp)
+return Imp.takeEr

[clang-tools-extra] r367071 - [clang-tidy] Add a module for the Linux kernel.

2019-07-25 Thread Tom Roeder via cfe-commits
Author: tmroeder
Date: Thu Jul 25 15:32:50 2019
New Revision: 367071

URL: http://llvm.org/viewvc/llvm-project?rev=367071&view=rev
Log:
[clang-tidy] Add a module for the Linux kernel.

Summary:
Now that clang is going to be able to build the Linux kernel again on
x86, and we have gen_compile_commands.py upstream for generating
compile_commands.json, clang-tidy can be used on the Linux kernel
source.

To that end, this commit adds a new clang-tidy module to be used for
checks specific to Linux kernel source. The Linux kernel follows its own
style of C, and it will be useful to separate those checks into their
own module.

This also adds an initial check that makes sure that return values from
the kernel error functions like PTR_ERR and ERR_PTR are checked. It also
makes sure that any functions that directly return values from these
functions are checked.

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

Tags: #clang, #clang-tools-extra

Reviewers: aaron.ballman, alexfh, hokein, JonasToth

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

Added:
clang-tools-extra/trunk/clang-tidy/linuxkernel/
clang-tools-extra/trunk/clang-tidy/linuxkernel/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/linuxkernel/MustCheckErrsCheck.cpp
clang-tools-extra/trunk/clang-tidy/linuxkernel/MustCheckErrsCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
clang-tools-extra/trunk/test/clang-tidy/linuxkernel-must-check-errs.c
Modified:
clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h
clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=367071&r1=367070&r2=367071&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Thu Jul 25 15:32:50 2019
@@ -44,6 +44,7 @@ add_subdirectory(cppcoreguidelines)
 add_subdirectory(fuchsia)
 add_subdirectory(google)
 add_subdirectory(hicpp)
+add_subdirectory(linuxkernel)
 add_subdirectory(llvm)
 add_subdirectory(misc)
 add_subdirectory(modernize)

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h?rev=367071&r1=367070&r2=367071&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyForceLinker.h Thu Jul 25 
15:32:50 2019
@@ -35,6 +35,11 @@ extern volatile int BugproneModuleAnchor
 static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination =
 BugproneModuleAnchorSource;
 
+// This anchor is used to force the linker to link the LinuxKernelModule.
+extern volatile int LinuxKernelModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED LinuxKernelModuleAnchorDestination =
+LinuxKernelModuleAnchorSource;
+
 // This anchor is used to force the linker to link the LLVMModule.
 extern volatile int LLVMModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =

Added: clang-tools-extra/trunk/clang-tidy/linuxkernel/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/linuxkernel/CMakeLists.txt?rev=367071&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/linuxkernel/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/clang-tidy/linuxkernel/CMakeLists.txt Thu Jul 25 
15:32:50 2019
@@ -0,0 +1,14 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_library(clangTidyLinuxKernelModule
+  LinuxKernelTidyModule.cpp
+  MustCheckErrsCheck.cpp
+
+  LINK_LIBS
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangLex
+  clangTidy
+  clangTidyUtils
+  )

Added: clang-tools-extra/trunk/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp?rev=367071&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/linuxkernel/LinuxKernelTidyModule.cpp 
Thu Jul 25 15:32:50 2019
@@ -0,0 +1,37 @@
+//===--- LinuxKernelTidyModule.cpp - 
clang-tidy===//
+//
+// Part of the LLVM Project, under the Apache License v2.

[clang-tools-extra] r367333 - [clang-tidy] Fix the documentation for linuxkernel-must-use-errs.

2019-07-30 Thread Tom Roeder via cfe-commits
Author: tmroeder
Date: Tue Jul 30 09:49:28 2019
New Revision: 367333

URL: http://llvm.org/viewvc/llvm-project?rev=367333&view=rev
Log:
[clang-tidy] Fix the documentation for linuxkernel-must-use-errs.

Summary:
This changes ReleaseNotes.txt to have the first sentence of the full
documentation from linuxkernel-must-use-errs.rst.

This addresses a comment from the review of rL367071 in
https://reviews.llvm.org/D59963.

Reviewers: Eugene.Zelenko

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=367333&r1=367332&r2=367333&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Tue Jul 30 09:49:28 2019
@@ -71,15 +71,7 @@ Improvements to clang-tidy
   ` check.
 
   Checks Linux kernel code to see if it uses the results from the functions in
-  ``linux/err.h``. Also checks to see if code uses the results from functions 
that
-  directly return a value from one of these error functions.
-
-  This is important in the Linux kernel because ``ERR_PTR``, ``PTR_ERR``,
-  ``IS_ERR``, ``IS_ERR_OR_NULL``, ``ERR_CAST``, and ``PTR_ERR_OR_ZERO`` return
-  values must be checked, since positive pointers and negative error codes are
-  being used in the same context. These functions are marked with
-  ``__attribute__((warn_unused_result))``, but some kernel versions do not have
-  this warning enabled for clang.
+  ``linux/err.h``.
 
 - New :doc:`google-upgrade-googletest-case
   ` check.

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst?rev=367333&r1=367332&r2=367333&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst 
(original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/linuxkernel-must-use-errs.rst 
Tue Jul 30 09:49:28 2019
@@ -3,14 +3,16 @@
 linuxkernel-must-use-errs
 =
 
-Checks for cases where the kernel error functions ``ERR_PTR``,
-``PTR_ERR``, ``IS_ERR``, ``IS_ERR_OR_NULL``, ``ERR_CAST``, and
-``PTR_ERR_OR_ZERO`` are called but the results are not used. These
-functions are marked with ``__attribute__((warn_unused_result))``, but
-the compiler warning for this attribute is not always enabled.
+Checks Linux kernel code to see if it uses the results from the functions in
+``linux/err.h``. Also checks to see if code uses the results from functions 
that
+directly return a value from one of these error functions.
 
-This also checks for unused values returned by functions that return
-``ERR_PTR``.
+This is important in the Linux kernel because ``ERR_PTR``, ``PTR_ERR``,
+``IS_ERR``, ``IS_ERR_OR_NULL``, ``ERR_CAST``, and ``PTR_ERR_OR_ZERO`` return
+values must be checked, since positive pointers and negative error codes are
+being used in the same context. These functions are marked with
+``__attribute__((warn_unused_result))``, but some kernel versions do not have
+this warning enabled for clang.
 
 Examples:
 


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


[clang] f31e9bc - Test commit: add valid punctuation to a comment. NFC.

2020-12-16 Thread Tom Roeder via cfe-commits

Author: Tom Roeder
Date: 2020-12-16T15:33:19-08:00
New Revision: f31e9bcd73eb5f99256a19ae8ed958140ba58a42

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

LOG: Test commit: add valid punctuation to a comment. NFC.

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 9c0a7320e5f2..9374e9316ce8 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8223,7 +8223,7 @@ Expected ASTImporter::Import(Decl *FromD) {
   return make_error(*Error);
 }
 
-// If FromD has some updated flags after last import, apply it
+// If FromD has some updated flags after last import, apply it.
 updateFlags(FromD, ToD);
 // If we encounter a cycle during an import then we save the relevant part
 // of the import path associated to the Decl.



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


[clang] 1844ab7 - [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.

2020-12-16 Thread Tom Roeder via cfe-commits

Author: Tom Roeder
Date: 2020-12-16T15:39:50-08:00
New Revision: 1844ab770cb9380a1896d83b1863b93766ffdf22

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

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

This allows ASTs to be merged when they contain GenericSelectionExpr
nodes (this is _Generic from C11). This is needed, for example, for
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. Additionally, this change adds support for structural
equivalence of _Generic in the AST.

Reviewed By: martong, aaron.ballman

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

Added: 
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

Modified: 
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/unittests/AST/ASTImporterTest.cpp
clang/unittests/AST/StructuralEquivalenceTest.cpp
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 203840c214a2..18acfc48 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -1704,6 +1704,11 @@ Node Matchers
 
 
 
+MatcherStmt>genericSelectionExprMatcherGenericSelectionExpr>...
+Matches C11 
_Generic expression.
+
+
+
 MatcherStmt>gnuNullExprMatcherGNUNullExpr>...
 Matches GNU __null 
expression.
 

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 0da469ea0f78..ba2dd862f171 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2362,6 +2362,10 @@ extern const internal::VariadicDynCastAllOfMatcher
 extern const internal::VariadicDynCastAllOfMatcher
 gnuNullExpr;
 
+/// Matches C11 _Generic expression.
+extern const internal::VariadicDynCastAllOfMatcher
+genericSelectionExpr;
+
 /// Matches atomic builtins.
 /// Example matches __atomic_load_n(ptr, 1)
 /// \code

diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 9374e9316ce8..54816b721a4a 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -577,6 +577,7 @@ namespace clang {
 ExpectedStmt VisitVAArgExpr(VAArgExpr *E);
 ExpectedStmt VisitChooseExpr(ChooseExpr *E);
 ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E);
+ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E);
 ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E);
 ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E);
 ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
@@ -6526,6 +6527,40 @@ ExpectedStmt 
ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) {
   return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
 }
 
+ExpectedStmt
+ASTNodeImporter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
+  Error Err = Error::success();
+  auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
+  auto *ToControllingExpr = importChecked(Err, E->getControllingExpr());
+  auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
+  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
+  if (Err)
+return std::move(Err);
+
+  ArrayRef 
FromAssocTypes(E->getAssocTypeSourceInfos());
+  SmallVector ToAssocTypes(FromAssocTypes.size());
+  if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
+return std::move(Err);
+
+  ArrayRef FromAssocExprs(E->getAssocExprs());
+  SmallVector ToAssocExprs(FromAssocExprs.size());
+  if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
+return std::move(Err);
+
+  const ASTContext &ToCtx = Importer.getToContext();
+  if (E->isResultDependent()) {
+return GenericSelectionExpr::Create(
+ToCtx, ToGenericLoc, ToControllingExpr,
+llvm::makeArrayRef(ToAssocTypes), llvm::makeArrayRef(ToAssocExprs),
+ToDefaultLoc, To

[clang] [StructuralEquivalence] fix crash & improve comparing on GenericSelectionExpr (PR #67458)

2023-09-26 Thread Tom Roeder via cfe-commits


@@ -247,6 +247,20 @@ class StmtComparer {
 
   bool IsStmtEquivalent(const GenericSelectionExpr *E1,
 const GenericSelectionExpr *E2) {
+if (!IsStructurallyEquivalent(Context,

tmroeder wrote:

Could you please add comments to the new checks that explains why they are 
needed?

I don't doubt that they are important, but I haven't touched this code in a 
very long time, and I'm sure that other readers of this code would appreciate 
it.

https://github.com/llvm/llvm-project/pull/67458
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits