[cfe-commits] r135279 - in /cfe/trunk/lib: AST/ExprConstant.cpp Sema/SemaChecking.cpp

Jeffrey Yasskin jyasskin at google.com
Fri Jul 15 10:03:08 PDT 2011


Author: jyasskin
Date: Fri Jul 15 12:03:07 2011
New Revision: 135279

URL: http://llvm.org/viewvc/llvm-project?rev=135279&view=rev
Log:
Use the new APFloat::convertToInt(APSInt) function to simplify uses of
convertToInt(integerParts*) and make them more reliable.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=135279&r1=135278&r2=135279&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Jul 15 12:03:07 2011
@@ -224,11 +224,10 @@
   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,

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=135279&r1=135278&r2=135279&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Jul 15 12:03:07 2011
@@ -3030,18 +3030,16 @@
   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);
 }





More information about the cfe-commits mailing list