Author: alexshap Date: Mon Oct 23 16:46:06 2017 New Revision: 316399 URL: http://llvm.org/viewvc/llvm-project?rev=316399&view=rev Log: [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 Modified: cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp cfe/trunk/test/Analysis/ptr-arith.c Modified: cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp?rev=316399&r1=316398&r2=316399&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp Mon Oct 23 16:46:06 2017 @@ -440,7 +440,10 @@ SVal StoreManager::getLValueElement(Qual // 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>(); Modified: cfe/trunk/test/Analysis/ptr-arith.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/ptr-arith.c?rev=316399&r1=316398&r2=316399&view=diff ============================================================================== --- cfe/trunk/test/Analysis/ptr-arith.c (original) +++ cfe/trunk/test/Analysis/ptr-arith.c Mon Oct 23 16:46:06 2017 @@ -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:; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits