aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Frontend/InitPreprocessor.cpp3
-rw-r--r--lib/Headers/stdint.h9
-rw-r--r--test/Preprocessor/stdint.c6
3 files changed, 16 insertions, 2 deletions
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