diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp index dbbb516441e8..6509ec30eea7 100644 --- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp @@ -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)) { diff --git a/clang/test/Analysis/casts.c b/clang/test/Analysis/casts.c index eccb67812a02..86fb7da58ec2 100644 --- a/clang/test/Analysis/casts.c +++ b/clang/test/Analysis/casts.c @@ -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; + } +}