cor3ntin created this revision. Herald added subscribers: s.egerton, simoncook, dschuff. cor3ntin requested review of this revision. Herald added subscribers: cfe-commits, aheejin. Herald added a project: clang.
Both C and C++ standard suggest that the macro __STDC_ISO_10646__ should be defined when wchar_t can represent all unicode characters. Because pending D93031 <https://reviews.llvm.org/D93031>, clang only support UTF-16 or UTF-32 as the wide execution encoding, wchar_t can represent all Unicode characters whenever wchar_t is at least 21 bits. But clang only seem to support 2 or 4 bytes wchar_t so only define __STDC_ISO_10646__ when wchar_t is at least 4 bytes. The value is rather meaning less as the version of Unicode is unlikely affect its codespace, or we would have bigger problems. We set it to the publication of Unicode 13. Note that this define was set up already in the CloudABI target. This project seems unmaintained, and for the sake of simplicity i elected to change the value used there. (only the presence of the macro is likely to be checked). When D93031 <https://reviews.llvm.org/D93031> is approved this code can be extended to check a user defined wide execution encoding. We could also imagine a per-target (OS) default wide execution encoding. EG for wide ebcdic. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D106577 Files: clang/lib/Basic/Targets/OSTargets.h clang/lib/Frontend/InitPreprocessor.cpp clang/test/Preprocessor/init-aarch64.c clang/test/Preprocessor/init-x86.c clang/test/Preprocessor/init.c
Index: clang/test/Preprocessor/init.c =================================================================== --- clang/test/Preprocessor/init.c +++ 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 Index: clang/test/Preprocessor/init-x86.c =================================================================== --- clang/test/Preprocessor/init-x86.c +++ 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 Index: clang/test/Preprocessor/init-aarch64.c =================================================================== --- clang/test/Preprocessor/init-aarch64.c +++ 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 Index: clang/lib/Frontend/InitPreprocessor.cpp =================================================================== --- clang/lib/Frontend/InitPreprocessor.cpp +++ 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 uses + // short wchar can represent the entire Unicode code space + // Unicode 13 was released in December 2020. + // Note that new Unicode version are *very* unlikely to affect + // representability + if (TI.getWCharWidth() >= 32) { + Builder.defineMacro("__STDC_ISO_10646__", "202012L"); + } + if (LangOpts.ObjC) Builder.defineMacro("__OBJC__"); Index: clang/lib/Basic/Targets/OSTargets.h =================================================================== --- clang/lib/Basic/Targets/OSTargets.h +++ 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__"); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits