summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Balogh <adam.balogh@ericsson.com>2018-12-05 13:17:50 +0000
committerAdam Balogh <adam.balogh@ericsson.com>2018-12-05 13:17:50 +0000
commitd363502dcdf5a04d562c36ec48a1a0f9f7e4f9b9 (patch)
treefaae76294b1b4e55a7e2b817e21070d3d656264e
parent1d3cb9452f23ae705ee23b4c2f588a1df9a0c2f1 (diff)
downloadbcm5719-llvm-d363502dcdf5a04d562c36ec48a1a0f9f7e4f9b9.tar.gz
bcm5719-llvm-d363502dcdf5a04d562c36ec48a1a0f9f7e4f9b9.zip
[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
-rw-r--r--clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp7
-rw-r--r--clang/test/Analysis/svalbuilder-rearrange-comparisons.c14
2 files changed, 18 insertions, 3 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index 62c54fc956a..da9dd3406e1 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 ac186120fe1..ca2099cf7fd 100644
--- a/clang/test/Analysis/svalbuilder-rearrange-comparisons.c
+++ b/clang/test/Analysis/svalbuilder-rearrange-comparisons.c
@@ -934,3 +934,17 @@ 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_dump(x == y); // expected-warning {{((conj_$2{unsigned int}) + 1U) == ((conj_$7{unsigned int}) + 1U)}}
+}
OpenPOWER on IntegriCloud