r326951 - [analyzer] Don't crash with assertion failure on structured bindings
George Karpenkov via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 7 14:20:35 PST 2018
Author: george.karpenkov
Date: Wed Mar 7 14:20:35 2018
New Revision: 326951
URL: http://llvm.org/viewvc/llvm-project?rev=326951&view=rev
Log:
[analyzer] Don't crash with assertion failure on structured bindings
Proper modeling still remains to be done.
Note that BindingDecl#getHoldingVar() is almost always null, and this
should probably be handled by dealing with DecompositionDecl beforehand.
rdar://36852163
Differential Revision: https://reviews.llvm.org/D44183
Added:
cfe/trunk/test/Analysis/structured_bindings.cc
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=326951&r1=326950&r2=326951&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Wed Mar 7 14:20:35 2018
@@ -2463,7 +2463,12 @@ void ExprEngine::VisitCommonDeclRefExpr(
currBldrCtx->blockCount());
state = state->assume(V.castAs<DefinedOrUnknownSVal>(), true);
Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), nullptr,
- ProgramPoint::PostLValueKind);
+ ProgramPoint::PostLValueKind);
+ return;
+ }
+ if (const auto* BD = dyn_cast<BindingDecl>(D)) {
+ // FIXME: proper support for bound declarations.
+ // For now, let's just prevent crashing.
return;
}
Added: cfe/trunk/test/Analysis/structured_bindings.cc
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/structured_bindings.cc?rev=326951&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/structured_bindings.cc (added)
+++ cfe/trunk/test/Analysis/structured_bindings.cc Wed Mar 7 14:20:35 2018
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -std=c++17 -analyzer-checker=core -verify %s
+
+// expected-no-diagnostics
+struct s { int a; };
+int foo() {
+ auto[a] = s{1}; // FIXME: proper modelling
+ if (a) {
+ }
+}
+
More information about the cfe-commits
mailing list