]> granicus.if.org Git - clang/commitdiff
[analyzer] Don't crash with assertion failure on structured bindings
authorGeorge Karpenkov <ekarpenkov@apple.com>
Wed, 7 Mar 2018 22:20:35 +0000 (22:20 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Wed, 7 Mar 2018 22:20:35 +0000 (22:20 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326951 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/ExprEngine.cpp
test/Analysis/structured_bindings.cc [new file with mode: 0644]

index 1569e86b57c5081af0c57fd2bd205572f6e947ef..0a63fed20122565e557b099e5a12cfb8c09c2c96 100644 (file)
@@ -2463,7 +2463,12 @@ void ExprEngine::VisitCommonDeclRefExpr(const Expr *Ex, const NamedDecl *D,
                                           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;
   }
 
diff --git a/test/Analysis/structured_bindings.cc b/test/Analysis/structured_bindings.cc
new file mode 100644 (file)
index 0000000..1e23246
--- /dev/null
@@ -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) {
+    }
+}
+