Author: dergachev Date: Mon Nov 27 09:37:09 2017 New Revision: 319058 URL: http://llvm.org/viewvc/llvm-project?rev=319058&view=rev Log: [analyzer] pr34766: Fix a crash on explicit std::initializer_list constructor.
We didn't support the following syntax: (std::initializer_list<int>){12} which suddenly produces CompoundLiteralExpr that contains CXXStdInitializerListExpr. Lift the assertion and instead pass the value through CompoundLiteralExpr transparently, as it doesn't add much. Differential Revision: https://reviews.llvm.org/D39803 Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp cfe/trunk/test/Analysis/initializer.cpp Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp?rev=319058&r1=319057&r2=319058&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp Mon Nov 27 09:37:09 2017 @@ -535,7 +535,7 @@ void ExprEngine::VisitCompoundLiteralExp const Expr *Init = CL->getInitializer(); SVal V = State->getSVal(CL->getInitializer(), LCtx); - if (isa<CXXConstructExpr>(Init)) { + if (isa<CXXConstructExpr>(Init) || isa<CXXStdInitializerListExpr>(Init)) { // No work needed. Just pass the value up to this expression. } else { assert(isa<InitListExpr>(Init)); Modified: cfe/trunk/test/Analysis/initializer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/initializer.cpp?rev=319058&r1=319057&r2=319058&view=diff ============================================================================== --- cfe/trunk/test/Analysis/initializer.cpp (original) +++ cfe/trunk/test/Analysis/initializer.cpp Mon Nov 27 09:37:09 2017 @@ -211,7 +211,7 @@ namespace CXX_initializer_lists { struct C { C(std::initializer_list<int *> list); }; -void foo() { +void testPointerEscapeIntoLists() { C empty{}; // no-crash // Do not warn that 'x' leaks. It might have been deleted by @@ -219,4 +219,8 @@ void foo() { int *x = new int; C c{x}; // no-warning } + +void testPassListsWithExplicitConstructors() { + (void)(std::initializer_list<int>){12}; // no-crash +} } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits