diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -42,9 +42,6 @@ MacroBuilder &Builder) const override { Builder.defineMacro("__CloudABI__"); Builder.defineMacro("__ELF__"); - - // CloudABI uses ISO/IEC 10646:2012 for wchar_t, char16_t and char32_t. - Builder.defineMacro("__STDC_ISO_10646__", "201206L"); Builder.defineMacro("__STDC_UTF_16__"); Builder.defineMacro("__STDC_UTF_32__"); } diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -427,6 +427,16 @@ Builder.defineMacro("__STDC_UTF_16__", "1"); Builder.defineMacro("__STDC_UTF_32__", "1"); + // Because Clang only supports UTF-32 or UTF-16 as the + // wide execution encoding, any platform that doesn't use + // short wchar_t can represent the entire Unicode code space. + // Unicode 13 was released in December 2020, which is why we're + // expanding to 202012L. Note that new Unicode versions are + // *very* unlikely to cause Clang to need to remove the + // predefined macro. + if (TI.getWCharWidth() >= 32) + Builder.defineMacro("__STDC_ISO_10646__", "202012L"); + if (LangOpts.ObjC) Builder.defineMacro("__OBJC__"); diff --git a/clang/test/Preprocessor/init-aarch64.c b/clang/test/Preprocessor/init-aarch64.c --- a/clang/test/Preprocessor/init-aarch64.c +++ b/clang/test/Preprocessor/init-aarch64.c @@ -235,6 +235,7 @@ // AARCH64_CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL // AARCH64_CXX: #define __STDCPP_THREADS__ 1 // AARCH64-NEXT: #define __STDC_HOSTED__ 1 +// AARCH64: #define __STDC_ISO_10646__ 202012L // AARCH64-NEXT: #define __STDC_UTF_16__ 1 // AARCH64-NEXT: #define __STDC_UTF_32__ 1 // AARCH64_C: #define __STDC_VERSION__ 201710L @@ -648,6 +649,7 @@ // AARCH64-MSVC: #define __SIZE_TYPE__ long long unsigned int // AARCH64-MSVC: #define __SIZE_WIDTH__ 64 // AARCH64-MSVC: #define __STDC_HOSTED__ 0 +// AARCH64-MSVC-NOT: #define __STDC_ISO_10646__ // AARCH64-MSVC: #define __STDC_UTF_16__ 1 // AARCH64-MSVC: #define __STDC_UTF_32__ 1 // AARCH64-MSVC: #define __STDC_VERSION__ 201710L diff --git a/clang/test/Preprocessor/init-x86.c b/clang/test/Preprocessor/init-x86.c --- a/clang/test/Preprocessor/init-x86.c +++ b/clang/test/Preprocessor/init-x86.c @@ -1199,7 +1199,7 @@ // X86_64-CLOUDABI:#define __SSE_MATH__ 1 // X86_64-CLOUDABI:#define __SSE__ 1 // X86_64-CLOUDABI:#define __STDC_HOSTED__ 0 -// X86_64-CLOUDABI:#define __STDC_ISO_10646__ 201206L +// X86_64-CLOUDABI:#define __STDC_ISO_10646__ 202012L // X86_64-CLOUDABI:#define __STDC_UTF_16__ 1 // X86_64-CLOUDABI:#define __STDC_UTF_32__ 1 // X86_64-CLOUDABI:#define __STDC_VERSION__ 201710L diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -89,6 +89,7 @@ // RUN: %clang_cc1 -std=iso9899:2011 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix C11 %s // RUN: %clang_cc1 -std=iso9899:201x -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix C11 %s // +// C11:#define __STDC_ISO_10646__ 202012L // C11:#define __STDC_UTF_16__ 1 // C11:#define __STDC_UTF_32__ 1 // C11:#define __STDC_VERSION__ 201112L @@ -284,6 +285,7 @@ // RUN: %clang_cc1 -dM -fwchar-type=short -fno-signed-wchar -triple=x86_64-unknown-windows-cygnus -E /dev/null | FileCheck -match-full-lines -check-prefix SHORTWCHAR %s // // SHORTWCHAR: #define __SIZEOF_WCHAR_T__ 2 +// SHORTWCHAR-NOT: #define __STDC_ISO_10646__ // SHORTWCHAR: #define __WCHAR_MAX__ 65535 // SHORTWCHAR: #define __WCHAR_TYPE__ unsigned short // SHORTWCHAR: #define __WCHAR_WIDTH__ 16 @@ -292,6 +294,7 @@ // RUN: %clang_cc1 -E -dM -fwchar-type=int -triple=x86_64-unknown-unknown < /dev/null | FileCheck -match-full-lines -check-prefix SHORTWCHAR2 %s // // SHORTWCHAR2: #define __SIZEOF_WCHAR_T__ 4 +// SHORTWCHAR2: #define __STDC_ISO_10646__ 202012L // SHORTWCHAR2: #define __WCHAR_WIDTH__ 32 // Other definitions vary from platform to platform @@ -1739,6 +1742,7 @@ // WEBASSEMBLY-NOT:#define __STDC_NO_COMPLEX__ // WEBASSEMBLY-NOT:#define __STDC_NO_VLA__ // WEBASSEMBLY-NOT:#define __STDC_NO_THREADS__ +// WEBASSEMBLY-NEXT:#define __STDC_ISO_10646__ 202012L // WEBASSEMBLY-NEXT:#define __STDC_UTF_16__ 1 // WEBASSEMBLY-NEXT:#define __STDC_UTF_32__ 1 // WEBASSEMBLY-NEXT:#define __STDC_VERSION__ 201710L @@ -2310,6 +2314,7 @@ // RISCV32: #define __SIZE_TYPE__ unsigned int // RISCV32: #define __SIZE_WIDTH__ 32 // RISCV32: #define __STDC_HOSTED__ 0 +// RISCV32: #define __STDC_ISO_10646__ 202012L // RISCV32: #define __STDC_UTF_16__ 1 // RISCV32: #define __STDC_UTF_32__ 1 // RISCV32: #define __STDC_VERSION__ 201710L @@ -2517,6 +2522,7 @@ // RISCV64: #define __SIZE_TYPE__ long unsigned int // RISCV64: #define __SIZE_WIDTH__ 64 // RISCV64: #define __STDC_HOSTED__ 0 +// RISCV64: #define __STDC_ISO_10646__ 202012L // RISCV64: #define __STDC_UTF_16__ 1 // RISCV64: #define __STDC_UTF_32__ 1 // RISCV64: #define __STDC_VERSION__ 201710L