[clang] 1a02c96 - Revert "Revert "[clang] Dont print implicit forrange initializer""
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 17 07:51:25 PDT 2022
Author: Kadir Cetinkaya
Date: 2022-06-17T16:51:16+02:00
New Revision: 1a02c963e338100a3000734b91f5956da9b8c95e
URL: https://github.com/llvm/llvm-project/commit/1a02c963e338100a3000734b91f5956da9b8c95e
DIFF: https://github.com/llvm/llvm-project/commit/1a02c963e338100a3000734b91f5956da9b8c95e.diff
LOG: Revert "Revert "[clang] Dont print implicit forrange initializer""
This reverts commit 7aac15d5df6cfa03b802e055b63227a95fa1734e.
Only updates the tests, as these statements are still part of the CFG
and its just the pretty printer policy that changes. Hopefully this
shouldn't affect any analysis.
Added:
Modified:
clang/lib/AST/DeclPrinter.cpp
clang/test/Analysis/auto-obj-dtors-cfg-output.cpp
clang/test/Analysis/scopes-cfg-output.cpp
clang/unittests/AST/DeclPrinterTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index faafe307f03cf..c6a392c9c01b5 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -895,12 +895,15 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) {
Expr *Init = D->getInit();
if (!Policy.SuppressInitializers && Init) {
bool ImplicitInit = false;
- if (CXXConstructExpr *Construct =
- dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
+ if (D->isCXXForRangeDecl()) {
+ // FIXME: We should print the range expression instead.
+ ImplicitInit = true;
+ } else if (CXXConstructExpr *Construct =
+ dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
if (D->getInitStyle() == VarDecl::CallInit &&
!Construct->isListInitialization()) {
ImplicitInit = Construct->getNumArgs() == 0 ||
- Construct->getArg(0)->isDefaultArgument();
+ Construct->getArg(0)->isDefaultArgument();
}
}
if (!ImplicitInit) {
diff --git a/clang/test/Analysis/auto-obj-dtors-cfg-output.cpp b/clang/test/Analysis/auto-obj-dtors-cfg-output.cpp
index 82c86a95792a9..e5397f5678cb5 100644
--- a/clang/test/Analysis/auto-obj-dtors-cfg-output.cpp
+++ b/clang/test/Analysis/auto-obj-dtors-cfg-output.cpp
@@ -1098,7 +1098,7 @@ void test_for_implicit_scope() {
// CHECK-NEXT: 2: [B3.1] (ImplicitCastExpr, LValueToRValue, int *)
// CHECK-NEXT: 3: *[B3.2]
// CHECK-NEXT: 4: [B3.3] (ImplicitCastExpr, LValueToRValue, int)
-// CHECK-NEXT: 5: int n = *__begin1;
+// CHECK-NEXT: 5: int n
// WARNINGS-NEXT: 6: (CXXConstructExpr, class A)
// ANALYZER-NEXT: 6: (CXXConstructExpr, [B3.7], class A)
// CHECK-NEXT: 7: A c;
diff --git a/clang/test/Analysis/scopes-cfg-output.cpp b/clang/test/Analysis/scopes-cfg-output.cpp
index c8212d51f6b24..ef2cac9538163 100644
--- a/clang/test/Analysis/scopes-cfg-output.cpp
+++ b/clang/test/Analysis/scopes-cfg-output.cpp
@@ -834,7 +834,7 @@ void test_for_compound_and_break() {
// CHECK-NEXT: 2: __begin1
// CHECK-NEXT: 3: [B4.2] (ImplicitCastExpr, LValueToRValue, class A *)
// CHECK-NEXT: 4: *[B4.3]
-// CHECK-NEXT: 5: auto &i = *__begin1;
+// CHECK-NEXT: 5: auto &i
// CHECK-NEXT: 6: operator=
// CHECK-NEXT: 7: [B4.6] (ImplicitCastExpr, FunctionToPointerDecay, class A &(*)(const class A &)
// CHECK-NEXT: 8: i
diff --git a/clang/unittests/AST/DeclPrinterTest.cpp b/clang/unittests/AST/DeclPrinterTest.cpp
index c2d7d78738f96..11dca6ed68167 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -1426,4 +1426,7 @@ TEST(DeclPrinter, VarDeclWithInitializer) {
ASSERT_TRUE(PrintedDeclCXX17Matches(
"int a = 0x15;", namedDecl(hasName("a")).bind("id"), "int a = 0x15",
[](PrintingPolicy &Policy) { Policy.ConstantsAsWritten = true; }));
+ ASSERT_TRUE(
+ PrintedDeclCXX17Matches("void foo() {int arr[42]; for(int a : arr);}",
+ namedDecl(hasName("a")).bind("id"), "int a"));
}
More information about the cfe-commits
mailing list