fix some undefined behavior, PR7779.

llvm-svn: 110116
This commit is contained in:
Chris Lattner 2010-08-03 16:48:42 +00:00
parent 081627ceb8
commit 278008f546
1 changed files with 4 additions and 3 deletions

View 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);