]> granicus.if.org Git - clang/commitdiff
[analyzer] Don't use makeIntVal to create a floating-point value.
authorJordan Rose <jordan_rose@apple.com>
Tue, 4 Sep 2012 19:34:58 +0000 (19:34 +0000)
committerJordan Rose <jordan_rose@apple.com>
Tue, 4 Sep 2012 19:34:58 +0000 (19:34 +0000)
SimpleSValBuilder processes a couple trivial identities, including 'x - x'
and 'x ^ x' (both 0). However, the former could appear with arguments of
floating-point type, and we weren't checking for that. This started
triggering an assert with r163069, which checks that a constant value is
actually going to be used as an integer or pointer.

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

lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
test/Analysis/idempotent-operations.c

index ad58a07c784ed0bae83960351cc5ca884a9ae277..1a22845874a123221aa5c3cd9f8c9907208b8ce9 100644 (file)
@@ -318,7 +318,9 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state,
         return makeTruthVal(false, resultTy);
       case BO_Xor:
       case BO_Sub:
-        return makeIntVal(0, resultTy);
+        if (resultTy->isIntegralOrEnumerationType())
+          return makeIntVal(0, resultTy);
+        return evalCastFromNonLoc(makeIntVal(0, /*Unsigned=*/false), resultTy);
       case BO_Or:
       case BO_And:
         return evalCastFromNonLoc(lhs, resultTy);
index 9281f279980c8bfb6654983653d88009004f7180..793e7cd324b91da815a2a15a21f6d6815884448c 100644 (file)
@@ -234,3 +234,11 @@ void rdar8601243() {
   (void) start;
 }
 
+
+float testFloatCast(int i) {
+  float f = i;
+
+  // Don't crash when trying to create a "zero" float.
+  return f - f;
+}
+