Skip to content

Commit d363502

Browse files
author
Adam Balogh
committed
[Analyzer] [HOTFIX!] SValBuilder crash when aggressive-binary-operation-simplification enabled
During the review of D41938 a condition check with an early exit accidentally slipped into a branch, leaving the other branch unprotected. This may result in an assertion later on. This hotfix moves this contition check outside of the branch. Differential Revision: https://reviews.llvm.org/D55051 llvm-svn: 348362
1 parent 1d3cb94 commit d363502

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,16 +475,17 @@ static Optional<NonLoc> tryRearrange(ProgramStateRef State,
475475
SingleTy = ResultTy;
476476
if (LSym->getType() != SingleTy)
477477
return None;
478-
// Substracting unsigned integers is a nightmare.
479-
if (!SingleTy->isSignedIntegerOrEnumerationType())
480-
return None;
481478
} else {
482479
// Don't rearrange other operations.
483480
return None;
484481
}
485482

486483
assert(!SingleTy.isNull() && "We should have figured out the type by now!");
487484

485+
// Rearrange signed symbolic expressions only
486+
if (!SingleTy->isSignedIntegerOrEnumerationType())
487+
return None;
488+
488489
SymbolRef RSym = Rhs.getAsSymbol();
489490
if (!RSym || RSym->getType() != SingleTy)
490491
return None;

clang/test/Analysis/svalbuilder-rearrange-comparisons.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,3 +934,17 @@ int mixed_integer_types(int x, int y) {
934934
short a = x - 1U;
935935
return a - y;
936936
}
937+
938+
unsigned gu();
939+
unsigned fu() {
940+
unsigned x = gu();
941+
// Assert that no overflows occur in this test file.
942+
// Assuming that concrete integers are also within that range.
943+
assert(x <= ((unsigned)UINT_MAX / 4));
944+
return x;
945+
}
946+
947+
void unsigned_concrete_int_no_crash() {
948+
unsigned x = fu() + 1U, y = fu() + 1U;
949+
clang_analyzer_dump(x == y); // expected-warning {{((conj_$2{unsigned int}) + 1U) == ((conj_$7{unsigned int}) + 1U)}}
950+
}

0 commit comments

Comments
 (0)