[PATCH] D43481: [CFG] [analyzer] Add construction context when the constructor is being no-op-casted to a const value type.

2018-02-23 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC326016: [CFG] Provide construction contexts for temporaries 
bound to const references. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D43481

Files:
  lib/Analysis/CFG.cpp
  test/Analysis/auto-obj-dtors-cfg-output.cpp
  test/Analysis/cfg-rich-constructors.cpp
  test/Analysis/temp-obj-dtors-cfg-output.cpp

Index: test/Analysis/cfg-rich-constructors.cpp
===
--- test/Analysis/cfg-rich-constructors.cpp
+++ test/Analysis/cfg-rich-constructors.cpp
@@ -155,9 +155,8 @@
   const C (0);
 }
 
-// TODO: Should find construction target here.
 // CHECK: void referenceVariableWithInitializer()
-// CHECK:  1: C() (CXXConstructExpr, class C)
+// CHECK:  1: C() (CXXConstructExpr, [B1.3], class C)
 // CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class C)
 // CHECK-NEXT: 3: [B1.2]
 // CHECK-NEXT: 4: const C  = C();
@@ -335,7 +334,7 @@
 };
 
 // CHECK:  return_stmt_with_dtor::D returnTemporary()
-// CHECK:  1: return_stmt_with_dtor::D() (CXXConstructExpr, [B1.2], class return_stmt_with_dtor::D)
+// CHECK:  1: return_stmt_with_dtor::D() (CXXConstructExpr, [B1.2], [B1.4], class return_stmt_with_dtor::D)
 // CHECK-NEXT: 2: [B1.1] (BindTemporary)
 // CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, NoOp, const class return_stmt_with_dtor::D)
 // CHECK-NEXT: 4: [B1.3]
@@ -418,7 +417,7 @@
 }
 
 // CHECK: void referenceVariableWithInitializer()
-// CHECK:  1: temporary_object_expr_with_dtors::D() (CXXConstructExpr, [B1.2], class temporary_object_expr_with_dtors::D)
+// CHECK:  1: temporary_object_expr_with_dtors::D() (CXXConstructExpr, [B1.2], [B1.4], class temporary_object_expr_with_dtors::D)
 // CHECK-NEXT: 2: [B1.1] (BindTemporary)
 // CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
 // CHECK-NEXT: 4: [B1.3]
@@ -446,7 +445,7 @@
 // CHECK-NEXT: 8: [B5.7] (BindTemporary)
 // CHECK:[B6]
 // CHECK-NEXT: 1: 0
-// CHECK-NEXT: 2: [B6.1] (CXXConstructExpr, [B6.3], class temporary_object_expr_with_dtors::D)
+// CHECK-NEXT: 2: [B6.1] (CXXConstructExpr, [B6.3], [B6.6], class temporary_object_expr_with_dtors::D)
 // CHECK-NEXT: 3: [B6.2] (BindTemporary)
 // CHECK-NEXT: 4: temporary_object_expr_with_dtors::D([B6.3]) (CXXFunctionalCastExpr, ConstructorConversion, class temporary_object_expr_with_dtors::D)
 // CHECK-NEXT: 5: [B6.4] (ImplicitCastExpr, NoOp, const class temporary_object_expr_with_dtors::D)
Index: test/Analysis/temp-obj-dtors-cfg-output.cpp
===
--- test/Analysis/temp-obj-dtors-cfg-output.cpp
+++ test/Analysis/temp-obj-dtors-cfg-output.cpp
@@ -217,7 +217,7 @@
 // CHECK: Succs (1): B1
 // CHECK:   [B1]
 // WARNINGS: 1: A() (CXXConstructExpr, class A)
-// ANALYZER: 1: A() (CXXConstructExpr, [B1.2], class A)
+// ANALYZER: 1: A() (CXXConstructExpr, [B1.2], [B1.4], class A)
 // CHECK: 2: [B1.1] (BindTemporary)
 // CHECK: 3: [B1.2] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 4: [B1.3]
@@ -277,7 +277,7 @@
 // CHECK: Succs (1): B1
 // CHECK:   [B1]
 // WARNINGS: 1: A() (CXXConstructExpr, class A)
-// ANALYZER: 1: A() (CXXConstructExpr, [B1.2], class A)
+// ANALYZER: 1: A() (CXXConstructExpr, [B1.2], [B1.4], class A)
 // CHECK: 2: [B1.1] (BindTemporary)
 // CHECK: 3: [B1.2] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 4: [B1.3]
