From 0763cc6bfdafd7ea2ae64bbe843f2979bb6e7652 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 6 Feb 2009 22:59:26 +0000 Subject: [PATCH] Export __INT8_TYPE__ / __INT16_TYPE__ / __INT32_TYPE__ / __INT64_TYPE__ in a gcc 4.5 compatible way so that stdint.h can follow the compiler's notion of types. llvm-svn: 63976 --- clang/lib/Lex/Preprocessor.cpp | 37 ++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index f4f3a0bfb6c9..db5ca2bd7fe5 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -438,6 +438,7 @@ static void DefineType(const char *MacroName, TargetInfo::IntType Ty, static void InitializePredefinedMacros(Preprocessor &PP, std::vector &Buf) { + char MacroBuf[60]; // Compiler version introspection macros. DefineBuiltinMacro(Buf, "__llvm__=1"); // LLVM Backend DefineBuiltinMacro(Buf, "__clang__=1"); // Clang Frontend @@ -512,10 +513,10 @@ static void InitializePredefinedMacros(Preprocessor &PP, // mode. if (PP.getLangOptions().Microsoft) { DefineBuiltinMacro(Buf, "_cdecl=__cdecl"); - DefineBuiltinMacro(Buf, "__int8=char"); - DefineBuiltinMacro(Buf, "__int16=short"); - DefineBuiltinMacro(Buf, "__int32=int"); - DefineBuiltinMacro(Buf, "__int64=long long"); + DefineBuiltinMacro(Buf, "__int8=__INT8_TYPE__"); + DefineBuiltinMacro(Buf, "__int16=__INT16_TYPE__"); + DefineBuiltinMacro(Buf, "__int32=__INT32_TYPE__"); + DefineBuiltinMacro(Buf, "__int64=__INT64_TYPE__"); } // Initialize target-specific preprocessor defines. @@ -558,6 +559,30 @@ static void InitializePredefinedMacros(Preprocessor &PP, DefineFloatMacros(Buf, "FLT", &TI.getFloatFormat()); DefineFloatMacros(Buf, "DBL", &TI.getDoubleFormat()); DefineFloatMacros(Buf, "LDBL", &TI.getLongDoubleFormat()); + + // Define a __POINTER_WIDTH__ macro for stdint.h. + sprintf(MacroBuf, "__POINTER_WIDTH__=%d", (int)TI.getPointerWidth(0)); + DefineBuiltinMacro(Buf, MacroBuf); + + if (!TI.isCharSigned()) + 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"); + DefineBuiltinMacro(Buf, "__INT16_TYPE__=short"); + + if (TI.getIntWidth() == 32) + DefineBuiltinMacro(Buf, "__INT32_TYPE__=int"); + else { + assert(TI.getLongLongWidth() == 32 && "unsupported target types"); + DefineBuiltinMacro(Buf, "__INT32_TYPE__=long long"); + } + + // 16-bit targets doesn't necessarily have a 64-bit type. + if (TI.getLongLongWidth() == 64) + DefineBuiltinMacro(Buf, "__INT64_TYPE__=long long"); // Add __builtin_va_list typedef. { @@ -566,15 +591,11 @@ static void InitializePredefinedMacros(Preprocessor &PP, Buf.push_back('\n'); } - char MacroBuf[60]; if (const char *Prefix = TI.getUserLabelPrefix()) { sprintf(MacroBuf, "__USER_LABEL_PREFIX__=%s", Prefix); DefineBuiltinMacro(Buf, MacroBuf); } - if (!TI.isCharSigned()) - DefineBuiltinMacro(Buf, "__CHAR_UNSIGNED__"); - // Build configuration options. FIXME: these should be controlled by // command line options or something. DefineBuiltinMacro(Buf, "__DYNAMIC__=1");