r186028 - [analyzer] Remove bogus assert: in C++11, 'new' can do list-initialization.

Jordan Rose jordan_rose at apple.com
Wed Jul 10 12:14:10 PDT 2013


Author: jrose
Date: Wed Jul 10 14:14:10 2013
New Revision: 186028

URL: http://llvm.org/viewvc/llvm-project?rev=186028&view=rev
Log:
[analyzer] Remove bogus assert: in C++11, 'new' can do list-initialization.

Previously, we asserted that whenever 'new' did not include a constructor
call, the type must be a non-record type. In C++11, however, uniform
initialization syntax (braces) allow 'new' to construct records with
list-initialization: "new Point{1, 2}".

Removing this assertion should be perfectly safe; the code here matches
what VisitDeclStmt does for regions allocated on the stack.

<rdar://problem/14403437>

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
    cfe/trunk/test/Analysis/new.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp?rev=186028&r1=186027&r2=186028&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp Wed Jul 10 14:14:10 2013
@@ -431,8 +431,6 @@ void ExprEngine::VisitCXXNewExpr(const C
     if (!isa<CXXConstructExpr>(Init)) {
       assert(Bldr.getResults().size() == 1);
       Bldr.takeNodes(NewN);
-
-      assert(!CNE->getType()->getPointeeCXXRecordDecl());
       evalBind(Dst, CNE, NewN, Result, State->getSVal(Init, LCtx),
                /*FirstInit=*/IsStandardGlobalOpNewFunction);
     }

Modified: cfe/trunk/test/Analysis/new.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/new.cpp?rev=186028&r1=186027&r2=186028&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/new.cpp (original)
+++ cfe/trunk/test/Analysis/new.cpp Wed Jul 10 14:14:10 2013
@@ -170,6 +170,16 @@ void testUsingThisAfterDelete() {
   c->f(0); // no-warning
 }
 
+void testAggregateNew() {
+  struct Point { int x, y; };
+  new Point{1, 2}; // no crash
+
+  Point p;
+  new (&p) Point{1, 2}; // no crash
+  clang_analyzer_eval(p.x == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(p.y == 2); // expected-warning{{TRUE}}
+}
+
 //--------------------------------
 // Incorrectly-modelled behavior
 //--------------------------------





More information about the cfe-commits mailing list