[cfe-commits] r173557 - [analyzer] C++ initializers may require cleanups; look through these.

Jordan Rose jordan_rose at apple.com
Fri Jan 25 19:16:31 PST 2013


Author: jrose
Date: Fri Jan 25 21:16:31 2013
New Revision: 173557

URL: http://llvm.org/viewvc/llvm-project?rev=173557&view=rev
Log:
[analyzer] C++ initializers may require cleanups; look through these.

When the analyzer sees an initializer, it checks if the initializer
contains a CXXConstructExpr. If so, it trusts that the CXXConstructExpr
does the necessary work to initialize the object, and performs no further
initialization.

This patch looks through any implicit wrapping expressions like
ExprWithCleanups to find the CXXConstructExpr inside.

Fixes PR15070.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
    cfe/trunk/test/Analysis/initializer.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=173557&r1=173556&r2=173557&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Fri Jan 25 21:16:31 2013
@@ -404,7 +404,7 @@ void ExprEngine::ProcessInitializer(cons
   if (BMI->isAnyMemberInitializer()) {
     // Constructors build the object directly in the field,
     // but non-objects must be copied in from the initializer.
-    const Expr *Init = BMI->getInit();
+    const Expr *Init = BMI->getInit()->IgnoreImplicit();
     if (!isa<CXXConstructExpr>(Init)) {
       SVal FieldLoc;
       if (BMI->isIndirectMemberInitializer())

Modified: cfe/trunk/test/Analysis/initializer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/initializer.cpp?rev=173557&r1=173556&r2=173557&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/initializer.cpp (original)
+++ cfe/trunk/test/Analysis/initializer.cpp Fri Jan 25 21:16:31 2013
@@ -80,3 +80,33 @@ class StringWrapper {
 public:
   StringWrapper(const char *input) : str(strdup(input)) {} // no-warning
 };
+
+
+// PR15070 - Constructing a type containing a non-POD array mistakenly
+// tried to perform a bind instead of relying on the CXXConstructExpr,
+// which caused a cast<> failure in RegionStore.
+namespace DefaultConstructorWithCleanups {
+  class Element {
+  public:
+    int value;
+
+    class Helper {
+    public:
+      ~Helper();
+    };
+    Element(Helper h = Helper());
+  };
+  class Wrapper {
+  public:
+    Element arr[2];
+
+    Wrapper();
+  };
+
+  Wrapper::Wrapper() /* initializers synthesized */ {}
+
+  int test() {
+    Wrapper w;
+    return w.arr[0].value; // no-warning
+  }
+}





More information about the cfe-commits mailing list