If char/short are shorter than int, do not use U as suffix for

constants. Comparing int against a constant of the given type like
UINT8_MAX will otherwise force a promotion to unsigned int, which is
typically not expected.

llvm-svn: 213301
This commit is contained in:
Joerg Sonnenberger 2014-07-17 20:12:32 +00:00
parent 11698180c3
commit 587deea875
5 changed files with 270 additions and 266 deletions

View File

@ -446,7 +446,7 @@ public:
/// \brief Return the constant suffix for the specified integer type enum.
///
/// For example, SignedLong -> "L".
static const char *getTypeConstantSuffix(IntType T);
const char *getTypeConstantSuffix(IntType T) const;
/// \brief Return the printf format modifier for the specified
/// integer type enum.

View File

@ -118,7 +118,7 @@ const char *TargetInfo::getTypeName(IntType T) {
/// getTypeConstantSuffix - Return the constant suffix for the specified
/// integer type enum. For example, SignedLong -> "L".
const char *TargetInfo::getTypeConstantSuffix(IntType T) {
const char *TargetInfo::getTypeConstantSuffix(IntType T) const {
switch (T) {
default: llvm_unreachable("not an integer!");
case SignedChar:
@ -127,7 +127,11 @@ const char *TargetInfo::getTypeConstantSuffix(IntType T) {
case SignedLong: return "L";
case SignedLongLong: return "LL";
case UnsignedChar:
if (getCharWidth() < getIntWidth())
return "";
case UnsignedShort:
if (getShortWidth() < getIntWidth())
return "";
case UnsignedInt: return "U";
case UnsignedLong: return "UL";
case UnsignedLongLong: return "ULL";

View File

@ -238,7 +238,7 @@ static void DefineExactWidthIntType(TargetInfo::IntType Ty,
DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
StringRef ConstSuffix(TargetInfo::getTypeConstantSuffix(Ty));
StringRef ConstSuffix(TI.getTypeConstantSuffix(Ty));
Builder.defineMacro(Prefix + Twine(TypeWidth) + "_C_SUFFIX__", ConstSuffix);
}
@ -655,11 +655,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Builder);
DefineFmt("__INTMAX", TI.getIntMaxType(), TI, Builder);
Builder.defineMacro("__INTMAX_C_SUFFIX__",
TargetInfo::getTypeConstantSuffix(TI.getIntMaxType()));
TI.getTypeConstantSuffix(TI.getIntMaxType()));
DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Builder);
DefineFmt("__UINTMAX", TI.getUIntMaxType(), TI, Builder);
Builder.defineMacro("__UINTMAX_C_SUFFIX__",
TargetInfo::getTypeConstantSuffix(TI.getUIntMaxType()));
TI.getTypeConstantSuffix(TI.getUIntMaxType()));
DefineTypeWidth("__INTMAX_WIDTH__", TI.getIntMaxType(), TI, Builder);
DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(0), Builder);
DefineFmt("__PTRDIFF", TI.getPtrDiffType(0), TI, Builder);

File diff suppressed because it is too large Load Diff

View File

@ -1173,8 +1173,8 @@
//
// RUN: %clang_cc1 -E -ffreestanding -triple=i386-mingw32 %s | FileCheck -check-prefix I386_MINGW32 %s
//
// I386_MINGW32:WCHAR_MAX_ 65535U
// I386_MINGW32:WCHAR_MIN_ 0U
// I386_MINGW32:WCHAR_MAX_ 65535
// I386_MINGW32:WCHAR_MIN_ 0
//
//
// RUN: %clang_cc1 -E -ffreestanding -triple=xcore-none-none %s | FileCheck -check-prefix XCORE %s
@ -1269,7 +1269,7 @@
// XCORE:WINT_MIN_ 0U
// XCORE:WINT_MAX_ 4294967295U
//
// XCORE:WCHAR_MAX_ 255U
// XCORE:WCHAR_MAX_ 255
// XCORE:WCHAR_MIN_ 0
//
// XCORE:INT8_C_(0) 0