@@ -532,7 +532,7 @@
 // CHECK: Succs (2): B6 B5
 // CHECK:   [B8]
 // WARNINGS: 1: A() (CXXConstructExpr, class A)
-// ANALYZER: 1: A() (CXXConstructExpr, [B8.2], class A)
+// ANALYZER: 1: A() (CXXConstructExpr, [B8.2], [B8.4], class A)
 // CHECK: 2: [B8.1] (BindTemporary)
 // CHECK: 3: [B8.2] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 4: [B8.3]
@@ -552,7 +552,7 @@
 // CHECK: 7: [B9.6] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 8: [B9.7]
 // WARNINGS: 9: [B9.8] (CXXConstructExpr, class A)
-// ANALYZER: 9: [B9.8] (CXXConstructExpr, [B9.10], class A)
+// ANALYZER: 9: [B9.8] (CXXConstructExpr, [B9.10], [B9.13], class A)
 // CHECK:10: [B9.9] (BindTemporary)
 // CHECK:11: A([B9.10]) (CXXFunctionalCastExpr, ConstructorConversion, class A)
 // CHECK:12: [B9.11] (ImplicitCastExpr, NoOp, const class A)
@@ -662,7 +662,7 @@
 // CHECK: Succs (1): B0
 // CHECK:   [B4]
 // WARNINGS: 1: C() (CXXConstructExpr, struct C)
-// ANALYZER: 1: C() (CXXConstructExpr, [B4.2], struct C)
+// ANALYZER: 1: C() (CXXConstructExpr, [B4.2], [B4.4], struct C)
 // CHECK: 2: [B4.1] (BindTemporary)
 // CHECK: 3: [B4.2] (ImplicitCastExpr, NoOp, const struct C)
 // CHECK: 4: [B4.3]
@@ -714,9 +714,8 @@
 // CHECK: Preds (1): B3
 // CHECK: Succs (1): B0
 

[PATCH] D43481: [CFG] [analyzer] Add construction context when the constructor is being no-op-casted to a const value type.

2018-02-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet.
Herald added subscribers: cfe-commits, rnkovacs.

Because lifetime-extended temporaries are treated as const objects, an implicit 
`NoOp` cast to `const` usually surrounds them in the AST, somewhere between 
`MaterializeTemporaryExpr` and `CXXBindTemporaryExpr`. Skip the cast while 
looking for the construction context.

In the Analyzer this, again, is more useful for adding 
`MaterializeTemporaryExpr` to existing contexts (which are still to be used) 
than to finding more "top-level" contexts, because `CXXBindTemporaryExpr` is 
usually enough to provide some context, and if there's no 
`CXXBindTemporaryExpr` then we're having no destructors and we'd inline the 
constructor anyway. So there are no functional changes in the analyzer yet.


Repository:
  rC Clang

https://reviews.llvm.org/D43481

Files:
  lib/Analysis/CFG.cpp
  test/Analysis/auto-obj-dtors-cfg-output.cpp
  test/Analysis/cfg-rich-constructors.cpp
  test/Analysis/temp-obj-dtors-cfg-output.cpp

Index: test/Analysis/temp-obj-dtors-cfg-output.cpp
===
--- test/Analysis/temp-obj-dtors-cfg-output.cpp
+++ test/Analysis/temp-obj-dtors-cfg-output.cpp
@@ -217,7 +217,7 @@
 // CHECK: Succs (1): B1
 // CHECK:   [B1]
 // WARNINGS: 1: A() (CXXConstructExpr, class A)
-// ANALYZER: 1: A() (CXXConstructExpr, [B1.2], class A)
+// ANALYZER: 1: A() (CXXConstructExpr, [B1.2], [B1.4], class A)
 // CHECK: 2: [B1.1] (BindTemporary)
 // CHECK: 3: [B1.2] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 4: [B1.3]
@@ -277,7 +277,7 @@
 // CHECK: Succs (1): B1
 // CHECK:   [B1]
 // WARNINGS: 1: A() (CXXConstructExpr, class A)
-// ANALYZER: 1: A() (CXXConstructExpr, [B1.2], class A)
+// ANALYZER: 1: A() (CXXConstructExpr, [B1.2], [B1.4], class A)
 // CHECK: 2: [B1.1] (BindTemporary)
 // CHECK: 3: [B1.2] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 4: [B1.3]
