]> granicus.if.org Git - clang/commitdiff
[analyzer] Don't try to simplify mixed Loc/NonLoc expressions.
authorArtem Dergachev <artem.dergachev@gmail.com>
Tue, 31 Jul 2018 19:26:34 +0000 (19:26 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Tue, 31 Jul 2018 19:26:34 +0000 (19:26 +0000)
This fix is similar to r337769 and addresses a regression caused by r337167.

When an operation between a nonloc::LocAsInteger and a non-pointer symbol
is performed, the LocAsInteger-specific part of information is lost.
When the non-pointer symbol is collapsing into a constant, we cannot easily
re-evaluate the result, because we need to recover the missing
LocAsInteger-specific information (eg., integer type, or the very fact that
this pointer was at some point converted to an integer).

Add one more defensive check to prevent crashes on trying to simplify a
SymSymExpr with different Loc-ness of operands.

Differential Revision:

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

lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
test/Analysis/casts.c

index dbbb516441e8957a5583ca0acb06960406989f1e..6509ec30eea725b19d19acf4745cc71e6ef8e445 100644 (file)
@@ -1291,6 +1291,17 @@ SVal SimpleSValBuilder::simplifySVal(ProgramStateRef State, SVal V) {
       if (I != Cached.end())
         return I->second;
 
+      // For now don't try to simplify mixed Loc/NonLoc expressions
+      // because they often appear from LocAsInteger operations
+      // and we don't know how to combine a LocAsInteger
+      // with a concrete value.
+      if (Loc::isLocType(S->getLHS()->getType()) !=
+          Loc::isLocType(S->getRHS()->getType())) {
+        SVal V = SVB.makeSymbolVal(S);
+        Cached[S] = V;
+        return V;
+      }
+
       SVal LHS = Visit(S->getLHS());
       SVal RHS = Visit(S->getRHS());
       if (isUnchanged(S->getLHS(), LHS) && isUnchanged(S->getRHS(), RHS)) {
index eccb67812a02224994300b7d247afa406d3a1e3f..86fb7da58ec2215a4f94f206bf448cd32417df00 100644 (file)
@@ -175,3 +175,10 @@ void testCastVoidPtrToIntPtrThroughUIntTypedAssignment() {
 void testLocNonLocSymbolAssume(int a, int *b) {
   if ((int)b < a) {} // no-crash
 }
+
+void testLocNonLocSymbolRemainder(int a, int *b) {
+  int c = ((int)b) % a;
+  if (a == 1) {
+    c += 1;
+  }
+}