]> granicus.if.org Git - clang/commitdiff
Use the new APFloat::convertToInt(APSInt) function to simplify uses of
authorJeffrey Yasskin <jyasskin@google.com>
Fri, 15 Jul 2011 17:03:07 +0000 (17:03 +0000)
committerJeffrey Yasskin <jyasskin@google.com>
Fri, 15 Jul 2011 17:03:07 +0000 (17:03 +0000)
convertToInt(integerParts*) and make them more reliable.

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

lib/AST/ExprConstant.cpp
lib/Sema/SemaChecking.cpp

index 987b02bb8ffbcce405fa20c3c1c05fa215eaa7ed..786155af281d6fb73a36d2bb317f146cedea0c37 100644 (file)
@@ -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,
index 3b48201eddf2a2de442a3a47e43963ad2846954e..690a29d281d20ae663fe906f8e5dd0b711699656 100644 (file)
@@ -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);
 }