From dcdd2a064a6d3ea7712169629328ef80d6cb28ec Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 12 Nov 2009 08:08:27 +0000 Subject: Generalize stdint.h for non-8-bit-multiple types, patch by Ken Dyck! "This adds definitions for types of 8-bit multiples from 8 to 64 to stdint.h and rationalizes the selection of types for the exact-width definitions in InitPreprocessor.cpp." git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86977 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/InitPreprocessor.cpp | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'lib/Frontend/InitPreprocessor.cpp') diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index f6e6058908..6968049131 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -237,6 +237,12 @@ static void DefineType(const char *MacroName, TargetInfo::IntType Ty, DefineBuiltinMacro(Buf, MacroBuf); } +static void DefineExactWidthIntType(TargetInfo::IntType Ty, + const TargetInfo &TI, std::vector &Buf) { + char MacroBuf[60]; + sprintf(MacroBuf, "__INT%d_TYPE__", TI.getTypeWidth(Ty)); + DefineType(MacroBuf, Ty, Buf); +} static void InitializePredefinedMacros(const TargetInfo &TI, const LangOptions &LangOpts, @@ -386,25 +392,22 @@ static void InitializePredefinedMacros(const TargetInfo &TI, if (!LangOpts.CharIsSigned) DefineBuiltinMacro(Buf, "__CHAR_UNSIGNED__"); - // Define fixed-sized integer types for stdint.h - assert(TI.getCharWidth() == 8 && "unsupported target types"); - assert(TI.getShortWidth() == 16 && "unsupported target types"); - DefineBuiltinMacro(Buf, "__INT8_TYPE__=char"); - DefineType("__INT16_TYPE__", TargetInfo::SignedShort, Buf); - - TargetInfo::IntType Int32Type; - if (TI.getIntWidth() == 32) - Int32Type = TargetInfo::SignedInt; - else { - assert(TI.getLongLongWidth() == 32 && "unsupported target types"); - Int32Type = TargetInfo::SignedLongLong; - } - DefineType("__INT32_TYPE__", Int32Type, Buf); - - // 16-bit targets doesn't necessarily have a 64-bit type. - if (TI.getLongLongWidth() == 64) - DefineType("__INT64_TYPE__", TI.getInt64Type(), Buf); + // Define exact-width integer types for stdint.h + sprintf(MacroBuf, "__INT%d_TYPE__=char", TI.getCharWidth()); + DefineBuiltinMacro(Buf, MacroBuf); + if (TI.getShortWidth() > TI.getCharWidth()) + DefineExactWidthIntType(TargetInfo::SignedShort, TI, Buf); + + if (TI.getIntWidth() > TI.getShortWidth()) + DefineExactWidthIntType(TargetInfo::SignedInt, TI, Buf); + + if (TI.getLongWidth() > TI.getIntWidth()) + DefineExactWidthIntType(TargetInfo::SignedLong, TI, Buf); + + if (TI.getLongLongWidth() > TI.getLongWidth()) + DefineExactWidthIntType(TargetInfo::SignedLongLong, TI, Buf); + // Add __builtin_va_list typedef. { const char *VAList = TI.getVAListDeclaration(); -- cgit v1.2.3-18-g5258