[PATCH] D124349: [analyzer] Get direct binding for specific punned case
Vince Bridgers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 24 12:16:58 PDT 2022
vabridgers updated this revision to Diff 424796.
vabridgers added a comment.
clang-format
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124349/new/
https://reviews.llvm.org/D124349
Files:
clang/lib/StaticAnalyzer/Core/RegionStore.cpp
clang/test/Analysis/array-struct-region.c
Index: clang/test/Analysis/array-struct-region.c
===================================================================
--- clang/test/Analysis/array-struct-region.c
+++ clang/test/Analysis/array-struct-region.c
@@ -353,3 +353,21 @@
// FIXME: Should be TRUE.
clang_analyzer_eval(vals[index].a[0].x == 42); // expected-warning{{UNKNOWN}}
}
+
+typedef struct {
+ int a : 1;
+ int b[2];
+} BITFIELD_CAST;
+
+int array_struct_bitfield_1() {
+ BITFIELD_CAST ff = {0};
+ BITFIELD_CAST *pff = &ff;
+ return *((int *)pff + 1);
+}
+
+int array_struct_bitfield_2() {
+ BITFIELD_CAST ff = {0};
+ BITFIELD_CAST *pff = &ff;
+ int a = *((int *)pff + 2); // expected-warning{{Assigned value is garbage or undefined [core.uninitialized.Assign]}}
+ return a;
+}
Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2153,8 +2153,13 @@
return UnknownVal();
// Additionally allow introspection of a block's internal layout.
- if (!hasPartialLazyBinding && !isa<BlockDataRegion>(R->getBaseRegion()))
+ // Try to get direct binding if all other attempts failed thus far.
+ // Else, return UndefinedVal()
+ if (!hasPartialLazyBinding && !isa<BlockDataRegion>(R->getBaseRegion())) {
+ if (const Optional<SVal> &V = B.getDefaultBinding(R))
+ return *V;
return UndefinedVal();
+ }
}
// All other values are symbolic.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124349.424796.patch
Type: text/x-patch
Size: 1532 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220424/75fbf66a/attachment.bin>
More information about the cfe-commits
mailing list