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)));
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)));
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits