diff options
author | Adam Balogh <adam.balogh@ericsson.com> | 2018-11-30 10:37:44 +0000 |
---|---|---|
committer | Adam Balogh <adam.balogh@ericsson.com> | 2018-11-30 10:37:44 +0000 |
commit | 471d0864dfa9b4f9de813c2d7492d40a52768cc9 (patch) | |
tree | a0e4361436d3dd145a1fa0637ea608f04f167559 | |
parent | bd24c7b045646f59f1fbf3298a2caab972726af4 (diff) | |
download | bcm5719-llvm-471d0864dfa9b4f9de813c2d7492d40a52768cc9.tar.gz bcm5719-llvm-471d0864dfa9b4f9de813c2d7492d40a52768cc9.zip |
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
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp | 7 | ||||
-rw-r--r-- | clang/test/Analysis/svalbuilder-rearrange-comparisons.c | 17 |
2 files changed, 21 insertions, 3 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp index 5cd9320d650..19d71253eb7 100644 --- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp @@ -475,9 +475,6 @@ static Optional<NonLoc> tryRearrange(ProgramStateRef State, SingleTy = ResultTy; if (LSym->getType() != SingleTy) return None; - // Substracting unsigned integers is a nightmare. - if (!SingleTy->isSignedIntegerOrEnumerationType()) - return None; } else { // Don't rearrange other operations. return None; @@ -485,6 +482,10 @@ static Optional<NonLoc> tryRearrange(ProgramStateRef State, assert(!SingleTy.isNull() && "We should have figured out the type by now!"); + // Rearrange signed symbolic expressions only + if (!SingleTy->isSignedIntegerOrEnumerationType()) + return None; + SymbolRef RSym = Rhs.getAsSymbol(); if (!RSym || RSym->getType() != SingleTy) return None; diff --git a/clang/test/Analysis/svalbuilder-rearrange-comparisons.c b/clang/test/Analysis/svalbuilder-rearrange-comparisons.c index daf17b66b2e..9e9bf0a9db9 100644 --- a/clang/test/Analysis/svalbuilder-rearrange-comparisons.c +++ b/clang/test/Analysis/svalbuilder-rearrange-comparisons.c @@ -979,3 +979,20 @@ int mixed_integer_types(int x, int y) { short a = x - 1U; return a - y; } + +unsigned gu(); +unsigned fu() { + unsigned x = gu(); + // Assert that no overflows occur in this test file. + // Assuming that concrete integers are also within that range. + assert(x <= ((unsigned)UINT_MAX / 4)); + return x; +} + +void unsigned_concrete_int_no_crash() { + unsigned x = fu() + 1U, y = fu() + 1U; + clang_analyzer_denote(x - 1U, "$x"); + clang_analyzer_denote(y - 1U, "$y"); + clang_analyzer_express(y); // expected-warning {{$y}} + clang_analyzer_express(x == y); // expected-warning {{$x + 1U == $y + 1U}} +} |