forked from OSchip/llvm-project
Implement predefined stdint macros
Add predefined stdint macros that match the given patterns: U?INT{_,_FAST,_LEAST}{8,16,32,64}_{MAX,TYPE} U?INT{PTR,MAX}_{MAX,TYPE} http://reviews.llvm.org/D4141 Author: binji llvm-svn: 211657
This commit is contained in:
parent
7899d5049b
commit
ab8d0a0dd5
|
@ -214,6 +214,9 @@ public:
|
|||
return AddrSpace == 0 ? PtrDiffType : getPtrDiffTypeV(AddrSpace);
|
||||
}
|
||||
IntType getIntPtrType() const { return IntPtrType; }
|
||||
IntType getUIntPtrType() const {
|
||||
return getIntTypeByWidth(getTypeWidth(IntPtrType), false);
|
||||
}
|
||||
IntType getWCharType() const { return WCharType; }
|
||||
IntType getWIntType() const { return WIntType; }
|
||||
IntType getChar16Type() const { return Char16Type; }
|
||||
|
@ -230,6 +233,9 @@ public:
|
|||
/// \brief Return integer type with specified width.
|
||||
IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
|
||||
|
||||
/// \brief Return the smallest integer type with at least the specified width.
|
||||
IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const;
|
||||
|
||||
/// \brief Return floating point type with specified width.
|
||||
RealType getRealTypeByWidth(unsigned BitWidth) const;
|
||||
|
||||
|
|
|
@ -168,6 +168,21 @@ TargetInfo::IntType TargetInfo::getIntTypeByWidth(
|
|||
return NoInt;
|
||||
}
|
||||
|
||||
TargetInfo::IntType TargetInfo::getLeastIntTypeByWidth(unsigned BitWidth,
|
||||
bool IsSigned) const {
|
||||
if (getCharWidth() >= BitWidth)
|
||||
return IsSigned ? SignedChar : UnsignedChar;
|
||||
if (getShortWidth() >= BitWidth)
|
||||
return IsSigned ? SignedShort : UnsignedShort;
|
||||
if (getIntWidth() >= BitWidth)
|
||||
return IsSigned ? SignedInt : UnsignedInt;
|
||||
if (getLongWidth() >= BitWidth)
|
||||
return IsSigned ? SignedLong : UnsignedLong;
|
||||
if (getLongLongWidth() >= BitWidth)
|
||||
return IsSigned ? SignedLongLong : UnsignedLongLong;
|
||||
return NoInt;
|
||||
}
|
||||
|
||||
TargetInfo::RealType TargetInfo::getRealTypeByWidth(unsigned BitWidth) const {
|
||||
if (getFloatWidth() == BitWidth)
|
||||
return Float;
|
||||
|
|
|
@ -180,7 +180,7 @@ static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix,
|
|||
/// DefineTypeSize - Emit a macro to the predefines buffer that declares a macro
|
||||
/// named MacroName with the max value for a type with width 'TypeWidth' a
|
||||
/// signedness of 'isSigned' and with a value suffix of 'ValSuffix' (e.g. LL).
|
||||
static void DefineTypeSize(StringRef MacroName, unsigned TypeWidth,
|
||||
static void DefineTypeSize(const Twine &MacroName, unsigned TypeWidth,
|
||||
StringRef ValSuffix, bool isSigned,
|
||||
MacroBuilder &Builder) {
|
||||
llvm::APInt MaxVal = isSigned ? llvm::APInt::getSignedMaxValue(TypeWidth)
|
||||
|
@ -190,7 +190,7 @@ static void DefineTypeSize(StringRef MacroName, unsigned TypeWidth,
|
|||
|
||||
/// DefineTypeSize - An overloaded helper that uses TargetInfo to determine
|
||||
/// the width, suffix, and signedness of the given type
|
||||
static void DefineTypeSize(StringRef MacroName, TargetInfo::IntType Ty,
|
||||
static void DefineTypeSize(const Twine &MacroName, TargetInfo::IntType Ty,
|
||||
const TargetInfo &TI, MacroBuilder &Builder) {
|
||||
DefineTypeSize(MacroName, TI.getTypeWidth(Ty), TI.getTypeConstantSuffix(Ty),
|
||||
TI.isTypeSigned(Ty), Builder);
|
||||
|
@ -212,23 +212,68 @@ static void DefineTypeSizeof(StringRef MacroName, unsigned BitWidth,
|
|||
Twine(BitWidth / TI.getCharWidth()));
|
||||
}
|
||||
|
||||
static void DefineExactWidthIntType(TargetInfo::IntType Ty,
|
||||
const TargetInfo &TI, MacroBuilder &Builder) {
|
||||
static void DefineExactWidthIntType(TargetInfo::IntType Ty,
|
||||
const TargetInfo &TI,
|
||||
MacroBuilder &Builder) {
|
||||
int TypeWidth = TI.getTypeWidth(Ty);
|
||||
bool IsSigned = TI.isTypeSigned(Ty);
|
||||
|
||||
// Use the target specified int64 type, when appropriate, so that [u]int64_t
|
||||
// ends up being defined in terms of the correct type.
|
||||
if (TypeWidth == 64)
|
||||
Ty = TI.getInt64Type();
|
||||
Ty = IsSigned ? TI.getInt64Type() : TI.getIntTypeByWidth(64, false);
|
||||
|
||||
DefineType("__INT" + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
|
||||
Twine Prefix = IsSigned ? "__INT" : "__UINT";
|
||||
|
||||
DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
|
||||
|
||||
StringRef ConstSuffix(TargetInfo::getTypeConstantSuffix(Ty));
|
||||
if (!ConstSuffix.empty())
|
||||
Builder.defineMacro("__INT" + Twine(TypeWidth) + "_C_SUFFIX__",
|
||||
ConstSuffix);
|
||||
Builder.defineMacro(Prefix + Twine(TypeWidth) + "_C_SUFFIX__", ConstSuffix);
|
||||
|
||||
}
|
||||
|
||||
static void DefineExactWidthIntTypeSize(TargetInfo::IntType Ty,
|
||||
const TargetInfo &TI,
|
||||
MacroBuilder &Builder) {
|
||||
int TypeWidth = TI.getTypeWidth(Ty);
|
||||
bool IsSigned = TI.isTypeSigned(Ty);
|
||||
|
||||
// Use the target specified int64 type, when appropriate, so that [u]int64_t
|
||||
// ends up being defined in terms of the correct type.
|
||||
if (TypeWidth == 64)
|
||||
Ty = IsSigned ? TI.getInt64Type() : TI.getIntTypeByWidth(64, false);
|
||||
|
||||
Twine Prefix = IsSigned ? "__INT" : "__UINT";
|
||||
DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
|
||||
}
|
||||
|
||||
static void DefineLeastWidthIntType(unsigned TypeWidth, bool IsSigned,
|
||||
const TargetInfo &TI,
|
||||
MacroBuilder &Builder) {
|
||||
TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned);
|
||||
if (Ty == TargetInfo::NoInt)
|
||||
return;
|
||||
|
||||
Twine Prefix = IsSigned ? "__INT_LEAST" : "__UINT_LEAST";
|
||||
DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
|
||||
DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
|
||||
}
|
||||
|
||||
static void DefineFastIntType(unsigned TypeWidth, bool IsSigned,
|
||||
const TargetInfo &TI, MacroBuilder &Builder) {
|
||||
// stdint.h currently defines the fast int types as equivalent to the least
|
||||
// types.
|
||||
TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned);
|
||||
if (Ty == TargetInfo::NoInt)
|
||||
return;
|
||||
|
||||
Twine Prefix = IsSigned ? "__INT_FAST" : "__UINT_FAST";
|
||||
DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
|
||||
DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
|
||||
}
|
||||
|
||||
|
||||
/// Get the value the ATOMIC_*_LOCK_FREE macro should have for a type with
|
||||
/// the specified properties.
|
||||
static const char *getLockFreeValue(unsigned TypeWidth, unsigned TypeAlign,
|
||||
|
@ -563,6 +608,13 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
|
|||
DefineTypeSize("__INTMAX_MAX__", TI.getIntMaxType(), TI, Builder);
|
||||
DefineTypeSize("__SIZE_MAX__", TI.getSizeType(), TI, Builder);
|
||||
|
||||
if (!LangOpts.MSVCCompat) {
|
||||
DefineTypeSize("__UINTMAX_MAX__", TI.getUIntMaxType(), TI, Builder);
|
||||
DefineTypeSize("__PTRDIFF_MAX__", TI.getPtrDiffType(0), TI, Builder);
|
||||
DefineTypeSize("__INTPTR_MAX__", TI.getIntPtrType(), TI, Builder);
|
||||
DefineTypeSize("__UINTPTR_MAX__", TI.getUIntPtrType(), TI, Builder);
|
||||
}
|
||||
|
||||
DefineTypeSizeof("__SIZEOF_DOUBLE__", TI.getDoubleWidth(), TI, Builder);
|
||||
DefineTypeSizeof("__SIZEOF_FLOAT__", TI.getFloatWidth(), TI, Builder);
|
||||
DefineTypeSizeof("__SIZEOF_INT__", TI.getIntWidth(), TI, Builder);
|
||||
|
@ -599,6 +651,12 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
|
|||
DefineType("__CHAR16_TYPE__", TI.getChar16Type(), Builder);
|
||||
DefineType("__CHAR32_TYPE__", TI.getChar32Type(), Builder);
|
||||
|
||||
if (!LangOpts.MSVCCompat) {
|
||||
DefineTypeWidth("__UINTMAX_WIDTH__", TI.getUIntMaxType(), TI, Builder);
|
||||
DefineType("__UINTPTR_TYPE__", TI.getUIntPtrType(), Builder);
|
||||
DefineTypeWidth("__UINTPTR_WIDTH__", TI.getUIntPtrType(), TI, Builder);
|
||||
}
|
||||
|
||||
DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
|
||||
DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
|
||||
DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
|
||||
|
@ -632,6 +690,54 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
|
|||
if (TI.getLongLongWidth() > TI.getLongWidth())
|
||||
DefineExactWidthIntType(TargetInfo::SignedLongLong, TI, Builder);
|
||||
|
||||
if (!LangOpts.MSVCCompat) {
|
||||
DefineExactWidthIntType(TargetInfo::UnsignedChar, TI, Builder);
|
||||
DefineExactWidthIntTypeSize(TargetInfo::UnsignedChar, TI, Builder);
|
||||
DefineExactWidthIntTypeSize(TargetInfo::SignedChar, TI, Builder);
|
||||
|
||||
if (TI.getShortWidth() > TI.getCharWidth()) {
|
||||
DefineExactWidthIntType(TargetInfo::UnsignedShort, TI, Builder);
|
||||
DefineExactWidthIntTypeSize(TargetInfo::UnsignedShort, TI, Builder);
|
||||
DefineExactWidthIntTypeSize(TargetInfo::SignedShort, TI, Builder);
|
||||
}
|
||||
|
||||
if (TI.getIntWidth() > TI.getShortWidth()) {
|
||||
DefineExactWidthIntType(TargetInfo::UnsignedInt, TI, Builder);
|
||||
DefineExactWidthIntTypeSize(TargetInfo::UnsignedInt, TI, Builder);
|
||||
DefineExactWidthIntTypeSize(TargetInfo::SignedInt, TI, Builder);
|
||||
}
|
||||
|
||||
if (TI.getLongWidth() > TI.getIntWidth()) {
|
||||
DefineExactWidthIntType(TargetInfo::UnsignedLong, TI, Builder);
|
||||
DefineExactWidthIntTypeSize(TargetInfo::UnsignedLong, TI, Builder);
|
||||
DefineExactWidthIntTypeSize(TargetInfo::SignedLong, TI, Builder);
|
||||
}
|
||||
|
||||
if (TI.getLongLongWidth() > TI.getLongWidth()) {
|
||||
DefineExactWidthIntType(TargetInfo::UnsignedLongLong, TI, Builder);
|
||||
DefineExactWidthIntTypeSize(TargetInfo::UnsignedLongLong, TI, Builder);
|
||||
DefineExactWidthIntTypeSize(TargetInfo::SignedLongLong, TI, Builder);
|
||||
}
|
||||
|
||||
DefineLeastWidthIntType(8, true, TI, Builder);
|
||||
DefineLeastWidthIntType(8, false, TI, Builder);
|
||||
DefineLeastWidthIntType(16, true, TI, Builder);
|
||||
DefineLeastWidthIntType(16, false, TI, Builder);
|
||||
DefineLeastWidthIntType(32, true, TI, Builder);
|
||||
DefineLeastWidthIntType(32, false, TI, Builder);
|
||||
DefineLeastWidthIntType(64, true, TI, Builder);
|
||||
DefineLeastWidthIntType(64, false, TI, Builder);
|
||||
|
||||
DefineFastIntType(8, true, TI, Builder);
|
||||
DefineFastIntType(8, false, TI, Builder);
|
||||
DefineFastIntType(16, true, TI, Builder);
|
||||
DefineFastIntType(16, false, TI, Builder);
|
||||
DefineFastIntType(32, true, TI, Builder);
|
||||
DefineFastIntType(32, false, TI, Builder);
|
||||
DefineFastIntType(64, true, TI, Builder);
|
||||
DefineFastIntType(64, false, TI, Builder);
|
||||
}
|
||||
|
||||
if (const char *Prefix = TI.getUserLabelPrefix())
|
||||
Builder.defineMacro("__USER_LABEL_PREFIX__", Prefix);
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -10,6 +10,62 @@
|
|||
// CHECK-MS: #define _WIN32 1
|
||||
// CHECK-MS-NOT: #define __GNUC__
|
||||
//
|
||||
// RUN: %clang_cc1 %s -E -dM -triple i686-pc-win32 -fms-compatibility \
|
||||
// RUN: -o - | FileCheck %s --check-prefix=CHECK-MS-STDINT
|
||||
// CHECK-MS-STDINT-NOT:#define __INT16_MAX__ 32767
|
||||
// CHECK-MS-STDINT-NOT:#define __INT32_MAX__ 2147483647
|
||||
// CHECK-MS-STDINT-NOT:#define __INT64_MAX__ 9223372036854775807LL
|
||||
// CHECK-MS-STDINT-NOT:#define __INT8_MAX__ 127
|
||||
// CHECK-MS-STDINT-NOT:#define __INTPTR_MAX__ 2147483647
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_FAST16_MAX__ 32767
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_FAST16_TYPE__ short
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_FAST32_MAX__ 2147483647
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_FAST32_TYPE__ int
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_FAST64_MAX__ 9223372036854775807LL
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_FAST64_TYPE__ long long int
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_FAST8_MAX__ 127
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_FAST8_TYPE__ char
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_LEAST16_MAX__ 32767
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_LEAST16_TYPE__ short
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_LEAST32_MAX__ 2147483647
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_LEAST32_TYPE__ int
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_LEAST64_MAX__ 9223372036854775807LL
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_LEAST64_TYPE__ long long int
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_LEAST8_MAX__ 127
|
||||
// CHECK-MS-STDINT-NOT:#define __INT_LEAST8_TYPE__ char
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT16_C_SUFFIX__ U
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT16_MAX__ 65535U
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT16_TYPE__ unsigned short
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT32_C_SUFFIX__ U
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT32_MAX__ 4294967295U
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT32_TYPE__ unsigned int
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT64_C_SUFFIX__ ULL
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT64_MAX__ 18446744073709551615ULL
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT64_TYPE__ long long unsigned int
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT8_C_SUFFIX__ U
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT8_MAX__ 255U
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT8_TYPE__ unsigned char
|
||||
// CHECK-MS-STDINT-NOT:#define __UINTMAX_MAX__ 18446744073709551615ULL
|
||||
// CHECK-MS-STDINT-NOT:#define __UINTPTR_MAX__ 4294967295U
|
||||
// CHECK-MS-STDINT-NOT:#define __UINTPTR_TYPE__ unsigned int
|
||||
// CHECK-MS-STDINT-NOT:#define __UINTPTR_WIDTH__ 32
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_FAST16_MAX__ 65535U
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_FAST16_TYPE__ unsigned short
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_FAST32_MAX__ 4294967295U
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_FAST32_TYPE__ unsigned int
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_FAST64_MAX__ 18446744073709551615ULL
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_FAST64_TYPE__ long long unsigned int
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_FAST8_MAX__ 255U
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_FAST8_TYPE__ unsigned char
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_LEAST16_MAX__ 65535U
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_LEAST16_TYPE__ unsigned short
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_LEAST32_MAX__ 4294967295U
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_LEAST32_TYPE__ unsigned int
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_LEAST64_MAX__ 18446744073709551615ULL
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_LEAST64_TYPE__ long long unsigned int
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_LEAST8_MAX__ 255U
|
||||
// CHECK-MS-STDINT-NOT:#define __UINT_LEAST8_TYPE__ unsigned char
|
||||
//
|
||||
// RUN: %clang_cc1 %s -E -dM -ffast-math -o - \
|
||||
// RUN: | FileCheck %s --check-prefix=CHECK-FAST-MATH
|
||||
// CHECK-FAST-MATH: #define __FAST_MATH__
|
||||
|
|
Loading…
Reference in New Issue