]> granicus.if.org Git - clang/commitdiff
[Analyzer] Fix for SValBuilder expressions rearrangement
authorAdam Balogh <adam.balogh@ericsson.com>
Fri, 13 Apr 2018 20:23:02 +0000 (20:23 +0000)
committerAdam Balogh <adam.balogh@ericsson.com>
Fri, 13 Apr 2018 20:23:02 +0000 (20:23 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@330064 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
test/Analysis/svalbuilder-rearrange-comparisons.c

index b2224b5495b7fa70e0df8f760d29031c07e1bfdc..4171ebf136876f0a5cfa9fa5dafb2348519740f9 100644 (file)
@@ -469,6 +469,8 @@ static Optional<NonLoc> tryRearrange(ProgramStateRef State,
     // 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;
index 47366d2445657f1747965d3875f94c97deb228b1..720144c38add7b4fb3d02a2e7021288f0f8d351e 100644 (file)
@@ -929,3 +929,8 @@ void overflow(signed char n, signed char m) {
     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;
+}