Skip to content

Commit 471d086

Browse files
author
Adam Balogh
committedNov 30, 2018
lyzer] [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: 347981
1 parent bd24c7b commit 471d086

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed
 

‎clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

+4-3
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

+17
Original file line numberDiff line numberDiff line change
@@ -979,3 +979,20 @@ int mixed_integer_types(int x, int y) {
979979
short a = x - 1U;
980980
return a - y;
981981
}
982+
983+
unsigned gu();
984+
unsigned fu() {
985+
unsigned x = gu();
986+
// Assert that no overflows occur in this test file.
987+
// Assuming that concrete integers are also within that range.
988+
assert(x <= ((unsigned)UINT_MAX / 4));
989+
return x;
990+
}
991+
992+
void unsigned_concrete_int_no_crash() {
993+
unsigned x = fu() + 1U, y = fu() + 1U;
994+
clang_analyzer_denote(x - 1U, "$x");
995+
clang_analyzer_denote(y - 1U, "$y");
996+
clang_analyzer_express(y); // expected-warning {{$y}}
997+
clang_analyzer_express(x == y); // expected-warning {{$x + 1U == $y + 1U}}
998+
}

0 commit comments

Comments
 (0)
Please sign in to comment.