Skip to content

Commit 9a21d28

Browse files
committedOct 23, 2017
[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
1 parent 0e88118 commit 9a21d28

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
 

‎clang/lib/StaticAnalyzer/Core/Store.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,10 @@ SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset,
440440
// value. See also the similar FIXME in getLValueFieldOrIvar().
441441
if (Base.isUnknownOrUndef() || Base.getAs<loc::ConcreteInt>())
442442
return Base;
443-
443+
444+
if (Base.getAs<loc::GotoLabel>())
445+
return UnknownVal();
446+
444447
const SubRegion *BaseRegion =
445448
Base.castAs<loc::MemRegionVal>().getRegionAs<SubRegion>();
446449

‎clang/test/Analysis/ptr-arith.c

+5
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,8 @@ void negativeIndex(char *str) {
342342
clang_analyzer_eval(*ptr3 == 'a'); // expected-warning{{UNKNOWN}}
343343
}
344344

345+
void test_no_crash_on_pointer_to_label() {
346+
char *a = &&label;
347+
a[0] = 0;
348+
label:;
349+
}

0 commit comments

Comments
 (0)