From 117339c38e266bf28c69d0bf29d35cb5ca79e2d8 Mon Sep 17 00:00:00 2001 From: Alexander Shaposhnikov Date: Mon, 23 Oct 2017 23:46:06 +0000 Subject: [PATCH] [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() triggers an assert, this diff makes getLValueElement return UnknownVal instead. Differential revision: https://reviews.llvm.org/D39174 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316399 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Core/Store.cpp | 5 ++++- test/Analysis/ptr-arith.c | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/StaticAnalyzer/Core/Store.cpp b/lib/StaticAnalyzer/Core/Store.cpp index 1af49f68cc..173fdd8d00 100644 --- a/lib/StaticAnalyzer/Core/Store.cpp +++ b/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()) return Base; - + + if (Base.getAs()) + return UnknownVal(); + const SubRegion *BaseRegion = Base.castAs().getRegionAs(); diff --git a/test/Analysis/ptr-arith.c b/test/Analysis/ptr-arith.c index b78ec503a1..93cb4ee9a6 100644 --- a/test/Analysis/ptr-arith.c +++ b/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:; +} -- 2.40.0