diff options
author | Alexander Shaposhnikov <shal1t712@gmail.com> | 2017-10-23 23:46:06 +0000 |
---|---|---|
committer | Alexander Shaposhnikov <shal1t712@gmail.com> | 2017-10-23 23:46:06 +0000 |
commit | 9a21d28b5da018ae94e8aa9ecae81f7c6a7cf7b8 (patch) | |
tree | a1a578406aca3307b14eb36386f42aef76704e9f | |
parent | 0e88118dd7e741fcbf25d63297f12dc8a1882558 (diff) | |
download | bcm5719-llvm-9a21d28b5da018ae94e8aa9ecae81f7c6a7cf7b8.tar.gz bcm5719-llvm-9a21d28b5da018ae94e8aa9ecae81f7c6a7cf7b8.zip |
[analyzer] Fix handling of labels in getLValueElement
In getLValueElement Base may represent the address of a label
(as in the newly-added test case), in this case it's not a loc::MemRegionVal
and Base.castAs<loc::MemRegionVal>() triggers an assert, this diff makes
getLValueElement return UnknownVal instead.
Differential revision: https://reviews.llvm.org/D39174
llvm-svn: 316399
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/Store.cpp | 5 | ||||
-rw-r--r-- | clang/test/Analysis/ptr-arith.c | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/Store.cpp b/clang/lib/StaticAnalyzer/Core/Store.cpp index 1af49f68cc0..173fdd8d005 100644 --- a/clang/lib/StaticAnalyzer/Core/Store.cpp +++ b/clang/lib/StaticAnalyzer/Core/Store.cpp @@ -440,7 +440,10 @@ SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset, // value. See also the similar FIXME in getLValueFieldOrIvar(). if (Base.isUnknownOrUndef() || Base.getAs<loc::ConcreteInt>()) return Base; - + + if (Base.getAs<loc::GotoLabel>()) + return UnknownVal(); + const SubRegion *BaseRegion = Base.castAs<loc::MemRegionVal>().getRegionAs<SubRegion>(); diff --git a/clang/test/Analysis/ptr-arith.c b/clang/test/Analysis/ptr-arith.c index b78ec503a1c..93cb4ee9a66 100644 --- a/clang/test/Analysis/ptr-arith.c +++ b/clang/test/Analysis/ptr-arith.c @@ -342,3 +342,8 @@ void negativeIndex(char *str) { clang_analyzer_eval(*ptr3 == 'a'); // expected-warning{{UNKNOWN}} } +void test_no_crash_on_pointer_to_label() { + char *a = &&label; + a[0] = 0; +label:; +} |