]> granicus.if.org Git - clang/commitdiff
CFG: Properly print delegating initializer CFG elements.
authorJordan Rose <jordan_rose@apple.com>
Tue, 22 Oct 2013 23:19:47 +0000 (23:19 +0000)
committerJordan Rose <jordan_rose@apple.com>
Tue, 22 Oct 2013 23:19:47 +0000 (23:19 +0000)
...rather than segfaulting.

Patch by Enrico P!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193208 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFG.cpp
test/Analysis/initializers-cfg-output.cpp

index c7fe9f3a8869d1944f84728e104bb8eb4ea641df..5b48a15def0ec2eb3662d56b93cfb00b91a46d71 100644 (file)
@@ -3762,6 +3762,8 @@ static void print_elem(raw_ostream &OS, StmtPrinterHelper* Helper,
     const CXXCtorInitializer *I = IE->getInitializer();
     if (I->isBaseInitializer())
       OS << I->getBaseClass()->getAsCXXRecordDecl()->getName();
+    else if (I->isDelegatingInitializer())
+      OS << I->getTypeSourceInfo()->getType()->getAsCXXRecordDecl()->getName();
     else OS << I->getAnyMember()->getName();
 
     OS << "(";
@@ -3771,6 +3773,8 @@ static void print_elem(raw_ostream &OS, StmtPrinterHelper* Helper,
 
     if (I->isBaseInitializer())
       OS << " (Base initializer)\n";
+    else if (I->isDelegatingInitializer())
+      OS << " (Delegating initializer)\n";
     else OS << " (Member initializer)\n";
 
   } else if (Optional<CFGAutomaticObjDtor> DE =
index b62d979d5bf038075c089143b6995247c5f2e654..db3c0fb99000f80beb143c5e564d2dbba99687be 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -analyze -analyzer-checker=debug.DumpCFG %s 2>&1 | FileCheck %s
 
 class A {
 public:
@@ -43,6 +43,13 @@ TestControlFlow::TestControlFlow(bool b)
   int v;
 }
 
+class TestDelegating {
+  int x, z;
+ public:
+  TestDelegating() : TestDelegating(2, 3) {}
+  TestDelegating(int x, int z) : x(x), z(z) {}
+};
+
 // CHECK:  [B2 (ENTRY)]
 // CHECK:    Succs (1): B1
 // CHECK:  [B1]
@@ -95,3 +102,14 @@ TestControlFlow::TestControlFlow(bool b)
 // CHECK:    Succs (2): B2 B3
 // CHECK:  [B0 (EXIT)]
 // CHECK:    Preds (1): B1
+// CHECK:  [B2 (ENTRY)]
+// CHECK:    Succs (1): B1
+// CHECK:  [B1]
+// CHECK:    1: 2
+// CHECK:    2: 3
+// CHECK:    3: [B1.1], [B1.2] (CXXConstructExpr, class TestDelegating)
+// CHECK:    4: TestDelegating([B1.3]) (Delegating initializer)
+// CHECK:    Preds (1): B2
+// CHECK:    Succs (1): B0
+// CHECK:  [B0 (EXIT)]
+// CHECK:    Preds (1): B1