@@ -532,7 +532,7 @@
 // CHECK: Succs (2): B6 B5
 // CHECK:   [B8]
 // WARNINGS: 1: A() (CXXConstructExpr, class A)
-// ANALYZER: 1: A() (CXXConstructExpr, [B8.2], class A)
+// ANALYZER: 1: A() (CXXConstructExpr, [B8.2], [B8.4], class A)
 // CHECK: 2: [B8.1] (BindTemporary)
 // CHECK: 3: [B8.2] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 4: [B8.3]
@@ -552,7 +552,7 @@
 // CHECK: 7: [B9.6] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 8: [B9.7]
 // WARNINGS: 9: [B9.8] (CXXConstructExpr, class A)
-// ANALYZER: 9: [B9.8] (CXXConstructExpr, [B9.10], class A)
+// ANALYZER: 9: [B9.8] (CXXConstructExpr, [B9.10], [B9.13], class A)
 // CHECK:10: [B9.9] (BindTemporary)
 // CHECK:11: A([B9.10]) (CXXFunctionalCastExpr, ConstructorConversion, class A)
 // CHECK:12: [B9.11] (ImplicitCastExpr, NoOp, const class A)
@@ -662,7 +662,7 @@
 // CHECK: Succs (1): B0
 // CHECK:   [B4]
 // WARNINGS: 1: C() (CXXConstructExpr, struct C)
-// ANALYZER: 1: C() (CXXConstructExpr, [B4.2], struct C)
+// ANALYZER: 1: C() (CXXConstructExpr, [B4.2], [B4.4], struct C)
 // CHECK: 2: [B4.1] (BindTemporary)
 // CHECK: 3: [B4.2] (ImplicitCastExpr, NoOp, const struct C)
 // CHECK: 4: [B4.3]
@@ -714,9 +714,8 @@
 // CHECK: Preds (1): B3
 // CHECK: Succs (1): B0
 // CHECK:   [B3]
-// WARNINGS: 1: D() (CXXConstructExpr, struct D)
-// CXX98-ANALYZER: 1: D() (CXXConstructExpr, struct D)
-// CXX11-ANALYZER: 1: D() (CXXConstructExpr, [B3.2], struct D)
+// CXX98-WARNINGS: 1: D() (CXXConstructExpr, struct D)
+// CXX98-ANALYZER: 1: D() (CXXConstructExpr, [B3.3], struct D)
 // CXX98: 2: [B3.1] (ImplicitCastExpr, NoOp, const struct D)
 // CXX98: 3: [B3.2]
 // CXX98-WARNINGS: 4: [B3.3] (CXXConstructExpr, struct D)
@@ -727,6 +726,8 @@
 // CXX98: 8: [B3.6]
 // CXX98: 9: [B3.8] (ImplicitCastExpr, UserDefinedConversion, _Bool)
 // CXX98: T: if [B3.9]
+// CXX11-WARNINGS: 1: D() (CXXConstructExpr, struct D)
+// CXX11-ANALYZER: 1: D() (CXXConstructExpr, [B3.2], struct D)
 // CXX11: 2: [B3.1]
 // CXX11-WARNINGS: 3: [B3.2] (CXXConstructExpr, struct D)
 // CXX11-ANALYZER: 3: [B3.2] (CXXConstructExpr, [B3.4], struct D)
@@ -770,7 +771,7 @@
 // CHECK: Succs (2): B3 B2
 // CHECK:   [B5]
 // WARNINGS: 1: A() (CXXConstructExpr, class A)
-// ANALYZER: 1: A() (CXXConstructExpr, [B5.2], class A)
+// ANALYZER: 1: A() (CXXConstructExpr, [B5.2], [B5.4], class A)
 // CHECK: 2: [B5.1] (BindTemporary)
 // CHECK: 3: [B5.2] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 4: [B5.3]
@@ -790,7 +791,7 @@
 // CHECK: 7: [B6.6] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 8: [B6.7]
 // WARNINGS: 9: [B6.8] (CXXConstructExpr, class A)
-// ANALYZER: 9: [B6.8] (CXXConstructExpr, [B6.10], class A)
+// ANALYZER: 9: [B6.8] (CXXConstructExpr, [B6.10], [B6.13],