[PATCH] D26442: [analyzer] Fix crash on getSVal: handle case of CompoundVal

Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 21 20:39:19 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL287618: [analyzer] Fix a crash on accessing a field within a literal-initialized union. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D26442?vs=77316&id=78826#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26442

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
  cfe/trunk/test/Analysis/uninit-vals-union.c


Index: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -1674,7 +1674,8 @@
 
     // Lazy bindings are usually handled through getExistingLazyBinding().
     // We should unify these two code paths at some point.
-    if (val.getAs<nonloc::LazyCompoundVal>())
+    if (val.getAs<nonloc::LazyCompoundVal>() ||
+        val.getAs<nonloc::CompoundVal>())
       return val;
 
     llvm_unreachable("Unknown default value");
Index: cfe/trunk/test/Analysis/uninit-vals-union.c
===================================================================
--- cfe/trunk/test/Analysis/uninit-vals-union.c
+++ cfe/trunk/test/Analysis/uninit-vals-union.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core.builtin -analyzer-store=region -verify -Wno-unused %s
+
+typedef union {
+  int y;
+} U;
+
+typedef struct { int x; } A;
+
+void foo() {
+  U u = {};
+  A *a = &u; // expected-warning{{incompatible pointer types}}
+  a->x;      // no-crash
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26442.78826.patch
Type: text/x-patch
Size: 1128 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161122/1243ac9b/attachment-0001.bin>


More information about the cfe-commits mailing list