diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-09-04 19:34:58 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-09-04 19:34:58 +0000 |
commit | 7523d1a847b661d0a8cc71f8aa051c873278445a (patch) | |
tree | f712e604a31e509e7b129ecf169d42fd67340f64 | |
parent | 7a204359dc0f577770be16c44216fc9e19675f3f (diff) | |
download | bcm5719-llvm-7523d1a847b661d0a8cc71f8aa051c873278445a.tar.gz bcm5719-llvm-7523d1a847b661d0a8cc71f8aa051c873278445a.zip |
[analyzer] Don't use makeIntVal to create a floating-point value.
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.
llvm-svn: 163159
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp | 4 | ||||
-rw-r--r-- | clang/test/Analysis/idempotent-operations.c | 8 |
2 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp index ad58a07c784..1a22845874a 100644 --- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp @@ -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); diff --git a/clang/test/Analysis/idempotent-operations.c b/clang/test/Analysis/idempotent-operations.c index 9281f279980..793e7cd324b 100644 --- a/clang/test/Analysis/idempotent-operations.c +++ b/clang/test/Analysis/idempotent-operations.c @@ -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; +} + |