[PATCH] D45557: [Analyzer] Fix for SValBuilder expressions rearrangement
Balogh, Ádám via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 12 01:31:17 PDT 2018
baloghadamsoftware created this revision.
baloghadamsoftware added a reviewer: NoQ.
Herald added subscribers: dkrupp, a.sidorin, rnkovacs, szepet, xazax.hun, whisperity.
Herald added a reviewer: george.karpenkov.
Expression rearrangement in SValBuilder (see https://reviews.llvm.org/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.
https://reviews.llvm.org/D45557
Files:
lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
test/Analysis/svalbuilder-rearrange-comparisons.c
Index: test/Analysis/svalbuilder-rearrange-comparisons.c
===================================================================
--- test/Analysis/svalbuilder-rearrange-comparisons.c
+++ test/Analysis/svalbuilder-rearrange-comparisons.c
@@ -929,3 +929,8 @@
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;
+}
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===================================================================
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -437,7 +437,10 @@
// overflow bounds.
static bool shouldRearrange(ProgramStateRef State, BinaryOperator::Opcode Op,
SymbolRef Sym, llvm::APSInt Int, QualType Ty) {
+ BasicValueFactory &BV = State->getStateManager().getBasicVals();
+
return Sym->getType() == Ty &&
+ APSIntType(Int) == BV.getAPSIntType(Sym->getType()) &&
(!BinaryOperator::isComparisonOp(Op) ||
(isWithinConstantOverflowBounds(Sym, State) &&
isWithinConstantOverflowBounds(Int)));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45557.142127.patch
Type: text/x-patch
Size: 1148 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180412/15bc347c/attachment.bin>
More information about the cfe-commits
mailing list