diff options
| author | Jeffrey Yasskin <jyasskin@google.com> | 2011-07-15 17:03:07 +0000 |
|---|---|---|
| committer | Jeffrey Yasskin <jyasskin@google.com> | 2011-07-15 17:03:07 +0000 |
| commit | d0f079dad4e117191c929a84fc72a6e9d1e7252b (patch) | |
| tree | 98acbbdc0110122c00c30f653384a32699c36172 | |
| parent | f5f352dda534ea676a2ddb00f8bc36dbd129974e (diff) | |
| download | bcm5719-llvm-d0f079dad4e117191c929a84fc72a6e9d1e7252b.tar.gz bcm5719-llvm-d0f079dad4e117191c929a84fc72a6e9d1e7252b.zip | |
Use the new APFloat::convertToInt(APSInt) function to simplify uses of
convertToInt(integerParts*) and make them more reliable.
llvm-svn: 135279
| -rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 7 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 12 |
2 files changed, 8 insertions, 11 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 987b02bb8ff..786155af281 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -224,11 +224,10 @@ static APSInt HandleFloatToIntCast(QualType DestType, QualType SrcType, bool DestSigned = DestType->isSignedIntegerOrEnumerationType(); // FIXME: Warning for overflow. - uint64_t Space[4]; + APSInt Result(DestWidth, !DestSigned); bool ignored; - (void)Value.convertToInteger(Space, DestWidth, DestSigned, - llvm::APFloat::rmTowardZero, &ignored); - return APSInt(llvm::APInt(DestWidth, 4, Space), !DestSigned); + (void)Value.convertToInteger(Result, llvm::APFloat::rmTowardZero, &ignored); + return Result; } static APFloat HandleFloatToFloatCast(QualType DestType, QualType SrcType, diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 3b48201eddf..690a29d281d 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -3030,18 +3030,16 @@ void DiagnoseFloatingLiteralImpCast(Sema &S, FloatingLiteral *FL, QualType T, if (&Value.getSemantics() == &llvm::APFloat::PPCDoubleDouble) return; - // Try to convert this exactly to an 64-bit integer. FIXME: It would be - // nice to support arbitrarily large integers here. + // Try to convert this exactly to an integer. bool isExact = false; - uint64_t IntegerPart; - if (Value.convertToInteger(&IntegerPart, 64, /*isSigned=*/true, + llvm::APSInt IntegerValue(S.Context.getIntWidth(T), + T->hasUnsignedIntegerRepresentation()); + if (Value.convertToInteger(IntegerValue, llvm::APFloat::rmTowardZero, &isExact) != llvm::APFloat::opOK || !isExact) return; - llvm::APInt IntegerValue(64, IntegerPart, /*isSigned=*/true); - - std::string LiteralValue = IntegerValue.toString(10, /*isSigned=*/true); + std::string LiteralValue = IntegerValue.toString(10); S.Diag(FL->getExprLoc(), diag::note_fix_integral_float_as_integer) << FixItHint::CreateReplacement(FL->getSourceRange(), LiteralValue); } |

