From 9853371f24c50326c379baeb5e8f8bd6a40b3a96 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Sat, 26 Jan 2013 03:16:31 +0000 Subject: [PATCH] [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. llvm-svn: 173557 --- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 2 +- clang/test/Analysis/initializer.cpp | 30 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index a1fc29eb7e40..26a3f9b1f530 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -404,7 +404,7 @@ void ExprEngine::ProcessInitializer(const CFGInitializer Init, 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(Init)) { SVal FieldLoc; if (BMI->isIndirectMemberInitializer()) diff --git a/clang/test/Analysis/initializer.cpp b/clang/test/Analysis/initializer.cpp index d4f336977e31..ab2eb9014367 100644 --- a/clang/test/Analysis/initializer.cpp +++ b/clang/test/Analysis/initializer.cpp @@ -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 + } +}