]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix symbol discovery in nonloc::LocAsInteger values.
authorArtem Dergachev <artem.dergachev@gmail.com>
Tue, 2 Oct 2018 20:48:12 +0000 (20:48 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Tue, 2 Oct 2018 20:48:12 +0000 (20:48 +0000)
Doesn't do much despite sounding quite bad, but fixes an exotic test case where
liveness of a nonloc::LocAsInteger array index is now evaluated correctly.

Differential Revision: https://reviews.llvm.org/D52667

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@343631 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/SVals.cpp
test/Analysis/symbol-reaper.c

index 559ca2c9840d3f200f145b82d7e6b42e69f3dadf..b32be9e82d4e4846c9e0e6d69479b90907baeaf7 100644 (file)
@@ -85,7 +85,7 @@ const FunctionDecl *SVal::getAsFunctionDecl() const {
 SymbolRef SVal::getAsLocSymbol(bool IncludeBaseRegions) const {
   // FIXME: should we consider SymbolRef wrapped in CodeTextRegion?
   if (Optional<nonloc::LocAsInteger> X = getAs<nonloc::LocAsInteger>())
-    return X->getLoc().getAsLocSymbol();
+    return X->getLoc().getAsLocSymbol(IncludeBaseRegions);
 
   if (Optional<loc::MemRegionVal> X = getAs<loc::MemRegionVal>()) {
     const MemRegion *R = X->getRegion();
index a47161bea2e3aca0b24bc52402aed10b07c34938..ef8ff18a2d831fcfacc67f26b3900af10af96994 100644 (file)
@@ -85,8 +85,7 @@ void test_loc_as_integer_element_index_lifetime() {
     x = (int)&(s->field);
     ptr = &arr[x];
     if (s) {}
-  // FIXME: Should not warn. The symbol is still alive within the ptr's index.
-  } while (0); // expected-warning{{SYMBOL DEAD}}
+  } while (0);
 }
 
 // Test below checks lifetime of SymbolRegionValue in certain conditions.