From fafd8d1be93cd5a43a08dbba36264edfd693381c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 5 Feb 2009 07:27:41 +0000 Subject: [PATCH] correct and generalize computation of __INTMAX_MAX__. llvm-svn: 63848 --- clang/lib/Lex/Preprocessor.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 14bddd68266e..f6a29dbd7c51 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -531,10 +531,22 @@ static void InitializePredefinedMacros(Preprocessor &PP, else assert(0 && "Unknown long size"); char MacroBuf[60]; - sprintf(MacroBuf, "__INTMAX_MAX__=%lld", - (TI.getIntMaxType() == TargetInfo::UnsignedLongLong? - (1LL << (TI.getLongLongWidth() - 1)) : - ((1LL << (TI.getLongLongWidth() - 2)) - 1))); + unsigned IntMaxWidth; + const char *IntMaxSuffix; + if (TI.getIntMaxType() == TargetInfo::SignedLongLong) { + IntMaxWidth = TI.getLongLongWidth(); + IntMaxSuffix = "LL"; + } else if (TI.getIntMaxType() == TargetInfo::SignedLong) { + IntMaxWidth = TI.getLongWidth(); + IntMaxSuffix = "L"; + } else { + assert(TI.getIntMaxType() == TargetInfo::SignedInt); + IntMaxWidth = TI.getIntWidth(); + IntMaxSuffix = ""; + } + + sprintf(MacroBuf, "__INTMAX_MAX__=%lld%s", (1LL << (IntMaxWidth - 1)) - 1, + IntMaxSuffix); DefineBuiltinMacro(Buf, MacroBuf); if (TI.getIntMaxType() == TargetInfo::UnsignedLongLong)