[clang] bf7d997 - Support the *_WIDTH macros in limits.h and stdint.h
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 13 08:46:41 PST 2022
Author: Aaron Ballman
Date: 2022-01-13T11:46:34-05:00
New Revision: bf7d9970ba0ac5ecfa1a469086f5789de5c94e3f
URL: https://github.com/llvm/llvm-project/commit/bf7d9970ba0ac5ecfa1a469086f5789de5c94e3f
DIFF: https://github.com/llvm/llvm-project/commit/bf7d9970ba0ac5ecfa1a469086f5789de5c94e3f.diff
LOG: Support the *_WIDTH macros in limits.h and stdint.h
This completes the implementation of
WG14 N2412 (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2412.pdf),
which standardizes C on a twos complement representation for integer
types. The only work that remained there was to define the correct
macros in the standard headers, which this patch does.
Added:
clang/test/Headers/stdint.c
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Headers/limits.h
clang/lib/Headers/stdint.h
clang/test/Headers/limits.cpp
clang/test/Preprocessor/init-aarch64.c
clang/test/Preprocessor/init.c
clang/www/c_status.html
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5481a8cdb60d5..8b039b20c0d6e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -165,6 +165,10 @@ C Language Changes in Clang
`this thread <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103640>` for more
info.
+- Implemented `WG14 N2412 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2412.pdf>`_,
+ which adds ``*_WIDTH`` macros to limits.h and stdint.h to report the bit
+ width of various integer datatypes.
+
C++ Language Changes in Clang
-----------------------------
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index ec40170b0a788..a9023a7a1171e 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -194,7 +194,7 @@ static void DefineType(const Twine &MacroName, TargetInfo::IntType Ty,
Builder.defineMacro(MacroName, TargetInfo::getTypeName(Ty));
}
-static void DefineTypeWidth(StringRef MacroName, TargetInfo::IntType Ty,
+static void DefineTypeWidth(const Twine &MacroName, TargetInfo::IntType Ty,
const TargetInfo &TI, MacroBuilder &Builder) {
Builder.defineMacro(MacroName, Twine(TI.getTypeWidth(Ty)));
}
@@ -205,6 +205,16 @@ static void DefineTypeSizeof(StringRef MacroName, unsigned BitWidth,
Twine(BitWidth / TI.getCharWidth()));
}
+// This will generate a macro based on the prefix with `_MAX__` as the suffix
+// for the max value representable for the type, and a macro with a `_WIDTH__`
+// suffix for the width of the type.
+static void DefineTypeSizeAndWidth(const Twine &Prefix, TargetInfo::IntType Ty,
+ const TargetInfo &TI,
+ MacroBuilder &Builder) {
+ DefineTypeSize(Prefix + "_MAX__", Ty, TI, Builder);
+ DefineTypeWidth(Prefix + "_WIDTH__", Ty, TI, Builder);
+}
+
static void DefineExactWidthIntType(TargetInfo::IntType Ty,
const TargetInfo &TI,
MacroBuilder &Builder) {
@@ -241,6 +251,8 @@ static void DefineExactWidthIntTypeSize(TargetInfo::IntType Ty,
if (TypeWidth == 64)
Ty = IsSigned ? TI.getInt64Type() : TI.getUInt64Type();
+ // We don't need to define a _WIDTH macro for the exact-width types because
+ // we already know the width.
const char *Prefix = IsSigned ? "__INT" : "__UINT";
DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
}
@@ -254,7 +266,12 @@ static void DefineLeastWidthIntType(unsigned TypeWidth, bool IsSigned,
const char *Prefix = IsSigned ? "__INT_LEAST" : "__UINT_LEAST";
DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
- DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
+ // We only want the *_WIDTH macro for the signed types to avoid too many
+ // predefined macros (the unsigned width and the signed width are identical.)
+ if (IsSigned)
+ DefineTypeSizeAndWidth(Prefix + Twine(TypeWidth), Ty, TI, Builder);
+ else
+ DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
}
@@ -268,8 +285,12 @@ static void DefineFastIntType(unsigned TypeWidth, bool IsSigned,
const char *Prefix = IsSigned ? "__INT_FAST" : "__UINT_FAST";
DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
- DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
-
+ // We only want the *_WIDTH macro for the signed types to avoid too many
+ // predefined macros (the unsigned width and the signed width are identical.)
+ if (IsSigned)
+ DefineTypeSizeAndWidth(Prefix + Twine(TypeWidth), Ty, TI, Builder);
+ else
+ DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
}
@@ -887,20 +908,26 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far");
Builder.defineMacro("__CHAR_BIT__", Twine(TI.getCharWidth()));
+ Builder.defineMacro("__BOOL_WIDTH__", Twine(TI.getBoolWidth()));
+ Builder.defineMacro("__SHRT_WIDTH__", Twine(TI.getShortWidth()));
+ Builder.defineMacro("__INT_WIDTH__", Twine(TI.getIntWidth()));
+ Builder.defineMacro("__LONG_WIDTH__", Twine(TI.getLongWidth()));
+ Builder.defineMacro("__LLONG_WIDTH__", Twine(TI.getLongLongWidth()));
+
DefineTypeSize("__SCHAR_MAX__", TargetInfo::SignedChar, TI, Builder);
DefineTypeSize("__SHRT_MAX__", TargetInfo::SignedShort, TI, Builder);
DefineTypeSize("__INT_MAX__", TargetInfo::SignedInt, TI, Builder);
DefineTypeSize("__LONG_MAX__", TargetInfo::SignedLong, TI, Builder);
DefineTypeSize("__LONG_LONG_MAX__", TargetInfo::SignedLongLong, TI, Builder);
- DefineTypeSize("__WCHAR_MAX__", TI.getWCharType(), TI, Builder);
- DefineTypeSize("__WINT_MAX__", TI.getWIntType(), TI, Builder);
- DefineTypeSize("__INTMAX_MAX__", TI.getIntMaxType(), TI, Builder);
- DefineTypeSize("__SIZE_MAX__", TI.getSizeType(), TI, Builder);
+ DefineTypeSizeAndWidth("__WCHAR", TI.getWCharType(), TI, Builder);
+ DefineTypeSizeAndWidth("__WINT", TI.getWIntType(), TI, Builder);
+ DefineTypeSizeAndWidth("__INTMAX", TI.getIntMaxType(), TI, Builder);
+ DefineTypeSizeAndWidth("__SIZE", TI.getSizeType(), TI, Builder);
- 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);
+ DefineTypeSizeAndWidth("__UINTMAX", TI.getUIntMaxType(), TI, Builder);
+ DefineTypeSizeAndWidth("__PTRDIFF", TI.getPtrDiffType(0), TI, Builder);
+ DefineTypeSizeAndWidth("__INTPTR", TI.getIntPtrType(), TI, Builder);
+ DefineTypeSizeAndWidth("__UINTPTR", TI.getUIntPtrType(), TI, Builder);
DefineTypeSizeof("__SIZEOF_DOUBLE__", TI.getDoubleWidth(), TI, Builder);
DefineTypeSizeof("__SIZEOF_FLOAT__", TI.getFloatWidth(), TI, Builder);
@@ -929,29 +956,29 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
DefineFmt("__UINTMAX", TI.getUIntMaxType(), TI, Builder);
Builder.defineMacro("__UINTMAX_C_SUFFIX__",
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);
- DefineTypeWidth("__PTRDIFF_WIDTH__", TI.getPtrDiffType(0), TI, Builder);
DefineType("__INTPTR_TYPE__", TI.getIntPtrType(), Builder);
DefineFmt("__INTPTR", TI.getIntPtrType(), TI, Builder);
- DefineTypeWidth("__INTPTR_WIDTH__", TI.getIntPtrType(), TI, Builder);
DefineType("__SIZE_TYPE__", TI.getSizeType(), Builder);
DefineFmt("__SIZE", TI.getSizeType(), TI, Builder);
- DefineTypeWidth("__SIZE_WIDTH__", TI.getSizeType(), TI, Builder);
DefineType("__WCHAR_TYPE__", TI.getWCharType(), Builder);
- DefineTypeWidth("__WCHAR_WIDTH__", TI.getWCharType(), TI, Builder);
DefineType("__WINT_TYPE__", TI.getWIntType(), Builder);
- DefineTypeWidth("__WINT_WIDTH__", TI.getWIntType(), TI, Builder);
- DefineTypeWidth("__SIG_ATOMIC_WIDTH__", TI.getSigAtomicType(), TI, Builder);
- DefineTypeSize("__SIG_ATOMIC_MAX__", TI.getSigAtomicType(), TI, Builder);
+ DefineTypeSizeAndWidth("__SIG_ATOMIC", TI.getSigAtomicType(), TI, Builder);
DefineType("__CHAR16_TYPE__", TI.getChar16Type(), Builder);
DefineType("__CHAR32_TYPE__", TI.getChar32Type(), Builder);
- DefineTypeWidth("__UINTMAX_WIDTH__", TI.getUIntMaxType(), TI, Builder);
DefineType("__UINTPTR_TYPE__", TI.getUIntPtrType(), Builder);
DefineFmt("__UINTPTR", TI.getUIntPtrType(), TI, Builder);
- DefineTypeWidth("__UINTPTR_WIDTH__", TI.getUIntPtrType(), TI, Builder);
+
+ // The C standard requires the width of uintptr_t and intptr_t to be the same,
+ // per 7.20.2.4p1. Same for intmax_t and uintmax_t, per 7.20.2.5p1.
+ assert(TI.getTypeWidth(TI.getUIntPtrType()) ==
+ TI.getTypeWidth(TI.getIntPtrType()) &&
+ "uintptr_t and intptr_t have
diff erent widths?");
+ assert(TI.getTypeWidth(TI.getUIntMaxType()) ==
+ TI.getTypeWidth(TI.getIntMaxType()) &&
+ "uintmax_t and intmax_t have
diff erent widths?");
if (TI.hasFloat16Type())
DefineFloatMacros(Builder, "FLT16", &TI.getHalfFormat(), "F16");
diff --git a/clang/lib/Headers/limits.h b/clang/lib/Headers/limits.h
index c653580bac4e6..c2d3a7cf43539 100644
--- a/clang/lib/Headers/limits.h
+++ b/clang/lib/Headers/limits.h
@@ -62,6 +62,24 @@
#define CHAR_BIT __CHAR_BIT__
+/* C2x 5.2.4.2.1 */
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+#define BOOL_WIDTH __BOOL_WIDTH__
+#define CHAR_WIDTH CHAR_BIT
+#define SCHAR_WIDTH CHAR_BIT
+#define UCHAR_WIDTH CHAR_BIT
+#define USHRT_WIDTH __SHRT_WIDTH__
+#define SHRT_WIDTH __SHRT_WIDTH__
+#define UINT_WIDTH __INT_WIDTH__
+#define INT_WIDTH __INT_WIDTH__
+#define ULONG_WIDTH __LONG_WIDTH__
+#define LONG_WIDTH __LONG_WIDTH__
+#define ULLONG_WIDTH __LLONG_WIDTH__
+#define LLONG_WIDTH __LLONG_WIDTH__
+#endif
+
#ifdef __CHAR_UNSIGNED__ /* -funsigned-char */
#define CHAR_MIN 0
#define CHAR_MAX UCHAR_MAX
diff --git a/clang/lib/Headers/stdint.h b/clang/lib/Headers/stdint.h
index 192f653e95a11..4790c25a2774b 100644
--- a/clang/lib/Headers/stdint.h
+++ b/clang/lib/Headers/stdint.h
@@ -461,6 +461,18 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define INT64_MAX INT64_C( 9223372036854775807)
# define INT64_MIN (-INT64_C( 9223372036854775807)-1)
# define UINT64_MAX UINT64_C(18446744073709551615)
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+# define UINT64_WIDTH 64
+# define INT64_WIDTH UINT64_WIDTH
+
+# define __UINT_LEAST64_WIDTH UINT64_WIDTH
+# define __UINT_LEAST32_WIDTH UINT64_WIDTH
+# define __UINT_LEAST16_WIDTH UINT64_WIDTH
+# define __UINT_LEAST8_MAX UINT64_MAX
+#endif /* __STDC_VERSION__ */
+
# define __INT_LEAST64_MIN INT64_MIN
# define __INT_LEAST64_MAX INT64_MAX
# define __UINT_LEAST64_MAX UINT64_MAX
@@ -482,6 +494,15 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define INT_FAST64_MIN __INT_LEAST64_MIN
# define INT_FAST64_MAX __INT_LEAST64_MAX
# define UINT_FAST64_MAX __UINT_LEAST64_MAX
+
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+# define UINT_LEAST64_WIDTH __UINT_LEAST64_WIDTH
+# define INT_LEAST64_WIDTH UINT_LEAST64_WIDTH
+# define UINT_FAST64_WIDTH __UINT_LEAST64_WIDTH
+# define INT_FAST64_WIDTH UINT_FAST64_WIDTH
+#endif /* __STDC_VERSION__ */
#endif /* __INT_LEAST64_MIN */
@@ -495,6 +516,7 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define INT_FAST56_MIN INT56_MIN
# define INT_FAST56_MAX INT56_MAX
# define UINT_FAST56_MAX UINT56_MAX
+
# define __INT_LEAST32_MIN INT56_MIN
# define __INT_LEAST32_MAX INT56_MAX
# define __UINT_LEAST32_MAX UINT56_MAX
@@ -504,6 +526,20 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define __INT_LEAST8_MIN INT56_MIN
# define __INT_LEAST8_MAX INT56_MAX
# define __UINT_LEAST8_MAX UINT56_MAX
+
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+# define UINT56_WIDTH 56
+# define INT56_WIDTH UINT56_WIDTH
+# define UINT_LEAST56_WIDTH UINT56_WIDTH
+# define INT_LEAST56_WIDTH UINT_LEAST56_WIDTH
+# define UINT_FAST56_WIDTH UINT56_WIDTH
+# define INT_FAST56_WIDTH UINT_FAST56_WIDTH
+# define __UINT_LEAST32_WIDTH UINT56_WIDTH
+# define __UINT_LEAST16_WIDTH UINT56_WIDTH
+# define __UINT_LEAST8_WIDTH UINT56_WIDTH
+#endif /* __STDC_VERSION__ */
#endif /* __INT56_TYPE__ */
@@ -517,6 +553,7 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define INT_FAST48_MIN INT48_MIN
# define INT_FAST48_MAX INT48_MAX
# define UINT_FAST48_MAX UINT48_MAX
+
# define __INT_LEAST32_MIN INT48_MIN
# define __INT_LEAST32_MAX INT48_MAX
# define __UINT_LEAST32_MAX UINT48_MAX
@@ -526,6 +563,20 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define __INT_LEAST8_MIN INT48_MIN
# define __INT_LEAST8_MAX INT48_MAX
# define __UINT_LEAST8_MAX UINT48_MAX
+
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+#define UINT48_WIDTH 48
+#define INT48_WIDTH UINT48_WIDTH
+#define UINT_LEAST48_WIDTH UINT48_WIDTH
+#define INT_LEAST48_WIDTH UINT_LEAST48_WIDTH
+#define UINT_FAST48_WIDTH UINT48_WIDTH
+#define INT_FAST48_WIDTH UINT_FAST48_WIDTH
+#define __UINT_LEAST32_WIDTH UINT48_WIDTH
+#define __UINT_LEAST16_WIDTH UINT48_WIDTH
+#define __UINT_LEAST8_WIDTH UINT48_WIDTH
+#endif /* __STDC_VERSION__ */
#endif /* __INT48_TYPE__ */
@@ -539,6 +590,7 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define INT_FAST40_MIN INT40_MIN
# define INT_FAST40_MAX INT40_MAX
# define UINT_FAST40_MAX UINT40_MAX
+
# define __INT_LEAST32_MIN INT40_MIN
# define __INT_LEAST32_MAX INT40_MAX
# define __UINT_LEAST32_MAX UINT40_MAX
@@ -548,6 +600,20 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define __INT_LEAST8_MIN INT40_MIN
# define __INT_LEAST8_MAX INT40_MAX
# define __UINT_LEAST8_MAX UINT40_MAX
+
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+# define UINT40_WIDTH 40
+# define INT40_WIDTH UINT40_WIDTH
+# define UINT_LEAST40_WIDTH UINT40_WIDTH
+# define INT_LEAST40_WIDTH UINT_LEAST40_WIDTH
+# define UINT_FAST40_WIDTH UINT40_WIDTH
+# define INT_FAST40_WIDTH UINT_FAST40_WIDTH
+# define __UINT_LEAST32_WIDTH UINT40_WIDTH
+# define __UINT_LEAST16_WIDTH UINT40_WIDTH
+# define __UINT_LEAST8_WIDTH UINT40_WIDTH
+#endif /* __STDC_VERSION__ */
#endif /* __INT40_TYPE__ */
@@ -555,6 +621,7 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define INT32_MAX INT32_C(2147483647)
# define INT32_MIN (-INT32_C(2147483647)-1)
# define UINT32_MAX UINT32_C(4294967295)
+
# define __INT_LEAST32_MIN INT32_MIN
# define __INT_LEAST32_MAX INT32_MAX
# define __UINT_LEAST32_MAX UINT32_MAX
@@ -564,6 +631,16 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define __INT_LEAST8_MIN INT32_MIN
# define __INT_LEAST8_MAX INT32_MAX
# define __UINT_LEAST8_MAX UINT32_MAX
+
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+# define UINT32_WIDTH 32
+# define INT32_WIDTH UINT32_WIDTH
+# define __UINT_LEAST32_WIDTH UINT32_WIDTH
+# define __UINT_LEAST16_WIDTH UINT32_WIDTH
+# define __UINT_LEAST8_WIDTH UINT32_WIDTH
+#endif /* __STDC_VERSION__ */
#endif /* __INT32_TYPE__ */
#ifdef __INT_LEAST32_MIN
@@ -573,6 +650,15 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define INT_FAST32_MIN __INT_LEAST32_MIN
# define INT_FAST32_MAX __INT_LEAST32_MAX
# define UINT_FAST32_MAX __UINT_LEAST32_MAX
+
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+# define UINT_LEAST32_WIDTH __UINT_LEAST32_WIDTH
+# define INT_LEAST32_WIDTH UINT_LEAST32_WIDTH
+# define UINT_FAST32_WIDTH __UINT_LEAST32_WIDTH
+# define INT_FAST32_WIDTH UINT_FAST32_WIDTH
+#endif /* __STDC_VERSION__ */
#endif /* __INT_LEAST32_MIN */
@@ -586,12 +672,26 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define INT_FAST24_MIN INT24_MIN
# define INT_FAST24_MAX INT24_MAX
# define UINT_FAST24_MAX UINT24_MAX
+
# define __INT_LEAST16_MIN INT24_MIN
# define __INT_LEAST16_MAX INT24_MAX
# define __UINT_LEAST16_MAX UINT24_MAX
# define __INT_LEAST8_MIN INT24_MIN
# define __INT_LEAST8_MAX INT24_MAX
# define __UINT_LEAST8_MAX UINT24_MAX
+
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+# define UINT24_WIDTH 24
+# define INT24_WIDTH UINT24_WIDTH
+# define UINT_LEAST24_WIDTH UINT24_WIDTH
+# define INT_LEAST24_WIDTH UINT_LEAST24_WIDTH
+# define UINT_FAST24_WIDTH UINT24_WIDTH
+# define INT_FAST24_WIDTH UINT_FAST24_WIDTH
+# define __UINT_LEAST16_WIDTH UINT24_WIDTH
+# define __UINT_LEAST8_WIDTH UINT24_WIDTH
+#endif /* __STDC_VERSION__ */
#endif /* __INT24_TYPE__ */
@@ -599,12 +699,22 @@ typedef __UINTMAX_TYPE__ uintmax_t;
#define INT16_MAX INT16_C(32767)
#define INT16_MIN (-INT16_C(32767)-1)
#define UINT16_MAX UINT16_C(65535)
+
# define __INT_LEAST16_MIN INT16_MIN
# define __INT_LEAST16_MAX INT16_MAX
# define __UINT_LEAST16_MAX UINT16_MAX
# define __INT_LEAST8_MIN INT16_MIN
# define __INT_LEAST8_MAX INT16_MAX
# define __UINT_LEAST8_MAX UINT16_MAX
+
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+# define UINT16_WIDTH 16
+# define INT16_WIDTH UINT16_WIDTH
+# define __UINT_LEAST16_WIDTH UINT16_WIDTH
+# define __UINT_LEAST8_WIDTH UINT16_WIDTH
+#endif /* __STDC_VERSION__ */
#endif /* __INT16_TYPE__ */
#ifdef __INT_LEAST16_MIN
@@ -614,6 +724,15 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define INT_FAST16_MIN __INT_LEAST16_MIN
# define INT_FAST16_MAX __INT_LEAST16_MAX
# define UINT_FAST16_MAX __UINT_LEAST16_MAX
+
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+# define UINT_LEAST16_WIDTH __UINT_LEAST16_WIDTH
+# define INT_LEAST16_WIDTH UINT_LEAST16_WIDTH
+# define UINT_FAST16_WIDTH __UINT_LEAST16_WIDTH
+# define INT_FAST16_WIDTH UINT_FAST16_WIDTH
+#endif /* __STDC_VERSION__ */
#endif /* __INT_LEAST16_MIN */
@@ -621,9 +740,18 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define INT8_MAX INT8_C(127)
# define INT8_MIN (-INT8_C(127)-1)
# define UINT8_MAX UINT8_C(255)
+
# define __INT_LEAST8_MIN INT8_MIN
# define __INT_LEAST8_MAX INT8_MAX
# define __UINT_LEAST8_MAX UINT8_MAX
+
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+# define UINT8_WIDTH 8
+# define INT8_WIDTH UINT8_WIDTH
+# define __UINT_LEAST8_WIDTH UINT8_WIDTH
+#endif /* __STDC_VERSION__ */
#endif /* __INT8_TYPE__ */
#ifdef __INT_LEAST8_MIN
@@ -633,6 +761,15 @@ typedef __UINTMAX_TYPE__ uintmax_t;
# define INT_FAST8_MIN __INT_LEAST8_MIN
# define INT_FAST8_MAX __INT_LEAST8_MAX
# define UINT_FAST8_MAX __UINT_LEAST8_MAX
+
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+# define UINT_LEAST8_WIDTH __UINT_LEAST8_WIDTH
+# define INT_LEAST8_WIDTH UINT_LEAST8_WIDTH
+# define UINT_FAST8_WIDTH __UINT_LEAST8_WIDTH
+# define INT_FAST8_WIDTH UINT_FAST8_WIDTH
+#endif /* __STDC_VERSION__ */
#endif /* __INT_LEAST8_MIN */
/* Some utility macros */
@@ -652,6 +789,16 @@ typedef __UINTMAX_TYPE__ uintmax_t;
#define PTRDIFF_MAX __PTRDIFF_MAX__
#define SIZE_MAX __SIZE_MAX__
+/* C2x 7.20.2.4 Width of integer types capable of holding object pointers. */
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+/* NB: The C standard requires that these be the same value, but the compiler
+ exposes separate internal width macros. */
+#define INTPTR_WIDTH __INTPTR_WIDTH__
+#define UINTPTR_WIDTH __UINTPTR_WIDTH__
+#endif
+
/* ISO9899:2011 7.20 (C11 Annex K): Define RSIZE_MAX if __STDC_WANT_LIB_EXT1__
* is enabled. */
#if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1
@@ -663,6 +810,16 @@ typedef __UINTMAX_TYPE__ uintmax_t;
#define INTMAX_MAX __INTMAX_MAX__
#define UINTMAX_MAX __UINTMAX_MAX__
+/* C2x 7.20.2.5 Width of greatest-width integer types. */
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+/* NB: The C standard requires that these be the same value, but the compiler
+ exposes separate internal width macros. */
+#define INTMAX_WIDTH __INTMAX_WIDTH__
+#define UINTMAX_WIDTH __UINTMAX_WIDTH__
+#endif
+
/* 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__)
@@ -689,5 +846,16 @@ typedef __UINTMAX_TYPE__ uintmax_t;
#define INTMAX_C(v) __int_c(v, __INTMAX_C_SUFFIX__)
#define UINTMAX_C(v) __int_c(v, __UINTMAX_C_SUFFIX__)
+/* C2x 7.20.3.x Width of other integer types. */
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+#define PTRDIFF_WIDTH __PTRDIFF_WIDTH__
+#define SIG_ATOMIC_WIDTH __SIG_ATOMIC_WIDTH__
+#define SIZE_WIDTH __SIZE_WIDTH__
+#define WCHAR_WIDTH __WCHAR_WIDTH__
+#define WINT_WIDTH __WINT_WIDTH__
+#endif
+
#endif /* __STDC_HOSTED__ */
#endif /* __CLANG_STDINT_H */
diff --git a/clang/test/Headers/limits.cpp b/clang/test/Headers/limits.cpp
index a78f7fc6de6e3..36a9523151574 100644
--- a/clang/test/Headers/limits.cpp
+++ b/clang/test/Headers/limits.cpp
@@ -1,6 +1,8 @@
// RUN: %clang_cc1 -ffreestanding -fsyntax-only -verify %s
// RUN: %clang_cc1 -fno-signed-char -ffreestanding -fsyntax-only -verify %s
// RUN: %clang_cc1 -std=c++11 -ffreestanding -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c17 -ffreestanding -fsyntax-only -verify -x c %s
+// RUN: %clang_cc1 -std=c2x -ffreestanding -fsyntax-only -verify -x c %s
// expected-no-diagnostics
#include <limits.h>
@@ -29,9 +31,8 @@ _Static_assert(MB_LEN_MAX >= 1, "");
_Static_assert(CHAR_BIT >= 8, "");
-const bool char_is_signed = (char)-1 < (char)0;
-_Static_assert(CHAR_MIN == (char_is_signed ? -CHAR_MAX-1 : 0), "");
-_Static_assert(CHAR_MAX == (char_is_signed ? -(CHAR_MIN+1) : (char)~0ULL), "");
+_Static_assert(CHAR_MIN == (((char)-1 < (char)0) ? -CHAR_MAX-1 : 0), "");
+_Static_assert(CHAR_MAX == (((char)-1 < (char)0) ? -(CHAR_MIN+1) : (char)~0ULL), "");
#if __STDC_VERSION__ >= 199901 || __cplusplus >= 201103L
_Static_assert(LLONG_MAX == -(LLONG_MIN+1LL), "");
@@ -40,3 +41,41 @@ _Static_assert(ULLONG_MAX == (unsigned long long)~0ULL, "");
#else
int LLONG_MIN, LLONG_MAX, ULLONG_MAX; // Not defined.
#endif
+
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+/* Validate the standard requirements. */
+_Static_assert(BOOL_WIDTH >= 1);
+
+_Static_assert(CHAR_WIDTH == CHAR_BIT);
+_Static_assert(CHAR_WIDTH / CHAR_BIT == sizeof(char));
+_Static_assert(SCHAR_WIDTH == CHAR_BIT);
+_Static_assert(SCHAR_WIDTH / CHAR_BIT == sizeof(signed char));
+_Static_assert(UCHAR_WIDTH == CHAR_BIT);
+_Static_assert(UCHAR_WIDTH / CHAR_BIT == sizeof(unsigned char));
+
+_Static_assert(USHRT_WIDTH >= 16);
+_Static_assert(USHRT_WIDTH / CHAR_BIT == sizeof(unsigned short));
+_Static_assert(SHRT_WIDTH == USHRT_WIDTH);
+_Static_assert(SHRT_WIDTH / CHAR_BIT == sizeof(signed short));
+
+_Static_assert(UINT_WIDTH >= 16);
+_Static_assert(UINT_WIDTH / CHAR_BIT == sizeof(unsigned int));
+_Static_assert(INT_WIDTH == UINT_WIDTH);
+_Static_assert(INT_WIDTH / CHAR_BIT == sizeof(signed int));
+
+_Static_assert(ULONG_WIDTH >= 32);
+_Static_assert(ULONG_WIDTH / CHAR_BIT == sizeof(unsigned long));
+_Static_assert(LONG_WIDTH == ULONG_WIDTH);
+_Static_assert(LONG_WIDTH / CHAR_BIT == sizeof(signed long));
+
+_Static_assert(ULLONG_WIDTH >= 64);
+_Static_assert(ULLONG_WIDTH / CHAR_BIT == sizeof(unsigned long long));
+_Static_assert(LLONG_WIDTH == ULLONG_WIDTH);
+_Static_assert(LLONG_WIDTH / CHAR_BIT == sizeof(signed long long));
+#else
+/* None of these are defined. */
+int BOOL_WIDTH, CHAR_WIDTH, SCHAR_WIDTH, UCHAR_WIDTH, USHRT_WIDTH, SHRT_WIDTH,
+ UINT_WIDTH, INT_WIDTH, ULONG_WIDTH, LONG_WIDTH, ULLONG_WIDTH, LLONG_WIDTH;
+#endif
diff --git a/clang/test/Headers/stdint.c b/clang/test/Headers/stdint.c
new file mode 100644
index 0000000000000..9c52b4d164dd1
--- /dev/null
+++ b/clang/test/Headers/stdint.c
@@ -0,0 +1,253 @@
+// RUN: %clang_cc1 -ffreestanding -fsyntax-only -verify -std=c17 %s
+// RUN: %clang_cc1 -ffreestanding -fsyntax-only -verify -std=c2x %s
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=aarch64-none-none
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=arm-none-none
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=i386-none-none
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=mips-none-none
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=mips64-none-none
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=msp430-none-none
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=powerpc64-none-none
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=powerpc64-none-netbsd
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=powerpc-none-none
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=s390x-none-none
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=sparc-none-none
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=tce-none-none
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=x86_64-none-none
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=x86_64-pc-linux-gnu
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=i386-mingw32
+// RUN: %clang_cc1 %s -ffreestanding -std=c2x -fsyntax-only -triple=xcore-none-none
+// expected-no-diagnostics
+
+#include <stdint.h>
+
+/* FIXME: This is using the placeholder dates Clang produces for these macros
+ in C2x mode; switch to the correct values once they've been published. */
+#if __STDC_VERSION__ >= 202000L
+/* Validate the standard requirements. */
+_Static_assert(SIG_ATOMIC_WIDTH >= 8);
+_Static_assert(SIZE_WIDTH >= 16);
+_Static_assert(SIZE_WIDTH / __CHAR_BIT__ == sizeof(sizeof(0)));
+_Static_assert(WCHAR_WIDTH >= 8);
+_Static_assert(WCHAR_WIDTH / __CHAR_BIT__ == sizeof(L't'));
+_Static_assert(WINT_WIDTH >= 16);
+_Static_assert(UINTPTR_WIDTH >= 16);
+_Static_assert(UINTPTR_WIDTH / __CHAR_BIT__ == sizeof(uintptr_t));
+_Static_assert(INTPTR_WIDTH == UINTPTR_WIDTH);
+_Static_assert(INTPTR_WIDTH / __CHAR_BIT__ == sizeof(intptr_t));
+
+/* FIXME: the TCE target is not a conforming C target because it defines these
+ values to be less than 64. */
+#if !defined(__TCE__)
+_Static_assert(UINTMAX_WIDTH >= 64);
+_Static_assert(UINTMAX_WIDTH / __CHAR_BIT__ == sizeof(uintmax_t));
+_Static_assert(INTMAX_WIDTH == UINTMAX_WIDTH);
+_Static_assert(INTMAX_WIDTH / __CHAR_BIT__ == sizeof(intmax_t));
+#endif
+
+/* NB: WG14 N2412 set this to 17, but WG14 N2808 set it back to 16. */
+_Static_assert(PTRDIFF_WIDTH >= 16);
+#else
+/* None of these are defined. */
+int PTRDIFF_WIDTH, SIG_ATOMIC_WIDTH, SIZE_WIDTH, WCHAR_WIDTH, WINT_WIDTH,
+ INTPTR_WIDTH, UINTPTR_WIDTH, INTMAX_WIDTH, UINTMAX_WIDTH;
+#endif
+
+#if defined(INT8_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT8_WIDTH == 8, "");
+_Static_assert(UINT8_WIDTH == INT8_WIDTH, "");
+_Static_assert(INT8_WIDTH / __CHAR_BIT__ == sizeof(int8_t), "");
+_Static_assert(UINT8_WIDTH / __CHAR_BIT__ == sizeof(uint8_t), "");
+#else
+int INT8_WIDTH, UINT8_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_LEAST8_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_LEAST8_WIDTH >= 8, "");
+_Static_assert(INT_LEAST8_WIDTH / __CHAR_BIT__ == sizeof(int_least8_t), "");
+_Static_assert(UINT_LEAST8_WIDTH == INT_LEAST8_WIDTH, "");
+_Static_assert(UINT_LEAST8_WIDTH / __CHAR_BIT__ == sizeof(uint_least8_t), "");
+#else
+int INT_LEAST8_WIDTH, UINT_LEAST8_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_FAST8_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_FAST8_WIDTH >= 8, "");
+_Static_assert(INT_FAST8_WIDTH / __CHAR_BIT__ == sizeof(int_fast8_t), "");
+_Static_assert(UINT_FAST8_WIDTH == INT_FAST8_WIDTH, "");
+_Static_assert(UINT_FAST8_WIDTH / __CHAR_BIT__ == sizeof(uint_fast8_t), "");
+#else
+int INT_FAST8_WIDTH, UINT_FAST8_WIDTH; /* None of these are defined. */
+#endif
+
+#if defined(INT16_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT16_WIDTH == 16, "");
+_Static_assert(UINT16_WIDTH == INT16_WIDTH, "");
+_Static_assert(INT16_WIDTH / __CHAR_BIT__ == sizeof(int16_t), "");
+_Static_assert(UINT16_WIDTH / __CHAR_BIT__ == sizeof(uint16_t), "");
+#else
+int INT16_WIDTH, UINT16_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_LEAST16_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_LEAST16_WIDTH >= 16, "");
+_Static_assert(INT_LEAST16_WIDTH / __CHAR_BIT__ == sizeof(int_least16_t), "");
+_Static_assert(UINT_LEAST16_WIDTH == INT_LEAST16_WIDTH, "");
+_Static_assert(UINT_LEAST16_WIDTH / __CHAR_BIT__ == sizeof(uint_least16_t), "");
+#else
+int INT_LEAST16_WIDTH, UINT_LEAST16_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_FAST16_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_FAST16_WIDTH >= 16, "");
+_Static_assert(INT_FAST16_WIDTH / __CHAR_BIT__ == sizeof(int_fast16_t), "");
+_Static_assert(UINT_FAST16_WIDTH == INT_FAST16_WIDTH, "");
+_Static_assert(UINT_FAST16_WIDTH / __CHAR_BIT__ == sizeof(int_fast16_t), "");
+#else
+int INT_FAST16_WIDTH, UINT_FAST16_WIDTH; /* None of these are defined. */
+#endif
+
+#if defined(INT24_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT24_WIDTH == 24, "");
+_Static_assert(UINT24_WIDTH == INT24_WIDTH, "");
+_Static_assert(INT24_WIDTH / __CHAR_BIT__ == sizeof(int24_t), "");
+_Static_assert(UINT24_WIDTH / __CHAR_BIT__ == sizeof(uint24_t), "");
+#else
+int INT24_WIDTH, UINT24_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_LEAST24_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_LEAST24_WIDTH >= 24, "");
+_Static_assert(INT_LEAST24_WIDTH / __CHAR_BIT__ == sizeof(int_least24_t), "");
+_Static_assert(UINT_LEAST24_WIDTH == INT_LEAST24_WIDTH, "");
+_Static_assert(UINT_LEAST24_WIDTH / __CHAR_BIT__ == sizeof(uint_least24_t), "");
+#else
+int INT_LEAST24_WIDTH, UINT_LEAST24_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_FAST24_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_FAST24_WIDTH >= 24, "");
+_Static_assert(INT_FAST24_WIDTH / __CHAR_BIT__ == sizeof(int_fast24_t), "");
+_Static_assert(UINT_FAST24_WIDTH == INT_FAST24_WIDTH, "");
+_Static_assert(UINT_FAST24_WIDTH / __CHAR_BIT__ == sizeof(uint_fast24_t), "");
+#else
+int INT_FAST24_WIDTH, UINT_FAST24_WIDTH; /* None of these are defined. */
+#endif
+
+#if defined(INT32_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT32_WIDTH == 32, "");
+_Static_assert(UINT32_WIDTH == INT32_WIDTH, "");
+_Static_assert(INT32_WIDTH / __CHAR_BIT__ == sizeof(int32_t), "");
+_Static_assert(UINT32_WIDTH / __CHAR_BIT__ == sizeof(uint32_t), "");
+#else
+int INT32_WIDTH, UINT32_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_LEAST32_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_LEAST32_WIDTH >= 32, "");
+_Static_assert(INT_LEAST32_WIDTH / __CHAR_BIT__ == sizeof(int_least32_t), "");
+_Static_assert(UINT_LEAST32_WIDTH == INT_LEAST32_WIDTH, "");
+_Static_assert(UINT_LEAST32_WIDTH / __CHAR_BIT__ == sizeof(uint_least32_t), "");
+#else
+int INT_LEAST32_WIDTH, UINT_LEAST32_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_FAST32_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_FAST32_WIDTH >= 32, "");
+_Static_assert(INT_FAST32_WIDTH / __CHAR_BIT__ == sizeof(int_fast32_t), "");
+_Static_assert(UINT_FAST32_WIDTH == INT_FAST32_WIDTH, "");
+_Static_assert(UINT_FAST32_WIDTH / __CHAR_BIT__ == sizeof(uint_fast32_t), "");
+#else
+int INT_FAST32_WIDTH, UINT_FAST32_WIDTH; /* None of these are defined. */
+#endif
+
+#if defined(INT40_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT40_WIDTH == 40, "");
+_Static_assert(UINT40_WIDTH == INT40_WIDTH, "");
+_Static_assert(INT40_WIDTH / __CHAR_BIT__ == sizeof(int40_t), "");
+_Static_assert(UINT40_WIDTH / __CHAR_BIT__ == sizeof(uint40_t), "");
+#else
+int INT40_WIDTH, UINT40_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_LEAST40_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_LEAST40_WIDTH >= 40, "");
+_Static_assert(INT_LEAST40_WIDTH / __CHAR_BIT__ == sizeof(int_least40_t), "");
+_Static_assert(UINT_LEAST40_WIDTH == INT_LEAST40_WIDTH, "");
+_Static_assert(UINT_LEAST40_WIDTH / __CHAR_BIT__ == sizeof(int_least40_t), "");
+#else
+int INT_LEAST40_WIDTH, UINT_LEAST40_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_FAST40_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_FAST40_WIDTH >= 40, "");
+_Static_assert(INT_FAST40_WIDTH / __CHAR_BIT__ == sizeof(int_fast40_t), "");
+_Static_assert(UINT_FAST40_WIDTH == INT_FAST40_WIDTH, "");
+_Static_assert(UINT_FAST40_WIDTH / __CHAR_BIT__ == sizeof(uint_fast40_t), "");
+#else
+int INT_FAST40_WIDTH, UINT_FAST40_WIDTH; /* None of these are defined. */
+#endif
+
+#if defined(INT48_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT48_WIDTH == 48, "");
+_Static_assert(UINT48_WIDTH == INT48_WIDTH, "");
+_Static_assert(INT48_WIDTH / __CHAR_BIT__ == sizeof(int48_t), "");
+_Static_assert(UINT48_WIDTH / __CHAR_BIT__ == sizeof(uint48_t), "");
+#else
+int INT48_WIDTH, UINT48_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_LEAST48_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_LEAST48_WIDTH >= 48, "");
+_Static_assert(INT_LEAST48_WIDTH / __CHAR_BIT__ == sizeof(int_least48_t), "");
+_Static_assert(UINT_LEAST48_WIDTH == INT_LEAST48_WIDTH, "");
+_Static_assert(UINT_LEAST48_WIDTH / __CHAR_BIT__ == sizeof(int_least48_t), "");
+#else
+int INT_LEAST48_WIDTH, UINT_LEAST48_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_FAST48_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_FAST48_WIDTH >= 48, "");
+_Static_assert(INT_FAST48_WIDTH / __CHAR_BIT__ == sizeof(int_fast48_t), "");
+_Static_assert(UINT_FAST48_WIDTH == INT_FAST48_WIDTH, "");
+_Static_assert(UINT_FAST48_WIDTH / __CHAR_BIT__ == sizeof(int_fast48_t), "");
+#else
+int INT_FAST48_WIDTH, UINT_FAST48_WIDTH; /* None of these are defined. */
+#endif
+
+#if defined(INT56_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT56_WIDTH == 56, "");
+_Static_assert(UINT56_WIDTH == INT56_WIDTH, "");
+_Static_assert(INT56_WIDTH / __CHAR_BIT__ == sizeof(int56_t), "");
+_Static_assert(UINT56_WIDTH / __CHAR_BIT__ == sizeof(uint56_t), "");
+#else
+int INT56_WIDTH, UINT56_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_LEAST56_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_LEAST56_WIDTH >= 56, "");
+_Static_assert(INT_LEAST56_WIDTH / __CHAR_BIT__ == sizeof(int_least56_t), "");
+_Static_assert(UINT_LEAST56_WIDTH == INT_LEAST56_WIDTH, "");
+_Static_assert(UINT_LEAST56_WIDTH / __CHAR_BIT__ == sizeof(int_least56_t), "");
+#else
+int INT_LEAST56_WIDTH, UINT_LEAST56_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_FAST56_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_FAST56_WIDTH >= 56, "");
+_Static_assert(INT_FAST56_WIDTH / __CHAR_BIT__ == sizeof(int_fast56_t), "");
+_Static_assert(UINT_FAST56_WIDTH == INT_FAST56_WIDTH, "");
+_Static_assert(UINT_FAST56_WIDTH / __CHAR_BIT__ == sizeof(int_fast56_t), "");
+#else
+int INT_FAST56_WIDTH, UINT_FAST56_WIDTH; /* None of these are defined. */
+#endif
+
+#if defined(INT64_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT64_WIDTH == 64, "");
+_Static_assert(UINT64_WIDTH == INT64_WIDTH, "");
+_Static_assert(INT64_WIDTH / __CHAR_BIT__ == sizeof(int64_t), "");
+_Static_assert(UINT64_WIDTH / __CHAR_BIT__ == sizeof(uint64_t), "");
+#else
+int INT64_WIDTH, UINT64_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_LEAST64_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_LEAST64_WIDTH >= 64, "");
+_Static_assert(INT_LEAST64_WIDTH / __CHAR_BIT__ == sizeof(int_least64_t), "");
+_Static_assert(UINT_LEAST64_WIDTH == INT_LEAST64_WIDTH, "");
+_Static_assert(UINT_LEAST64_WIDTH / __CHAR_BIT__ == sizeof(int_least64_t), "");
+#else
+int INT_LEAST64_WIDTH, UINT_LEAST64_WIDTH; /* None of these are defined. */
+#endif
+#if defined(INT_FAST64_MAX) && __STDC_VERSION__ >= 202000L
+_Static_assert(INT_FAST64_WIDTH >= 64, "");
+_Static_assert(INT_FAST64_WIDTH / __CHAR_BIT__ == sizeof(int_fast64_t), "");
+_Static_assert(UINT_FAST64_WIDTH == INT_FAST64_WIDTH, "");
+_Static_assert(UINT_FAST64_WIDTH / __CHAR_BIT__ == sizeof(int_fast64_t), "");
+#else
+int INT_FAST64_WIDTH, UINT_FAST64_WIDTH; /* None of these are defined. */
+#endif
diff --git a/clang/test/Preprocessor/init-aarch64.c b/clang/test/Preprocessor/init-aarch64.c
index 8787d24f01cee..598b3c75507ca 100644
--- a/clang/test/Preprocessor/init-aarch64.c
+++ b/clang/test/Preprocessor/init-aarch64.c
@@ -40,6 +40,7 @@
// AARCH64-NEXT: #define __ATOMIC_SEQ_CST 5
// AARCH64: #define __BIGGEST_ALIGNMENT__ 16
// AARCH64_BE-NEXT: #define __BIG_ENDIAN__ 1
+// AARCH64-NEXT: #define __BOOL_WIDTH__ 8
// AARCH64_BE-NEXT: #define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
// AARCH64_LE-NEXT: #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
// AARCH64-NEXT: #define __CHAR16_TYPE__ unsigned short
@@ -144,35 +145,44 @@
// AARCH64-NEXT: #define __INT_FAST16_FMTi__ "hi"
// AARCH64-NEXT: #define __INT_FAST16_MAX__ 32767
// AARCH64-NEXT: #define __INT_FAST16_TYPE__ short
+// AARCH64-NEXT: #define __INT_FAST16_WIDTH__ 16
// AARCH64-NEXT: #define __INT_FAST32_FMTd__ "d"
// AARCH64-NEXT: #define __INT_FAST32_FMTi__ "i"
// AARCH64-NEXT: #define __INT_FAST32_MAX__ 2147483647
// AARCH64-NEXT: #define __INT_FAST32_TYPE__ int
+// AARCH64-NEXT: #define __INT_FAST32_WIDTH__ 32
// AARCH64-NEXT: #define __INT_FAST64_FMTd__ "ld"
// AARCH64-NEXT: #define __INT_FAST64_FMTi__ "li"
// AARCH64-NEXT: #define __INT_FAST64_MAX__ 9223372036854775807L
// AARCH64-NEXT: #define __INT_FAST64_TYPE__ long int
+// AARCH64-NEXT: #define __INT_FAST64_WIDTH__ 64
// AARCH64-NEXT: #define __INT_FAST8_FMTd__ "hhd"
// AARCH64-NEXT: #define __INT_FAST8_FMTi__ "hhi"
// AARCH64-NEXT: #define __INT_FAST8_MAX__ 127
// AARCH64-NEXT: #define __INT_FAST8_TYPE__ signed char
+// AARCH64-NEXT: #define __INT_FAST8_WIDTH__ 8
// AARCH64-NEXT: #define __INT_LEAST16_FMTd__ "hd"
// AARCH64-NEXT: #define __INT_LEAST16_FMTi__ "hi"
// AARCH64-NEXT: #define __INT_LEAST16_MAX__ 32767
// AARCH64-NEXT: #define __INT_LEAST16_TYPE__ short
+// AARCH64-NEXT: #define __INT_LEAST16_WIDTH__ 16
// AARCH64-NEXT: #define __INT_LEAST32_FMTd__ "d"
// AARCH64-NEXT: #define __INT_LEAST32_FMTi__ "i"
// AARCH64-NEXT: #define __INT_LEAST32_MAX__ 2147483647
// AARCH64-NEXT: #define __INT_LEAST32_TYPE__ int
+// AARCH64-NEXT: #define __INT_LEAST32_WIDTH__ 32
// AARCH64-NEXT: #define __INT_LEAST64_FMTd__ "ld"
// AARCH64-NEXT: #define __INT_LEAST64_FMTi__ "li"
// AARCH64-NEXT: #define __INT_LEAST64_MAX__ 9223372036854775807L
// AARCH64-NEXT: #define __INT_LEAST64_TYPE__ long int
+// AARCH64-NEXT: #define __INT_LEAST64_WIDTH__ 64
// AARCH64-NEXT: #define __INT_LEAST8_FMTd__ "hhd"
// AARCH64-NEXT: #define __INT_LEAST8_FMTi__ "hhi"
// AARCH64-NEXT: #define __INT_LEAST8_MAX__ 127
// AARCH64-NEXT: #define __INT_LEAST8_TYPE__ signed char
+// AARCH64-NEXT: #define __INT_LEAST8_WIDTH__ 8
// AARCH64-NEXT: #define __INT_MAX__ 2147483647
+// AARCH64-NEXT: #define __INT_WIDTH__ 32
// AARCH64-NEXT: #define __LDBL_DECIMAL_DIG__ 36
// AARCH64-NEXT: #define __LDBL_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966L
// AARCH64-NEXT: #define __LDBL_DIG__ 33
@@ -188,8 +198,10 @@
// AARCH64-NEXT: #define __LDBL_MIN_EXP__ (-16381)
// AARCH64-NEXT: #define __LDBL_MIN__ 3.36210314311209350626267781732175260e-4932L
// AARCH64_LE-NEXT: #define __LITTLE_ENDIAN__ 1
+// AARCH64-NEXT: #define __LLONG_WIDTH__ 64
// AARCH64-NEXT: #define __LONG_LONG_MAX__ 9223372036854775807LL
// AARCH64-NEXT: #define __LONG_MAX__ 9223372036854775807L
+// AARCH64-NEXT: #define __LONG_WIDTH__ 64
// AARCH64-NEXT: #define __LP64__ 1
// AARCH64-NEXT: #define __NO_INLINE__ 1
// AARCH64-NEXT: #define __NO_MATH_ERRNO__ 1
@@ -211,6 +223,7 @@
// AARCH64-NEXT: #define __PTRDIFF_WIDTH__ 64
// AARCH64-NEXT: #define __SCHAR_MAX__ 127
// AARCH64-NEXT: #define __SHRT_MAX__ 32767
+// AARCH64-NEXT: #define __SHRT_WIDTH__ 16
// AARCH64-NEXT: #define __SIG_ATOMIC_MAX__ 2147483647
// AARCH64-NEXT: #define __SIG_ATOMIC_WIDTH__ 32
// AARCH64-NEXT: #define __SIZEOF_DOUBLE__ 8
diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 45d494112a4f5..f11f600beed15 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1520,6 +1520,7 @@
// WEBASSEMBLY-NEXT:#define __ATOMIC_RELEASE 3
// WEBASSEMBLY-NEXT:#define __ATOMIC_SEQ_CST 5
// WEBASSEMBLY-NEXT:#define __BIGGEST_ALIGNMENT__ 16
+// WEBASSEMBLY-NEXT:#define __BOOL_WIDTH__ 8
// WEBASSEMBLY-NEXT:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
// WEBASSEMBLY-NEXT:#define __CHAR16_TYPE__ unsigned short
// WEBASSEMBLY-NEXT:#define __CHAR32_TYPE__ unsigned int
@@ -1641,35 +1642,44 @@
// WEBASSEMBLY-NEXT:#define __INT_FAST16_FMTi__ "hi"
// WEBASSEMBLY-NEXT:#define __INT_FAST16_MAX__ 32767
// WEBASSEMBLY-NEXT:#define __INT_FAST16_TYPE__ short
+// WEBASSEMBLY-NEXT:#define __INT_FAST16_WIDTH__ 16
// WEBASSEMBLY-NEXT:#define __INT_FAST32_FMTd__ "d"
// WEBASSEMBLY-NEXT:#define __INT_FAST32_FMTi__ "i"
// WEBASSEMBLY-NEXT:#define __INT_FAST32_MAX__ 2147483647
// WEBASSEMBLY-NEXT:#define __INT_FAST32_TYPE__ int
+// WEBASSEMBLY-NEXT:#define __INT_FAST32_WIDTH__ 32
// WEBASSEMBLY-NEXT:#define __INT_FAST64_FMTd__ "lld"
// WEBASSEMBLY-NEXT:#define __INT_FAST64_FMTi__ "lli"
// WEBASSEMBLY-NEXT:#define __INT_FAST64_MAX__ 9223372036854775807LL
// WEBASSEMBLY-NEXT:#define __INT_FAST64_TYPE__ long long int
+// WEBASSEMBLY-NEXT:#define __INT_FAST64_WIDTH__ 64
// WEBASSEMBLY-NEXT:#define __INT_FAST8_FMTd__ "hhd"
// WEBASSEMBLY-NEXT:#define __INT_FAST8_FMTi__ "hhi"
// WEBASSEMBLY-NEXT:#define __INT_FAST8_MAX__ 127
// WEBASSEMBLY-NEXT:#define __INT_FAST8_TYPE__ signed char
+// WEBASSEMBLY-NEXT:#define __INT_FAST8_WIDTH__ 8
// WEBASSEMBLY-NEXT:#define __INT_LEAST16_FMTd__ "hd"
// WEBASSEMBLY-NEXT:#define __INT_LEAST16_FMTi__ "hi"
// WEBASSEMBLY-NEXT:#define __INT_LEAST16_MAX__ 32767
// WEBASSEMBLY-NEXT:#define __INT_LEAST16_TYPE__ short
+// WEBASSEMBLY-NEXT:#define __INT_LEAST16_WIDTH__ 16
// WEBASSEMBLY-NEXT:#define __INT_LEAST32_FMTd__ "d"
// WEBASSEMBLY-NEXT:#define __INT_LEAST32_FMTi__ "i"
// WEBASSEMBLY-NEXT:#define __INT_LEAST32_MAX__ 2147483647
// WEBASSEMBLY-NEXT:#define __INT_LEAST32_TYPE__ int
+// WEBASSEMBLY-NEXT:#define __INT_LEAST32_WIDTH__ 32
// WEBASSEMBLY-NEXT:#define __INT_LEAST64_FMTd__ "lld"
// WEBASSEMBLY-NEXT:#define __INT_LEAST64_FMTi__ "lli"
// WEBASSEMBLY-NEXT:#define __INT_LEAST64_MAX__ 9223372036854775807LL
// WEBASSEMBLY-NEXT:#define __INT_LEAST64_TYPE__ long long int
+// WEBASSEMBLY-NEXT:#define __INT_LEAST64_WIDTH__ 64
// WEBASSEMBLY-NEXT:#define __INT_LEAST8_FMTd__ "hhd"
// WEBASSEMBLY-NEXT:#define __INT_LEAST8_FMTi__ "hhi"
// WEBASSEMBLY-NEXT:#define __INT_LEAST8_MAX__ 127
// WEBASSEMBLY-NEXT:#define __INT_LEAST8_TYPE__ signed char
+// WEBASSEMBLY-NEXT:#define __INT_LEAST8_WIDTH__ 8
// WEBASSEMBLY-NEXT:#define __INT_MAX__ 2147483647
+// WEBASSEMBLY-NEXT:#define __INT_WIDTH__ 32
// WEBASSEMBLY-NEXT:#define __LDBL_DECIMAL_DIG__ 36
// WEBASSEMBLY-NEXT:#define __LDBL_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966L
// WEBASSEMBLY-NEXT:#define __LDBL_DIG__ 33
@@ -1685,10 +1695,13 @@
// WEBASSEMBLY-NEXT:#define __LDBL_MIN_EXP__ (-16381)
// WEBASSEMBLY-NEXT:#define __LDBL_MIN__ 3.36210314311209350626267781732175260e-4932L
// WEBASSEMBLY-NEXT:#define __LITTLE_ENDIAN__ 1
+// WEBASSEMBLY-NEXT:#define __LLONG_WIDTH__ 64
// WEBASSEMBLY-NEXT:#define __LONG_LONG_MAX__ 9223372036854775807LL
// WEBASSEMBLY32-NEXT:#define __LONG_MAX__ 2147483647L
// WEBASSEMBLY32-NOT:#define __LP64__
+// WEBASSEMBLY32-NEXT:#define __LONG_WIDTH__ 32
// WEBASSEMBLY64-NEXT:#define __LONG_MAX__ 9223372036854775807L
+// WEBASSEMBLY64-NEXT:#define __LONG_WIDTH__ 64
// WEBASSEMBLY64-NEXT:#define __LP64__ 1
// WEBASSEMBLY-NEXT:#define __NO_INLINE__ 1
// WEBASSEMBLY-NEXT:#define __NO_MATH_ERRNO__ 1
@@ -1714,6 +1727,7 @@
// WEBASSEMBLY-NOT:#define __REGISTER_PREFIX__
// WEBASSEMBLY-NEXT:#define __SCHAR_MAX__ 127
// WEBASSEMBLY-NEXT:#define __SHRT_MAX__ 32767
+// WEBASSEMBLY-NEXT:#define __SHRT_WIDTH__ 16
// WEBASSEMBLY32-NEXT:#define __SIG_ATOMIC_MAX__ 2147483647L
// WEBASSEMBLY32-NEXT:#define __SIG_ATOMIC_WIDTH__ 32
// WEBASSEMBLY64-NEXT:#define __SIG_ATOMIC_MAX__ 9223372036854775807L
diff --git a/clang/www/c_status.html b/clang/www/c_status.html
index 42bc57d969ad8..f81ac19cce702 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -715,11 +715,7 @@ <h2 id="c2x">C2x implementation status</h2>
<tr>
<td>Two's complement sign representation</td>
<td><a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2412.pdf">N2412</a></td>
- <td class="partial" align="center">
- <details><summary>Partial</summary>
- Lacking width macros in limits.h and stdint.h
- </details>
- </td>
+ <td class="unreleased" align="center">Clang 14</td>
</tr>
<tr>
<td>Adding the u8 character prefix</td>
More information about the cfe-commits
mailing list