Author: baloghadamsoftware Date: Fri Nov 30 02:37:44 2018 New Revision: 347981
URL: http://llvm.org/viewvc/llvm-project?rev=347981&view=rev Log: 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 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=347981&r1=347980&r2=347981&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp Fri Nov 30 02:37:44 2018 @@ -475,9 +475,6 @@ static Optional<NonLoc> tryRearrange(Pro 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(Pro 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; 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=347981&r1=347980&r2=347981&view=diff ============================================================================== --- cfe/trunk/test/Analysis/svalbuilder-rearrange-comparisons.c (original) +++ cfe/trunk/test/Analysis/svalbuilder-rearrange-comparisons.c Fri Nov 30 02:37:44 2018 @@ -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}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits