[cfe-commits] r126365 - /cfe/trunk/lib/Frontend/InitPreprocessor.cpp

Chris Lattner sabre at nondot.org
Wed Feb 23 22:54:56 PST 2011


Author: lattner
Date: Thu Feb 24 00:54:56 2011
New Revision: 126365

URL: http://llvm.org/viewvc/llvm-project?rev=126365&view=rev
Log:
Reimplement DefineTypeSize in terms of APInt.  This eliminates some
magic integer arithmetic and allows it to work with types larger
than 64 bits.

Modified:
    cfe/trunk/lib/Frontend/InitPreprocessor.cpp

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=126365&r1=126364&r2=126365&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Thu Feb 24 00:54:56 2011
@@ -174,15 +174,10 @@
 /// signedness of 'isSigned' and with a value suffix of 'ValSuffix' (e.g. LL).
 static void DefineTypeSize(llvm::StringRef MacroName, unsigned TypeWidth,
                            llvm::StringRef ValSuffix, bool isSigned,
-                           MacroBuilder& Builder) {
-  long long MaxVal;
-  if (isSigned) {
-    assert(TypeWidth != 1);
-    MaxVal = ~0ULL >> (65-TypeWidth);
-  } else
-    MaxVal = ~0ULL >> (64-TypeWidth);
-
-  Builder.defineMacro(MacroName, llvm::Twine(MaxVal) + ValSuffix);
+                           MacroBuilder &Builder) {
+  llvm::APInt MaxVal = isSigned ? llvm::APInt::getSignedMaxValue(TypeWidth)
+                                : llvm::APInt::getMaxValue(TypeWidth);
+  Builder.defineMacro(MacroName, MaxVal.toString(10, isSigned) + ValSuffix);
 }
 
 /// DefineTypeSize - An overloaded helper that uses TargetInfo to determine





More information about the cfe-commits mailing list