Skip to content

Commit 05220a9

Browse files
committed
[analyzer] Don't try to simplify mixed Loc/NonLoc expressions.
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: llvm-svn: 338420
1 parent deb471f commit 05220a9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,17 @@ SVal SimpleSValBuilder::simplifySVal(ProgramStateRef State, SVal V) {
12911291
if (I != Cached.end())
12921292
return I->second;
12931293

1294+
// For now don't try to simplify mixed Loc/NonLoc expressions
1295+
// because they often appear from LocAsInteger operations
1296+
// and we don't know how to combine a LocAsInteger
1297+
// with a concrete value.
1298+
if (Loc::isLocType(S->getLHS()->getType()) !=
1299+
Loc::isLocType(S->getRHS()->getType())) {
1300+
SVal V = SVB.makeSymbolVal(S);
1301+
Cached[S] = V;
1302+
return V;
1303+
}
1304+
12941305
SVal LHS = Visit(S->getLHS());
12951306
SVal RHS = Visit(S->getRHS());
12961307
if (isUnchanged(S->getLHS(), LHS) && isUnchanged(S->getRHS(), RHS)) {

clang/test/Analysis/casts.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,10 @@ void testCastVoidPtrToIntPtrThroughUIntTypedAssignment() {
175175
void testLocNonLocSymbolAssume(int a, int *b) {
176176
if ((int)b < a) {} // no-crash
177177
}
178+
179+
void testLocNonLocSymbolRemainder(int a, int *b) {
180+
int c = ((int)b) % a;
181+
if (a == 1) {
182+
c += 1;
183+
}
184+
}

0 commit comments

Comments
 (0)