From: Eli Friedman Date: Thu, 21 Apr 2011 05:45:45 +0000 (+0000) Subject: PR9772: Fix the definition of WINT_MIN and WINT_MAX on Linux -ffreestanding. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1cfeefdb383b106f63d91dd715f54339467d6aa8;p=clang PR9772: Fix the definition of WINT_MIN and WINT_MAX on Linux -ffreestanding. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129907 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index 928e84b185..ff3cf4b9cd 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -419,6 +419,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI, if (!LangOpts.CharIsSigned) Builder.defineMacro("__CHAR_UNSIGNED__"); + if (!TargetInfo::isTypeSigned(TI.getWIntType())) + Builder.defineMacro("__WINT_UNSIGNED__"); + // Define exact-width integer types for stdint.h Builder.defineMacro("__INT" + llvm::Twine(TI.getCharWidth()) + "_TYPE__", "char"); diff --git a/lib/Headers/stdint.h b/lib/Headers/stdint.h index d2ba8de135..ed3240abc9 100644 --- a/lib/Headers/stdint.h +++ b/lib/Headers/stdint.h @@ -630,8 +630,13 @@ typedef __UINTMAX_TYPE__ uintmax_t; /* C99 7.18.3 Limits of other integer types. */ #define SIG_ATOMIC_MIN __INTN_MIN(__SIG_ATOMIC_WIDTH__) #define SIG_ATOMIC_MAX __INTN_MAX(__SIG_ATOMIC_WIDTH__) -#define WINT_MIN __INTN_MIN(__WINT_WIDTH__) -#define WINT_MAX __INTN_MAX(__WINT_WIDTH__) +#ifdef __WINT_UNSIGNED__ +# define WINT_MIN 0 +# define WINT_MAX __UINTN_MAX(__WINT_WIDTH__) +#else +# define WINT_MIN __INTN_MIN(__WINT_WIDTH__) +# define WINT_MAX __INTN_MAX(__WINT_WIDTH__) +#endif /* FIXME: if we ever support a target with unsigned wchar_t, this should be * 0 .. Max. diff --git a/test/Preprocessor/stdint.c b/test/Preprocessor/stdint.c index b3ae843803..4821cf423f 100644 --- a/test/Preprocessor/stdint.c +++ b/test/Preprocessor/stdint.c @@ -1059,6 +1059,12 @@ // X86_64:UINTMAX_C_(0) 0UL // // +// RUN: %clang_cc1 -E -ffreestanding -triple=x86_64-pc-linux-gnu %s | FileCheck -check-prefix X86_64_LINUX %s +// +// X86_64_LINUX:WINT_MIN_ 0 +// X86_64_LINUX:WINT_MAX_ 4294967295U +// +// // stdint.h forms several macro definitions by pasting together identifiers // to form names (eg. int32_t is formed from int ## 32 ## _t). The following // case tests that these joining operations are performed correctly even if