Skip to content

Commit 54928a1

Browse files
authored
[clang] __STDC_NO_THREADS__ is no longer necessary for VS 2022 1939 and above (#117149)
Since `__STDC_NO_THREADS__` is a reserved identifier, - If `MSVC version < 17.9` - C version < C11(201112L) - When `<threads.h>` is unavailable `!__has_include(<threads.h>)` is `__has_include` is defined. Closes #115529
1 parent f075058 commit 54928a1

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

clang/docs/ReleaseNotes.rst

+1
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ C Language Changes
387387
------------------
388388

389389
- Extend clang's ``<limits.h>`` to define ``LONG_LONG_*`` macros for Android's bionic.
390+
- Macro ``__STDC_NO_THREADS__`` is no longer necessary for MSVC 2022 1939 and later.
390391

391392
C2y Feature Support
392393
^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/LangOptions.h

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class LangOptionsBase {
144144
MSVC2019_5 = 1925,
145145
MSVC2019_8 = 1928,
146146
MSVC2022_3 = 1933,
147+
MSVC2022_9 = 1939,
147148
};
148149

149150
enum SYCLMajorVersion {

clang/lib/Basic/Targets/OSTargets.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,10 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) {
259259
Builder.defineMacro("_KERNEL_MODE");
260260

261261
Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
262-
Builder.defineMacro("__STDC_NO_THREADS__");
263-
262+
// Define __STDC_NO_THREADS__ based on MSVC version, threads.h availability,
263+
// and language standard.
264+
if (!(Opts.isCompatibleWithMSVC(LangOptions::MSVC2022_9) && Opts.C11))
265+
Builder.defineMacro("__STDC_NO_THREADS__");
264266
// Starting with VS 2022 17.1, MSVC predefines the below macro to inform
265267
// users of the execution character set defined at compile time.
266268
// The value given is the Windows Code Page Identifier:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -E -dM -triple=arm64ec-windows-msvc -std=c89 -fms-compatibility-version=19.33 -ffreestanding < /dev/null | FileCheck -check-prefix=C89_MSVC33 %s
2+
// RUN: %clang_cc1 -E -dM -triple=arm64ec-windows-msvc -std=c99 -fms-compatibility-version=19.33 -ffreestanding < /dev/null | FileCheck -check-prefix=C99_MSVC33 %s
3+
// RUN: %clang_cc1 -E -dM -triple=arm64ec-windows-msvc -std=c11 -fms-compatibility-version=19.33 -ffreestanding < /dev/null | FileCheck -check-prefix=C11_MSVC33 %s
4+
// RUN: %clang_cc1 -E -dM -triple=arm64ec-windows-msvc -std=c89 -fms-compatibility-version=19.39 -ffreestanding < /dev/null | FileCheck -check-prefix=C89_MSVC39 %s
5+
// RUN: %clang_cc1 -E -dM -triple=arm64ec-windows-msvc -std=c99 -fms-compatibility-version=19.39 -ffreestanding < /dev/null | FileCheck -check-prefix=C99_MSVC39 %s
6+
// RUN: %clang_cc1 -E -dM -triple=arm64ec-windows-msvc -std=c11 -fms-compatibility-version=19.39 -ffreestanding < /dev/null | FileCheck -check-prefix=C11_MSVC39 %s
7+
// RUN: %clang_cc1 -E -dM -triple=arm64ec-windows-msvc -std=c11 -fms-compatibility-version=19.40 -ffreestanding < /dev/null | FileCheck -check-prefix=C11_MSVC40 %s
8+
9+
// C89_MSVC33: #define __STDC_NO_THREADS__ 1
10+
// C99_MSVC33: #define __STDC_NO_THREADS__ 1
11+
// C11_MSVC33: #define __STDC_NO_THREADS__ 1
12+
// C89_MSVC39: #define __STDC_NO_THREADS__ 1
13+
// C99_MSVC39: #define __STDC_NO_THREADS__ 1
14+
// C11_MSVC39-NOT: #define __STDC_NO_THREADS__
15+
// C11_MSVC40-NOT: #define __STDC_NO_THREADS__

clang/test/Preprocessor/init-aarch64.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@
772772
// AARCH64-MSVC: #define __WINT_WIDTH__ 16
773773
// AARCH64-MSVC: #define __aarch64__ 1
774774

775-
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=arm64ec-windows-msvc < /dev/null | FileCheck -match-full-lines -check-prefix ARM64EC-MSVC %s
775+
// RUN: %clang_cc1 -E -dM -fms-compatibility-version=19.33 -ffreestanding -triple=arm64ec-windows-msvc < /dev/null | FileCheck -match-full-lines -check-prefix ARM64EC-MSVC %s
776776

777777
// ARM64EC-MSVC: #define _INTEGRAL_MAX_BITS 64
778778
// ARM64EC-MSVC: #define _M_AMD64 100

0 commit comments

Comments
 (0)