r330064 - [Analyzer] Fix for SValBuilder expressions rearrangement
Adam Balogh via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 13 13:23:02 PDT 2018
Author: baloghadamsoftware
Date: Fri Apr 13 13:23:02 2018
New Revision: 330064
URL: http://llvm.org/viewvc/llvm-project?rev=330064&view=rev
Log:
[Analyzer] Fix for SValBuilder expressions rearrangement
Expression rearrangement in SValBuilder (see rL329780) crashes with an assert if the type of the integer is different from the type of the symbol. This fix adds a check that prevents rearrangement in such cases.
Differential Revision: https://reviews.llvm.org/D45557
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
cfe/trunk/test/Analysis/svalbuilder-rearrange-comparisons.c
Modified: cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp?rev=330064&r1=330063&r2=330064&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp Fri Apr 13 13:23:02 2018
@@ -469,6 +469,8 @@ static Optional<NonLoc> tryRearrange(Pro
// Initialize SingleTy later with a symbol's type.
} else if (BinaryOperator::isAdditiveOp(Op)) {
SingleTy = ResultTy;
+ if (LSym->getType() != SingleTy)
+ return None;
// Substracting unsigned integers is a nightmare.
if (!SingleTy->isSignedIntegerOrEnumerationType())
return None;
Modified: cfe/trunk/test/Analysis/svalbuilder-rearrange-comparisons.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/svalbuilder-rearrange-comparisons.c?rev=330064&r1=330063&r2=330064&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/svalbuilder-rearrange-comparisons.c (original)
+++ cfe/trunk/test/Analysis/svalbuilder-rearrange-comparisons.c Fri Apr 13 13:23:02 2018
@@ -929,3 +929,8 @@ void overflow(signed char n, signed char
clang_analyzer_eval(n - 126 == m + 3); // expected-warning{{UNKNOWN}}
}
}
+
+int mixed_integer_types(int x, int y) {
+ short a = x - 1U;
+ return a - y;
+}
More information about the cfe-commits
mailing list