]> granicus.if.org Git - clang/commitdiff
fix some undefined behavior, PR7779.
authorChris Lattner <sabre@nondot.org>
Tue, 3 Aug 2010 16:48:42 +0000 (16:48 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 3 Aug 2010 16:48:42 +0000 (16:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110116 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/InitPreprocessor.cpp

index 9990fc42ba1d406b0c16a86d1ee2fd2ffc8c40e8..e5a4169502daa368f74209b3df8868c079fd66c0 100644 (file)
@@ -169,9 +169,10 @@ static void DefineTypeSize(llvm::StringRef MacroName, unsigned TypeWidth,
                            llvm::StringRef ValSuffix, bool isSigned,
                            MacroBuilder& Builder) {
   long long MaxVal;
-  if (isSigned)
-    MaxVal = (1LL << (TypeWidth - 1)) - 1;
-  else
+  if (isSigned) {
+    assert(TypeWidth != 1);
+    MaxVal = ~0ULL >> (65-TypeWidth);
+  } else
     MaxVal = ~0LL >> (64-TypeWidth);
 
   Builder.defineMacro(MacroName, llvm::Twine(MaxVal) + ValSuffix);