diff options
author | Artem Dergachev <artem.dergachev@gmail.com> | 2017-11-27 17:37:09 +0000 |
---|---|---|
committer | Artem Dergachev <artem.dergachev@gmail.com> | 2017-11-27 17:37:09 +0000 |
commit | 0dca9cdd99ab667dbc8d28d7e3eddd7d658d52f6 (patch) | |
tree | 4edc2b922282133ea9d341543b1c146a0cda43b7 | |
parent | 37d08be31c190321aab5b8d192d2401a58a5938a (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319058 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/StaticAnalyzer/Core/ExprEngineC.cpp | 2 | ||||
-rw-r--r-- | test/Analysis/initializer.cpp | 6 |
2 files changed, 6 insertions, 2 deletions
diff --git a/lib/StaticAnalyzer/Core/ExprEngineC.cpp b/lib/StaticAnalyzer/Core/ExprEngineC.cpp index d6feabea53..e0e1c3617d 100644 --- a/lib/StaticAnalyzer/Core/ExprEngineC.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngineC.cpp @@ -535,7 +535,7 @@ void ExprEngine::VisitCompoundLiteralExpr(const CompoundLiteralExpr *CL, 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)); diff --git a/test/Analysis/initializer.cpp b/test/Analysis/initializer.cpp index e9658a067c..6359b93d0a 100644 --- a/test/Analysis/initializer.cpp +++ b/test/Analysis/initializer.cpp @@ -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 +} } |