[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
This commit is contained in:
Jordan Rose 2012-09-04 19:34:58 +00:00
parent 7a204359dc
commit 7523d1a847
2 changed files with 11 additions and 1 deletions

View 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);

View 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;
}