diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 2b35c8e2296b8d899c912934cc6f74b260b7001e..c9c76e5f1f3b08d24fc21f6805fce8c0b0dda4fc 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -195,6 +195,12 @@ static void DefineTypeWidth(llvm::StringRef MacroName, TargetInfo::IntType Ty, Builder.defineMacro(MacroName, llvm::Twine(TI.getTypeWidth(Ty))); } +static void DefineTypeSizeof(llvm::StringRef MacroName, unsigned BitWidth, + const TargetInfo &TI, MacroBuilder &Builder) { + Builder.defineMacro(MacroName, + llvm::Twine(BitWidth / TI.getCharWidth())); +} + static void DefineExactWidthIntType(TargetInfo::IntType Ty, const TargetInfo &TI, MacroBuilder &Builder) { int TypeWidth = TI.getTypeWidth(Ty); @@ -293,6 +299,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI, if (LangOpts.Exceptions) Builder.defineMacro("__EXCEPTIONS"); + if (LangOpts.RTTI) + Builder.defineMacro("__GXX_RTTI"); if (LangOpts.SjLjExceptions) Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__"); @@ -350,6 +358,23 @@ static void InitializePredefinedMacros(const TargetInfo &TI, DefineTypeSize("__WCHAR_MAX__", TI.getWCharType(), TI, Builder); DefineTypeSize("__INTMAX_MAX__", TI.getIntMaxType(), TI, Builder); + DefineTypeSizeof("__SIZEOF_DOUBLE__", TI.getDoubleWidth(), TI, Builder); + DefineTypeSizeof("__SIZEOF_FLOAT__", TI.getFloatWidth(), TI, Builder); + DefineTypeSizeof("__SIZEOF_INT__", TI.getIntWidth(), TI, Builder); + DefineTypeSizeof("__SIZEOF_LONG__", TI.getLongWidth(), TI, Builder); + DefineTypeSizeof("__SIZEOF_LONG_DOUBLE__",TI.getLongDoubleWidth(),TI,Builder); + DefineTypeSizeof("__SIZEOF_LONG_LONG__", TI.getLongLongWidth(), TI, Builder); + DefineTypeSizeof("__SIZEOF_POINTER__", TI.getPointerWidth(0), TI, Builder); + DefineTypeSizeof("__SIZEOF_SHORT__", TI.getShortWidth(), TI, Builder); + DefineTypeSizeof("__SIZEOF_PTRDIFF_T__", + TI.getTypeWidth(TI.getPtrDiffType(0)), TI, Builder); + DefineTypeSizeof("__SIZEOF_SIZE_T__", + TI.getTypeWidth(TI.getSizeType()), TI, Builder); + DefineTypeSizeof("__SIZEOF_WCHAR_T__", + TI.getTypeWidth(TI.getWCharType()), TI, Builder); + DefineTypeSizeof("__SIZEOF_WINT_T__", + TI.getTypeWidth(TI.getWIntType()), TI, Builder); + DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Builder); DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Builder); DefineTypeWidth("__INTMAX_WIDTH__", TI.getIntMaxType(), TI, Builder); @@ -364,6 +389,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI, DefineType("__WINT_TYPE__", TI.getWIntType(), Builder); DefineTypeWidth("__WINT_WIDTH__", TI.getWIntType(), TI, Builder); DefineTypeWidth("__SIG_ATOMIC_WIDTH__", TI.getSigAtomicType(), TI, Builder); + DefineType("__CHAR16_TYPE__", TI.getChar16Type(), Builder); + DefineType("__CHAR32_TYPE__", TI.getChar32Type(), Builder); DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat()); DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat()); diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index b9850983a2a141ab2d768623d10307bb633b965c..28ead97c575265fc1c6591ee9e6d69fee964bcad 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -14,6 +14,7 @@ // CXX0X:#define __DEPRECATED 1 // CXX0X:#define __GNUG__ // CXX0X:#define __GXX_EXPERIMENTAL_CXX0X__ 1 +// CXX0X:#define __GXX_RTTI 1 // CXX0X:#define __GXX_WEAK__ 1 // CXX0X:#define __cplusplus 199711L // CXX0X:#define __private_extern__ extern @@ -23,6 +24,7 @@ // // CXX98:#define __DEPRECATED 1 // CXX98:#define __GNUG__ +// CXX98:#define __GXX_RTTI 1 // CXX98:#define __GXX_WEAK__ 1 // CXX98:#define __cplusplus 199711L // CXX98:#define __private_extern__ extern @@ -120,6 +122,8 @@ // ARM:#define __APCS_32__ 1 // ARM:#define __ARMEL__ 1 // ARM:#define __ARM_ARCH_6J__ 1 +// ARM:#define __CHAR16_TYPE__ unsigned short +// ARM:#define __CHAR32_TYPE__ unsigned int // ARM:#define __CHAR_BIT__ 8 // ARM:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 // ARM:#define __DBL_DIG__ 15 @@ -185,6 +189,18 @@ // ARM:#define __SCHAR_MAX__ 127 // ARM:#define __SHRT_MAX__ 32767 // ARM:#define __SIG_ATOMIC_WIDTH__ 32 +// ARM:#define __SIZEOF_DOUBLE__ 8 +// ARM:#define __SIZEOF_FLOAT__ 4 +// ARM:#define __SIZEOF_INT__ 4 +// ARM:#define __SIZEOF_LONG_DOUBLE__ 8 +// ARM:#define __SIZEOF_LONG_LONG__ 8 +// ARM:#define __SIZEOF_LONG__ 4 +// ARM:#define __SIZEOF_POINTER__ 4 +// ARM:#define __SIZEOF_PTRDIFF_T__ 4 +// ARM:#define __SIZEOF_SHORT__ 2 +// ARM:#define __SIZEOF_SIZE_T__ 4 +// ARM:#define __SIZEOF_WCHAR_T__ 4 +// ARM:#define __SIZEOF_WINT_T__ 4 // ARM:#define __SIZE_TYPE__ unsigned int // ARM:#define __SIZE_WIDTH__ 32 // ARM:#define __THUMB_INTERWORK__ 1 @@ -205,6 +221,8 @@ // BFIN:#define __ADSPLPBLACKFIN__ 1 // BFIN:#define __BFIN 1 // BFIN:#define __BFIN__ 1 +// BFIN:#define __CHAR16_TYPE__ unsigned short +// BFIN:#define __CHAR32_TYPE__ unsigned int // BFIN:#define __CHAR_BIT__ 8 // BFIN:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 // BFIN:#define __DBL_DIG__ 15 @@ -268,6 +286,18 @@ // BFIN:#define __SCHAR_MAX__ 127 // BFIN:#define __SHRT_MAX__ 32767 // BFIN:#define __SIG_ATOMIC_WIDTH__ 32 +// BFIN:#define __SIZEOF_DOUBLE__ 8 +// BFIN:#define __SIZEOF_FLOAT__ 4 +// BFIN:#define __SIZEOF_INT__ 4 +// BFIN:#define __SIZEOF_LONG_DOUBLE__ 8 +// BFIN:#define __SIZEOF_LONG_LONG__ 8 +// BFIN:#define __SIZEOF_LONG__ 4 +// BFIN:#define __SIZEOF_POINTER__ 4 +// BFIN:#define __SIZEOF_PTRDIFF_T__ 4 +// BFIN:#define __SIZEOF_SHORT__ 2 +// BFIN:#define __SIZEOF_SIZE_T__ 4 +// BFIN:#define __SIZEOF_WCHAR_T__ 4 +// BFIN:#define __SIZEOF_WINT_T__ 4 // BFIN:#define __SIZE_TYPE__ long unsigned int // BFIN:#define __SIZE_WIDTH__ 32 // BFIN:#define __UINTMAX_TYPE__ long long unsigned int @@ -283,6 +313,8 @@ // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=i386-none-none < /dev/null | FileCheck -check-prefix I386 %s // +// I386:#define __CHAR16_TYPE__ unsigned short +// I386:#define __CHAR32_TYPE__ unsigned int // I386:#define __CHAR_BIT__ 8 // I386:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 // I386:#define __DBL_DIG__ 15 @@ -349,6 +381,18 @@ // I386:#define __SCHAR_MAX__ 127 // I386:#define __SHRT_MAX__ 32767 // I386:#define __SIG_ATOMIC_WIDTH__ 32 +// I386:#define __SIZEOF_DOUBLE__ 8 +// I386:#define __SIZEOF_FLOAT__ 4 +// I386:#define __SIZEOF_INT__ 4 +// I386:#define __SIZEOF_LONG_DOUBLE__ 12 +// I386:#define __SIZEOF_LONG_LONG__ 8 +// I386:#define __SIZEOF_LONG__ 4 +// I386:#define __SIZEOF_POINTER__ 4 +// I386:#define __SIZEOF_PTRDIFF_T__ 4 +// I386:#define __SIZEOF_SHORT__ 2 +// I386:#define __SIZEOF_SIZE_T__ 4 +// I386:#define __SIZEOF_WCHAR_T__ 4 +// I386:#define __SIZEOF_WINT_T__ 4 // I386:#define __SIZE_TYPE__ unsigned int // I386:#define __SIZE_WIDTH__ 32 // I386:#define __UINTMAX_TYPE__ long long unsigned int @@ -368,6 +412,8 @@ // RUN: %clang_cc1 -E -dM -ffreestanding -triple=msp430-none-none < /dev/null | FileCheck -check-prefix MSP430 %s // // MSP430:#define MSP430 1 +// MSP430:#define __CHAR16_TYPE__ unsigned short +// MSP430:#define __CHAR32_TYPE__ unsigned int // MSP430:#define __CHAR_BIT__ 8 // MSP430:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 // MSP430:#define __DBL_DIG__ 15 @@ -431,6 +477,18 @@ // MSP430:#define __SCHAR_MAX__ 127 // MSP430:#define __SHRT_MAX__ 32767 // MSP430:#define __SIG_ATOMIC_WIDTH__ 32 +// MSP430:#define __SIZEOF_DOUBLE__ 8 +// MSP430:#define __SIZEOF_FLOAT__ 4 +// MSP430:#define __SIZEOF_INT__ 2 +// MSP430:#define __SIZEOF_LONG_DOUBLE__ 8 +// MSP430:#define __SIZEOF_LONG_LONG__ 8 +// MSP430:#define __SIZEOF_LONG__ 4 +// MSP430:#define __SIZEOF_POINTER__ 2 +// MSP430:#define __SIZEOF_PTRDIFF_T__ 2 +// MSP430:#define __SIZEOF_SHORT__ 2 +// MSP430:#define __SIZEOF_SIZE_T__ 2 +// MSP430:#define __SIZEOF_WCHAR_T__ 2 +// MSP430:#define __SIZEOF_WINT_T__ 2 // MSP430:#define __SIZE_TYPE__ unsigned int // MSP430:#define __SIZE_WIDTH__ 16 // MSP430:#define __UINTMAX_TYPE__ long unsigned int @@ -444,6 +502,8 @@ // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=pic16-none-none < /dev/null | FileCheck -check-prefix PIC16 %s // +// PIC16:#define __CHAR16_TYPE__ unsigned short +// PIC16:#define __CHAR32_TYPE__ unsigned int // PIC16:#define __CHAR_BIT__ 8 // PIC16:#define __DBL_DENORM_MIN__ 1.40129846e-45F // PIC16:#define __DBL_DIG__ 6 @@ -507,6 +567,18 @@ // PIC16:#define __SCHAR_MAX__ 127 // PIC16:#define __SHRT_MAX__ 32767 // PIC16:#define __SIG_ATOMIC_WIDTH__ 32 +// PIC16:#define __SIZEOF_DOUBLE__ 4 +// PIC16:#define __SIZEOF_FLOAT__ 4 +// PIC16:#define __SIZEOF_INT__ 2 +// PIC16:#define __SIZEOF_LONG_DOUBLE__ 4 +// PIC16:#define __SIZEOF_LONG_LONG__ 4 +// PIC16:#define __SIZEOF_LONG__ 4 +// PIC16:#define __SIZEOF_POINTER__ 2 +// PIC16:#define __SIZEOF_PTRDIFF_T__ 2 +// PIC16:#define __SIZEOF_SHORT__ 2 +// PIC16:#define __SIZEOF_SIZE_T__ 2 +// PIC16:#define __SIZEOF_WCHAR_T__ 2 +// PIC16:#define __SIZEOF_WINT_T__ 2 // PIC16:#define __SIZE_TYPE__ unsigned int // PIC16:#define __SIZE_WIDTH__ 16 // PIC16:#define __UINTMAX_TYPE__ long unsigned int @@ -535,6 +607,8 @@ // PPC64:#define _BIG_ENDIAN 1 // PPC64:#define _LP64 1 // PPC64:#define __BIG_ENDIAN__ 1 +// PPC64:#define __CHAR16_TYPE__ unsigned short +// PPC64:#define __CHAR32_TYPE__ unsigned int // PPC64:#define __CHAR_BIT__ 8 // PPC64:#define __CHAR_UNSIGNED__ 1 // PPC64:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 @@ -604,6 +678,18 @@ // PPC64:#define __SCHAR_MAX__ 127 // PPC64:#define __SHRT_MAX__ 32767 // PPC64:#define __SIG_ATOMIC_WIDTH__ 32 +// PPC64:#define __SIZEOF_DOUBLE__ 8 +// PPC64:#define __SIZEOF_FLOAT__ 4 +// PPC64:#define __SIZEOF_INT__ 4 +// PPC64:#define __SIZEOF_LONG_DOUBLE__ 8 +// PPC64:#define __SIZEOF_LONG_LONG__ 8 +// PPC64:#define __SIZEOF_LONG__ 8 +// PPC64:#define __SIZEOF_POINTER__ 8 +// PPC64:#define __SIZEOF_PTRDIFF_T__ 8 +// PPC64:#define __SIZEOF_SHORT__ 2 +// PPC64:#define __SIZEOF_SIZE_T__ 8 +// PPC64:#define __SIZEOF_WCHAR_T__ 4 +// PPC64:#define __SIZEOF_WINT_T__ 4 // PPC64:#define __SIZE_TYPE__ long unsigned int // PPC64:#define __SIZE_WIDTH__ 64 // PPC64:#define __UINTMAX_TYPE__ long unsigned int @@ -621,6 +707,8 @@ // PPC:#define _ARCH_PPC 1 // PPC:#define _BIG_ENDIAN 1 // PPC:#define __BIG_ENDIAN__ 1 +// PPC:#define __CHAR16_TYPE__ unsigned short +// PPC:#define __CHAR32_TYPE__ unsigned int // PPC:#define __CHAR_BIT__ 8 // PPC:#define __CHAR_UNSIGNED__ 1 // PPC:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 @@ -689,6 +777,18 @@ // PPC:#define __SCHAR_MAX__ 127 // PPC:#define __SHRT_MAX__ 32767 // PPC:#define __SIG_ATOMIC_WIDTH__ 32 +// PPC:#define __SIZEOF_DOUBLE__ 8 +// PPC:#define __SIZEOF_FLOAT__ 4 +// PPC:#define __SIZEOF_INT__ 4 +// PPC:#define __SIZEOF_LONG_DOUBLE__ 8 +// PPC:#define __SIZEOF_LONG_LONG__ 8 +// PPC:#define __SIZEOF_LONG__ 4 +// PPC:#define __SIZEOF_POINTER__ 4 +// PPC:#define __SIZEOF_PTRDIFF_T__ 4 +// PPC:#define __SIZEOF_SHORT__ 2 +// PPC:#define __SIZEOF_SIZE_T__ 4 +// PPC:#define __SIZEOF_WCHAR_T__ 4 +// PPC:#define __SIZEOF_WINT_T__ 4 // PPC:#define __SIZE_TYPE__ long unsigned int // PPC:#define __SIZE_WIDTH__ 32 // PPC:#define __UINTMAX_TYPE__ long long unsigned int @@ -702,6 +802,8 @@ // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=s390x-none-none -fno-signed-char < /dev/null | FileCheck -check-prefix S390X %s // +// S390X:#define __CHAR16_TYPE__ unsigned short +// S390X:#define __CHAR32_TYPE__ unsigned int // S390X:#define __CHAR_BIT__ 8 // S390X:#define __CHAR_UNSIGNED__ 1 // S390X:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 @@ -766,6 +868,18 @@ // S390X:#define __SCHAR_MAX__ 127 // S390X:#define __SHRT_MAX__ 32767 // S390X:#define __SIG_ATOMIC_WIDTH__ 32 +// S390X:#define __SIZEOF_DOUBLE__ 8 +// S390X:#define __SIZEOF_FLOAT__ 4 +// S390X:#define __SIZEOF_INT__ 4 +// S390X:#define __SIZEOF_LONG_DOUBLE__ 8 +// S390X:#define __SIZEOF_LONG_LONG__ 8 +// S390X:#define __SIZEOF_LONG__ 8 +// S390X:#define __SIZEOF_POINTER__ 8 +// S390X:#define __SIZEOF_PTRDIFF_T__ 8 +// S390X:#define __SIZEOF_SHORT__ 2 +// S390X:#define __SIZEOF_SIZE_T__ 8 +// S390X:#define __SIZEOF_WCHAR_T__ 4 +// S390X:#define __SIZEOF_WINT_T__ 4 // S390X:#define __SIZE_TYPE__ long unsigned int // S390X:#define __SIZE_WIDTH__ 64 // S390X:#define __UINTMAX_TYPE__ long long unsigned int @@ -780,6 +894,8 @@ // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=sparc-none-none < /dev/null | FileCheck -check-prefix SPARC %s // +// SPARC:#define __CHAR16_TYPE__ unsigned short +// SPARC:#define __CHAR32_TYPE__ unsigned int // SPARC:#define __CHAR_BIT__ 8 // SPARC:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 // SPARC:#define __DBL_DIG__ 15 @@ -844,6 +960,18 @@ // SPARC:#define __SCHAR_MAX__ 127 // SPARC:#define __SHRT_MAX__ 32767 // SPARC:#define __SIG_ATOMIC_WIDTH__ 32 +// SPARC:#define __SIZEOF_DOUBLE__ 8 +// SPARC:#define __SIZEOF_FLOAT__ 4 +// SPARC:#define __SIZEOF_INT__ 4 +// SPARC:#define __SIZEOF_LONG_DOUBLE__ 8 +// SPARC:#define __SIZEOF_LONG_LONG__ 8 +// SPARC:#define __SIZEOF_LONG__ 4 +// SPARC:#define __SIZEOF_POINTER__ 4 +// SPARC:#define __SIZEOF_PTRDIFF_T__ 4 +// SPARC:#define __SIZEOF_SHORT__ 2 +// SPARC:#define __SIZEOF_SIZE_T__ 4 +// SPARC:#define __SIZEOF_WCHAR_T__ 4 +// SPARC:#define __SIZEOF_WINT_T__ 4 // SPARC:#define __SIZE_TYPE__ long unsigned int // SPARC:#define __SIZE_WIDTH__ 32 // SPARC:#define __UINTMAX_TYPE__ long long unsigned int @@ -861,6 +989,8 @@ // // RUN: %clang_cc1 -E -dM -ffreestanding -triple=tce-none-none < /dev/null | FileCheck -check-prefix TCE %s // +// TCE:#define __CHAR16_TYPE__ unsigned short +// TCE:#define __CHAR32_TYPE__ unsigned int // TCE:#define __CHAR_BIT__ 8 // TCE:#define __DBL_DENORM_MIN__ 1.40129846e-45F // TCE:#define __DBL_DIG__ 6 @@ -922,6 +1052,18 @@ // TCE:#define __SCHAR_MAX__ 127 // TCE:#define __SHRT_MAX__ 32767 // TCE:#define __SIG_ATOMIC_WIDTH__ 32 +// TCE:#define __SIZEOF_DOUBLE__ 4 +// TCE:#define __SIZEOF_FLOAT__ 4 +// TCE:#define __SIZEOF_INT__ 4 +// TCE:#define __SIZEOF_LONG_DOUBLE__ 4 +// TCE:#define __SIZEOF_LONG_LONG__ 4 +// TCE:#define __SIZEOF_LONG__ 4 +// TCE:#define __SIZEOF_POINTER__ 4 +// TCE:#define __SIZEOF_PTRDIFF_T__ 4 +// TCE:#define __SIZEOF_SHORT__ 2 +// TCE:#define __SIZEOF_SIZE_T__ 4 +// TCE:#define __SIZEOF_WCHAR_T__ 4 +// TCE:#define __SIZEOF_WINT_T__ 4 // TCE:#define __SIZE_TYPE__ unsigned int // TCE:#define __SIZE_WIDTH__ 32 // TCE:#define __TCE_V1__ 1 @@ -940,6 +1082,8 @@ // RUN: %clang_cc1 -E -dM -ffreestanding -triple=x86_64-none-none < /dev/null | FileCheck -check-prefix X86_64 %s // // X86_64:#define _LP64 1 +// X86_64:#define __CHAR16_TYPE__ unsigned short +// X86_64:#define __CHAR32_TYPE__ unsigned int // X86_64:#define __CHAR_BIT__ 8 // X86_64:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 // X86_64:#define __DBL_DIG__ 15 @@ -1008,6 +1152,18 @@ // X86_64:#define __SCHAR_MAX__ 127 // X86_64:#define __SHRT_MAX__ 32767 // X86_64:#define __SIG_ATOMIC_WIDTH__ 32 +// X86_64:#define __SIZEOF_DOUBLE__ 8 +// X86_64:#define __SIZEOF_FLOAT__ 4 +// X86_64:#define __SIZEOF_INT__ 4 +// X86_64:#define __SIZEOF_LONG_DOUBLE__ 16 +// X86_64:#define __SIZEOF_LONG_LONG__ 8 +// X86_64:#define __SIZEOF_LONG__ 8 +// X86_64:#define __SIZEOF_POINTER__ 8 +// X86_64:#define __SIZEOF_PTRDIFF_T__ 8 +// X86_64:#define __SIZEOF_SHORT__ 2 +// X86_64:#define __SIZEOF_SIZE_T__ 8 +// X86_64:#define __SIZEOF_WCHAR_T__ 4 +// X86_64:#define __SIZEOF_WINT_T__ 4 // X86_64:#define __SIZE_TYPE__ long unsigned int // X86_64:#define __SIZE_WIDTH__ 64 // X86_64:#define __SSE2_MATH__ 1 @@ -1032,3 +1188,7 @@ // RUN: %clang_cc1 -x c++ -triple i686-pc-linux-gnu -E -dM < /dev/null | FileCheck -check-prefix GNUSOURCE %s // GNUSOURCE:#define _GNU_SOURCE 1 // +// RUN: %clang_cc1 -x c++ -std=c++98 -fno-rtti -E -dM < /dev/null | FileCheck -check-prefix NORTTI %s +// NORTTI: __GXX_ABI_VERSION +// NORTTI-NOT:#define __GXX_RTTI +// NORTTI: __STDC__