Index: lib/Analysis/CFG.cpp =================================================================== --- lib/Analysis/CFG.cpp +++ lib/Analysis/CFG.cpp @@ -2377,7 +2377,9 @@ autoCreateBlock(); appendStmt(Block, DS); - + + EnterConstructionContextIfNecessary(DS, Init); + // Keep track of the last non-null block, as 'Block' can be nulled out // if the initializer expression is something like a 'while' in a // statement-expression. Index: test/Analysis/auto-obj-dtors-cfg-output.cpp =================================================================== --- test/Analysis/auto-obj-dtors-cfg-output.cpp +++ test/Analysis/auto-obj-dtors-cfg-output.cpp @@ -1,5 +1,16 @@ -// RUN: %clang_analyze_cc1 -fcxx-exceptions -fexceptions -analyzer-checker=debug.DumpCFG %s > %t 2>&1 -// RUN: FileCheck --input-file=%t %s +// RUN: %clang_analyze_cc1 -fcxx-exceptions -fexceptions -analyzer-checker=debug.DumpCFG -analyzer-config cfg-rich-constructors=false %s > %t 2>&1 +// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,WARNINGS %s +// RUN: %clang_analyze_cc1 -fcxx-exceptions -fexceptions -analyzer-checker=debug.DumpCFG -analyzer-config cfg-rich-constructors=true %s > %t 2>&1 +// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,ANALYZER %s + +// This file tests how we construct two different flavors of the Clang CFG - +// the CFG used by the Sema analysis-based warnings and the CFG used by the +// static analyzer. The difference in the behavior is checked via FileCheck +// prefixes (WARNINGS and ANALYZER respectively). When introducing new analyzer +// flags, no new run lines should be added - just these flags would go to the +// respective line depending on where is it turned on and where is it turned +// off. Feel free to add tests that test only one of the CFG flavors if you're +// not sure how the other flavor is supposed to work in your case. class A { public: @@ -32,7 +43,8 @@ // CHECK: [B2 (ENTRY)] // CHECK-NEXT: Succs (1): B1 // CHECK: [B1] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B1.2], class A) // CHECK-NEXT: 2: A a; // CHECK-NEXT: 3: a // CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, NoOp, const class A) @@ -57,9 +69,11 @@ // CHECK: [B2 (ENTRY)] // CHECK-NEXT: Succs (1): B1 // CHECK: [B1] -// CHECK-NEXT: 1: (CXXConstructExpr, class A [2]) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A [2]) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B1.2], class A [2]) // CHECK-NEXT: 2: A a[2]; -// CHECK-NEXT: 3: (CXXConstructExpr, class A [0]) +// WARNINGS-NEXT: 3: (CXXConstructExpr, class A [0]) +// ANALYZER-NEXT: 3: (CXXConstructExpr, [B1.4], class A [0]) // CHECK-NEXT: 4: A b[0]; // CHECK-NEXT: 5: [B1.2].~A() (Implicit destructor) // CHECK-NEXT: Preds (1): B2 @@ -74,15 +88,19 @@ // CHECK: [B2 (ENTRY)] // CHECK-NEXT: Succs (1): B1 // CHECK: [B1] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B1.2], class A) // CHECK-NEXT: 2: A a; -// CHECK-NEXT: 3: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 3: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 3: (CXXConstructExpr, [B1.4], class A) // CHECK-NEXT: 4: A c; -// CHECK-NEXT: 5: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 5: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 5: (CXXConstructExpr, [B1.6], class A) // CHECK-NEXT: 6: A d; // CHECK-NEXT: 7: [B1.6].~A() (Implicit destructor) // CHECK-NEXT: 8: [B1.4].~A() (Implicit destructor) -// CHECK-NEXT: 9: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 9: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 9: (CXXConstructExpr, [B1.10], class A) // CHECK: 10: A b; // CHECK: 11: [B1.10].~A() (Implicit destructor) // CHECK: 12: [B1.2].~A() (Implicit destructor) @@ -101,7 +119,8 @@ // CHECK: [B4 (ENTRY)] // CHECK-NEXT: Succs (1): B3 // CHECK: [B1] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B1.2], class A) // CHECK-NEXT: 2: A c; // CHECK-NEXT: 3: [B1.2].~A() (Implicit destructor) // CHECK-NEXT: 4: [B3.4].~A() (Implicit destructor) @@ -115,9 +134,11 @@ // CHECK-NEXT: Preds (1): B3 // CHECK-NEXT: Succs (1): B0 // CHECK: [B3] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B3.2], class A) // CHECK-NEXT: 2: A a; -// CHECK-NEXT: 3: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 3: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 3: (CXXConstructExpr, [B3.4], class A) // CHECK-NEXT: 4: A b; // CHECK-NEXT: 5: UV // CHECK-NEXT: 6: [B3.5] (ImplicitCastExpr, LValueToRValue, _Bool) @@ -137,7 +158,8 @@ // CHECK-NEXT: Succs (1): B7 // CHECK: [B1] // CHECK: l1: -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B1.2], class A) // CHECK-NEXT: 2: A c; // CHECK-NEXT: 3: [B1.2].~A() (Implicit destructor) // CHECK-NEXT: 4: [B6.2].~A() (Implicit destructor) @@ -145,7 +167,8 @@ // CHECK-NEXT: Preds (2): B2 B3 // CHECK-NEXT: Succs (1): B0 // CHECK: [B2] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B2.2], class A) // CHECK-NEXT: 2: A b; // CHECK-NEXT: 3: [B2.2].~A() (Implicit destructor) // CHECK-NEXT: 4: [B6.4].~A() (Implicit destructor) @@ -170,9 +193,11 @@ // CHECK-NEXT: Succs (1): B6 // CHECK: [B6] // CHECK: l0: -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B6.2], class A) // CHECK-NEXT: 2: A b; -// CHECK-NEXT: 3: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 3: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 3: (CXXConstructExpr, [B6.4], class A) // CHECK-NEXT: 4: A a; // CHECK-NEXT: 5: UV // CHECK-NEXT: 6: [B6.5] (ImplicitCastExpr, LValueToRValue, _Bool) @@ -180,7 +205,8 @@ // CHECK-NEXT: Preds (2): B7 B5 // CHECK-NEXT: Succs (2): B5 B4 // CHECK: [B7] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B7.2], class A) // CHECK-NEXT: 2: A a; // CHECK-NEXT: Preds (1): B8 // CHECK-NEXT: Succs (1): B6 @@ -207,23 +233,27 @@ // CHECK-NEXT: Preds (2): B2 B3 // CHECK-NEXT: Succs (1): B0 // CHECK: [B2] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B2.2], class A) // CHECK-NEXT: 2: A c; // CHECK-NEXT: 3: [B2.2].~A() (Implicit destructor) // CHECK-NEXT: Preds (1): B4 // CHECK-NEXT: Succs (1): B1 // CHECK: [B3] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B3.2], class A) // CHECK-NEXT: 2: A c; // CHECK-NEXT: 3: [B3.2].~A() (Implicit destructor) // CHECK-NEXT: Preds (1): B4 // CHECK-NEXT: Succs (1): B1 // CHECK: [B4] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B4.2], class A) // CHECK-NEXT: 2: A a; // CHECK-NEXT: 3: a // CHECK-NEXT: 4: [B4.3] (ImplicitCastExpr, NoOp, const class A) -// CHECK-NEXT: 5: [B4.4] (CXXConstructExpr, class A) +// WARNINGS-NEXT: 5: [B4.4] (CXXConstructExpr, class A) +// ANALYZER-NEXT: 5: [B4.4] (CXXConstructExpr, [B4.6], class A) // CHECK-NEXT: 6: A b = a; // CHECK-NEXT: 7: b // CHECK-NEXT: 8: [B4.7] (ImplicitCastExpr, NoOp, const class A) @@ -247,14 +277,16 @@ // CHECK-NEXT: Succs (1): B8 // CHECK: [B1] // CHECK-NEXT: 1: [B8.6].~A() (Implicit destructor) -// CHECK-NEXT: 2: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 2: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 2: (CXXConstructExpr, [B1.3], class A) // CHECK-NEXT: 3: A e; // CHECK-NEXT: 4: [B1.3].~A() (Implicit destructor) // CHECK-NEXT: 5: [B8.2].~A() (Implicit destructor) // CHECK-NEXT: Preds (2): B2 B5 // CHECK-NEXT: Succs (1): B0 // CHECK: [B2] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B2.2], class A) // CHECK-NEXT: 2: A d; // CHECK-NEXT: 3: [B2.2].~A() (Implicit destructor) // CHECK-NEXT: 4: [B4.2].~A() (Implicit destructor) @@ -268,7 +300,8 @@ // CHECK-NEXT: Preds (1): B4 // CHECK-NEXT: Succs (1): B0 // CHECK: [B4] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B4.2], class A) // CHECK-NEXT: 2: A c; // CHECK-NEXT: 3: UV // CHECK-NEXT: 4: [B4.3] (ImplicitCastExpr, LValueToRValue, _Bool) @@ -276,7 +309,8 @@ // CHECK-NEXT: Preds (1): B8 // CHECK-NEXT: Succs (2): B3 B2 // CHECK: [B5] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B5.2], class A) // CHECK-NEXT: 2: A d; // CHECK-NEXT: 3: [B5.2].~A() (Implicit destructor) // CHECK-NEXT: 4: [B7.2].~A() (Implicit destructor) @@ -290,7 +324,8 @@ // CHECK-NEXT: Preds (1): B7 // CHECK-NEXT: Succs (1): B0 // CHECK: [B7] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B7.2], class A) // CHECK-NEXT: 2: A c; // CHECK-NEXT: 3: UV // CHECK-NEXT: 4: [B7.3] (ImplicitCastExpr, LValueToRValue, _Bool) @@ -298,11 +333,13 @@ // CHECK-NEXT: Preds (1): B8 // CHECK-NEXT: Succs (2): B6 B5 // CHECK: [B8] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B8.2], class A) // CHECK-NEXT: 2: A a; // CHECK-NEXT: 3: a // CHECK-NEXT: 4: [B8.3] (ImplicitCastExpr, NoOp, const class A) -// CHECK-NEXT: 5: [B8.4] (CXXConstructExpr, class A) +// WARNINGS-NEXT: 5: [B8.4] (CXXConstructExpr, class A) +// ANALYZER-NEXT: 5: [B8.4] (CXXConstructExpr, [B8.6], class A) // CHECK-NEXT: 6: A b = a; // CHECK-NEXT: 7: b // CHECK-NEXT: 8: [B8.7] (ImplicitCastExpr, NoOp, const class A) @@ -340,7 +377,8 @@ // CHECK-NEXT: Preds (1): B3 // CHECK-NEXT: Succs (1): B4 // CHECK: [B3] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B3.2], class A) // CHECK-NEXT: 2: A c; // CHECK-NEXT: 3: [B3.2].~A() (Implicit destructor) // CHECK-NEXT: 4: [B4.4].~A() (Implicit destructor) @@ -361,7 +399,8 @@ // CHECK-NEXT: Preds (2): B2 B5 // CHECK-NEXT: Succs (2): B3 B1 // CHECK: [B5] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B5.2], class A) // CHECK-NEXT: 2: A a; // CHECK-NEXT: Preds (1): B6 // CHECK-NEXT: Succs (1): B4 @@ -377,7 +416,8 @@ // CHECK-NEXT: Succs (1): B11 // CHECK: [B1] // CHECK-NEXT: 1: [B10.4].~A() (Implicit destructor) -// CHECK-NEXT: 2: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 2: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 2: (CXXConstructExpr, [B1.3], class A) // CHECK-NEXT: 3: A e; // CHECK-NEXT: 4: [B1.3].~A() (Implicit destructor) // CHECK-NEXT: 5: [B11.2].~A() (Implicit destructor) @@ -387,7 +427,8 @@ // CHECK-NEXT: Preds (2): B3 B6 // CHECK-NEXT: Succs (1): B10 // CHECK: [B3] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B3.2], class A) // CHECK-NEXT: 2: A d; // CHECK-NEXT: 3: [B3.2].~A() (Implicit destructor) // CHECK-NEXT: 4: [B9.2].~A() (Implicit destructor) @@ -425,7 +466,8 @@ // CHECK: Preds (1): B9 // CHECK-NEXT: Succs (1): B1 // CHECK: [B9] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B9.2], class A) // CHECK-NEXT: 2: A c; // CHECK-NEXT: 3: UV // CHECK-NEXT: 4: [B9.3] (ImplicitCastExpr, LValueToRValue, _Bool) @@ -447,7 +489,8 @@ // CHECK-NEXT: Preds (2): B2 B11 // CHECK-NEXT: Succs (2): B9 B1 // CHECK: [B11] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B11.2], class A) // CHECK-NEXT: 2: A a; // CHECK-NEXT: Preds (1): B12 // CHECK-NEXT: Succs (1): B10 @@ -474,7 +517,8 @@ // CHECK-NEXT: Preds (1): B2 // CHECK-NEXT: Succs (2): B3 B0 // CHECK: [B2] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B2.2], class A) // CHECK-NEXT: 2: A a; // CHECK-NEXT: 3: [B2.2].~A() (Implicit destructor) // CHECK-NEXT: Preds (2): B3 B4 @@ -492,7 +536,8 @@ // CHECK: [B12 (ENTRY)] // CHECK-NEXT: Succs (1): B11 // CHECK: [B1] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B1.2], class A) // CHECK-NEXT: 2: A d; // CHECK-NEXT: 3: [B1.2].~A() (Implicit destructor) // CHECK-NEXT: 4: [B11.2].~A() (Implicit destructor) @@ -505,7 +550,8 @@ // CHECK-NEXT: Preds (2): B3 B6 // CHECK-NEXT: Succs (2): B10 B1 // CHECK: [B3] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B3.2], class A) // CHECK-NEXT: 2: A c; // CHECK-NEXT: 3: [B3.2].~A() (Implicit destructor) // CHECK-NEXT: 4: [B9.2].~A() (Implicit destructor) @@ -540,7 +586,8 @@ // CHECK: Preds (1): B9 // CHECK-NEXT: Succs (1): B1 // CHECK: [B9] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B9.2], class A) // CHECK-NEXT: 2: A b; // CHECK-NEXT: 3: UV // CHECK-NEXT: 4: [B9.3] (ImplicitCastExpr, LValueToRValue, _Bool) @@ -551,7 +598,8 @@ // CHECK-NEXT: Preds (1): B2 // CHECK-NEXT: Succs (1): B9 // CHECK: [B11] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B11.2], class A) // CHECK-NEXT: 2: A a; // CHECK-NEXT: Preds (1): B12 // CHECK-NEXT: Succs (1): B9 @@ -577,7 +625,8 @@ // CHECK-NEXT: Preds (2): B3 B2 // CHECK-NEXT: Succs (1): B0 // CHECK: [B2] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B2.2], class A) // CHECK-NEXT: 2: A a; // CHECK-NEXT: 3: a // CHECK-NEXT: 4: [B2.3] (ImplicitCastExpr, NoOp, const class A) @@ -592,7 +641,8 @@ // CHECK-NEXT: Preds (1): B4 // CHECK-NEXT: Succs (1): B1 // CHECK: [B3] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B3.2], class A) // CHECK-NEXT: 2: A c; // CHECK-NEXT: 3: [B3.2].~A() (Implicit destructor) // CHECK-NEXT: Succs (1): B1 @@ -608,14 +658,16 @@ // CHECK-NEXT: Succs (1): B2 // CHECK: [B1] // CHECK-NEXT: 1: [B2.6].~A() (Implicit destructor) -// CHECK-NEXT: 2: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 2: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 2: (CXXConstructExpr, [B1.3], class A) // CHECK-NEXT: 3: A g; // CHECK-NEXT: 4: [B1.3].~A() (Implicit destructor) // CHECK-NEXT: 5: [B2.2].~A() (Implicit destructor) // CHECK-NEXT: Preds (3): B3 B7 B2 // CHECK-NEXT: Succs (1): B0 // CHECK: [B2] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B2.2], class A) // CHECK-NEXT: 2: A a; // CHECK-NEXT: 3: a // CHECK-NEXT: 4: [B2.3] (ImplicitCastExpr, NoOp, const class A) @@ -635,7 +687,8 @@ // CHECK: Preds (2): B2 B4 // CHECK-NEXT: Succs (1): B1 // CHECK: [B4] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B4.2], class A) // CHECK-NEXT: 2: A f; // CHECK-NEXT: 3: [B4.2].~A() (Implicit destructor) // CHECK-NEXT: 4: [B8.2].~A() (Implicit destructor) @@ -661,7 +714,8 @@ // CHECK-NEXT: Succs (1): B1 // CHECK: [B8] // CHECK: case 0: -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B8.2], class A) // CHECK-NEXT: 2: A c; // CHECK-NEXT: 3: UV // CHECK-NEXT: 4: [B8.3] (ImplicitCastExpr, LValueToRValue, _Bool) @@ -696,7 +750,8 @@ // CHECK-NEXT: Preds (1): B3 // CHECK-NEXT: Succs (1): B4 // CHECK: [B3] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B3.2], class A) // CHECK-NEXT: 2: A c; // CHECK-NEXT: 3: [B3.2].~A() (Implicit destructor) // CHECK-NEXT: 4: [B4.4].~A() (Implicit destructor) @@ -717,7 +772,8 @@ // CHECK-NEXT: Preds (2): B2 B5 // CHECK-NEXT: Succs (2): B3 B1 // CHECK: [B5] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B5.2], class A) // CHECK-NEXT: 2: A a; // CHECK-NEXT: Preds (1): B6 // CHECK-NEXT: Succs (1): B4 @@ -733,7 +789,8 @@ // CHECK: [B1] // CHECK-NEXT: 1: [B10.4].~A() (Implicit destructor) // CHECK-NEXT: 2: [B11.4].~A() (Implicit destructor) -// CHECK-NEXT: 3: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 3: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 3: (CXXConstructExpr, [B1.4], class A) // CHECK-NEXT: 4: A f; // CHECK-NEXT: 5: [B1.4].~A() (Implicit destructor) // CHECK-NEXT: 6: [B11.2].~A() (Implicit destructor) @@ -743,7 +800,8 @@ // CHECK-NEXT: Preds (2): B3 B6 // CHECK-NEXT: Succs (1): B10 // CHECK: [B3] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B3.2], class A) // CHECK-NEXT: 2: A e; // CHECK-NEXT: 3: [B3.2].~A() (Implicit destructor) // CHECK-NEXT: 4: [B9.2].~A() (Implicit destructor) @@ -781,7 +839,8 @@ // CHECK: Preds (1): B9 // CHECK-NEXT: Succs (1): B1 // CHECK: [B9] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B9.2], class A) // CHECK-NEXT: 2: A d; // CHECK-NEXT: 3: UV // CHECK-NEXT: 4: [B9.3] (ImplicitCastExpr, LValueToRValue, _Bool) @@ -803,9 +862,11 @@ // CHECK-NEXT: Preds (2): B2 B11 // CHECK-NEXT: Succs (2): B9 B1 // CHECK: [B11] -// CHECK-NEXT: 1: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 1: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 1: (CXXConstructExpr, [B11.2], class A) // CHECK-NEXT: 2: A a; -// CHECK-NEXT: 3: (CXXConstructExpr, class A) +// WARNINGS-NEXT: 3: (CXXConstructExpr, class A) +// ANALYZER-NEXT: 3: (CXXConstructExpr, [B11.4], class A) // CHECK-NEXT: 4: A b; // CHECK-NEXT: Preds (1): B12 // CHECK-NEXT: Succs (1): B10 Index: test/Analysis/blocks.mm =================================================================== --- test/Analysis/blocks.mm +++ test/Analysis/blocks.mm @@ -1,6 +1,17 @@ // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -analyzer-opt-analyze-nested-blocks -verify -x objective-c++ %s -// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.DumpCFG -fblocks -analyzer-opt-analyze-nested-blocks %s > %t 2>&1 -// RUN: FileCheck --input-file=%t %s +// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.DumpCFG -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-config cfg-rich-constructors=false %s > %t 2>&1 +// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,WARNINGS %s +// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,debug.DumpCFG -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-config cfg-rich-constructors=true %s > %t 2>&1 +// RUN: FileCheck --input-file=%t -check-prefixes=CHECK,ANALYZER %s + +// This file tests how we construct two different flavors of the Clang CFG - +// the CFG used by the Sema analysis-based warnings and the CFG used by the +// static analyzer. The difference in the behavior is checked via FileCheck +// prefixes (WARNINGS and ANALYZER respectively). When introducing new analyzer +// flags, no new run lines should be added - just these flags would go to the +// respective line depending on where is it turned on and where is it turned +// off. Feel free to add tests that test only one of the CFG flavors if you're +// not sure how the other flavor is supposed to work in your case. // expected-no-diagnostics @@ -64,7 +75,8 @@ // CHECK: [B1] // CHECK-NEXT: 1: 5 -// CHECK-NEXT: 2: [B1.1] (CXXConstructExpr, struct StructWithCopyConstructor) +// WARNINGS-NEXT: 2: [B1.1] (CXXConstructExpr, struct StructWithCopyConstructor) +// ANALYZER-NEXT: 2: [B1.1] (CXXConstructExpr, [B1.3], struct StructWithCopyConstructor) // CHECK-NEXT: 3: StructWithCopyConstructor s(5) __attribute__((blocks("byref"))); // CHECK-NEXT: 4: ^{ } // CHECK-NEXT: 5: (void)([B1.4]) (CStyleCastExpr, ToVoid, void) Index: test/Analysis/cfg-rich-constructors.cpp =================================================================== --- test/Analysis/cfg-rich-constructors.cpp +++ test/Analysis/cfg-rich-constructors.cpp @@ -5,6 +5,8 @@ public: C(); C(C *); + + static C get(); }; typedef __typeof(sizeof(int)) size_t; @@ -44,3 +46,83 @@ } } // namespace operator_new + +namespace decl_stmt { + +// CHECK: void simpleVariable() +// CHECK: 1: (CXXConstructExpr, [B1.2], class C) +// CHECK-NEXT: 2: C c; +void simpleVariable() { + C c; +} + +// CHECK: void simpleVariableWithBraces() +// CHECK: 1: {} (CXXConstructExpr, [B1.2], class C) +// CHECK-NEXT: 2: C c{}; +void simpleVariableWithBraces() { + C c{}; +} + +// CHECK: void simpleVariableWithConstructorArgument() +// CHECK: 1: 0 +// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NullToPointer, class C *) +// CHECK-NEXT: 3: [B1.2] (CXXConstructExpr, [B1.4], class C) +// CHECK-NEXT: 4: C c(0); +void simpleVariableWithConstructorArgument() { + C c(0); +} + +// CHECK: void simpleVariableWithOperatorNewInConstructorArgument() +// CHECK: 1: CFGNewAllocator(C *) +// CHECK-NEXT: 2: (CXXConstructExpr, [B1.3], class C) +// CHECK-NEXT: 3: new C([B1.2]) +// CHECK-NEXT: 4: [B1.3] (CXXConstructExpr, [B1.5], class C) +// CHECK-NEXT: 5: C c(new C()); +void simpleVariableWithOperatorNewInConstructorArgument() { + C c(new C()); +} + +// CHECK: void simpleVariableWithOperatorNewInBraces() +// CHECK: 1: CFGNewAllocator(C *) +// CHECK-NEXT: 2: (CXXConstructExpr, [B1.3], class C) +// CHECK-NEXT: 3: new C([B1.2]) +// CHECK-NEXT: 4: {[B1.3]} (CXXConstructExpr, [B1.5], class C) +// CHECK-NEXT: 5: C c{new C()}; +void simpleVariableWithOperatorNewInBraces() { + C c{new C()}; +} + +// TODO: Should find construction target here. +// CHECK: void simpleVariableInitializedByValue() +// CHECK: 1: C::get +// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class C (*)(void)) +// CHECK-NEXT: 3: [B1.2]() +// CHECK-NEXT: 4: [B1.3] +// CHECK-NEXT: 5: [B1.4] (CXXConstructExpr, class C) +// CHECK-NEXT: 6: C c = C::get(); +void simpleVariableInitializedByValue() { + C c = C::get(); +} + +// TODO: Should find construction target here. +// CHECK: void referenceVariableWithConstructor() +// CHECK: 1: 0 +// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NullToPointer, class C *) +// CHECK-NEXT: 3: [B1.2] (CXXConstructExpr, const class C) +// CHECK-NEXT: 4: [B1.3] +// CHECK-NEXT: 5: const C &c(0); +void referenceVariableWithConstructor() { + const C &c(0); +} + +// TODO: Should find construction target here. +// CHECK: void referenceVariableWithInitializer() +// CHECK: 1: C() (CXXConstructExpr, class C) +// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class C) +// CHECK-NEXT: 3: [B1.2] +// CHECK-NEXT: 4: const C &c = C(); +void referenceVariableWithInitializer() { + const C &c = C(); +} + +} // end namespace decl_stmt Index: test/Analysis/cfg.cpp =================================================================== --- test/Analysis/cfg.cpp +++ test/Analysis/cfg.cpp @@ -59,11 +59,14 @@ // CHECK-NEXT: 5: int l; // CHECK-NEXT: 6: 2 // CHECK-NEXT: 7: int m = 2; -// CHECK-NEXT: CXXConstructExpr +// WARNINGS-NEXT: (CXXConstructExpr, struct standalone) +// ANALYZER-NEXT: (CXXConstructExpr, [B1.9], struct standalone) // CHECK-NEXT: 9: struct standalone myStandalone; -// CHECK-NEXT: CXXConstructExpr +// WARNINGS-NEXT: (CXXConstructExpr, struct (anonymous struct at {{.*}})) +// ANALYZER-NEXT: (CXXConstructExpr, [B1.11], struct (anonymous struct at {{.*}})) // CHECK-NEXT: 11: struct (anonymous struct at {{.*}}) myAnon; -// CHECK-NEXT: CXXConstructExpr +// WARNINGS-NEXT: (CXXConstructExpr, struct named) +// ANALYZER-NEXT: (CXXConstructExpr, [B1.13], struct named) // CHECK-NEXT: 13: struct named myNamed; // CHECK-NEXT: Preds (1): B2 // CHECK-NEXT: Succs (1): B0 Index: test/Analysis/initializers-cfg-output.cpp =================================================================== --- test/Analysis/initializers-cfg-output.cpp +++ test/Analysis/initializers-cfg-output.cpp @@ -1,4 +1,14 @@ -// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=debug.DumpCFG %s 2>&1 | FileCheck %s +// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=debug.DumpCFG -analyzer-config cfg-rich-constructors=false %s 2>&1 | FileCheck -check-prefixes=CHECK,WARNINGS %s +// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=debug.DumpCFG -analyzer-config cfg-rich-constructors=true %s 2>&1 | FileCheck -check-prefixes=CHECK,ANALYZER %s + +// This file tests how we construct two different flavors of the Clang CFG - +// the CFG used by the Sema analysis-based warnings and the CFG used by the +// static analyzer. The difference in the behavior is checked via FileCheck +// prefixes (WARNINGS and ANALYZER respectively). When introducing new analyzer +// flags, no new run lines should be added - just these flags would go to the +// respective line depending on where is it turned on and where is it turned +// off. Feel free to add tests that test only one of the CFG flavors if you're +// not sure how the other flavor is supposed to work in your case. class A { public: @@ -66,7 +76,8 @@ // CHECK: 11: this // CHECK: 12: [B1.11]->i // CHECK: 13: r([B1.12]) (Member initializer) -// CHECK: 14: (CXXConstructExpr, class A) +// WARNINGS: 14: (CXXConstructExpr, class A) +// ANALYZER: 14: (CXXConstructExpr, [B1.15], class A) // CHECK: 15: A a; // CHECK: Preds (1): B2 // CHECK: Succs (1): B0 Index: test/Analysis/lifetime-cfg-output.cpp =================================================================== --- test/Analysis/lifetime-cfg-output.cpp +++ test/Analysis/lifetime-cfg-output.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-lifetime=true -analyzer-config cfg-implicit-dtors=false %s > %t 2>&1 +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-lifetime=true,cfg-rich-constructors=false -analyzer-config cfg-implicit-dtors=false %s > %t 2>&1 // RUN: FileCheck --input-file=%t %s extern bool UV;