]> granicus.if.org Git - clang/commitdiff
Reimplement DefineTypeSize in terms of APInt. This eliminates some
authorChris Lattner <sabre@nondot.org>
Thu, 24 Feb 2011 06:54:56 +0000 (06:54 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 24 Feb 2011 06:54:56 +0000 (06:54 +0000)
magic integer arithmetic and allows it to work with types larger
than 64 bits.

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

lib/Frontend/InitPreprocessor.cpp

index 90ca65746d554894613ae9c8e1e67268d18c4fc9..91b5280a87ef8ae7cf31d9ac840971b4003f2d49 100644 (file)
@@ -174,15 +174,10 @@ static void DefineFloatMacros(MacroBuilder &Builder, llvm::StringRef Prefix,
 /// 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