Skip to content

Commit 8d1758e

Browse files
committed
[clang] guard __STDC_NO_THREADS__ defination for MSVCVersion 2022 17.9 and above
1 parent c4ca87e commit 8d1758e

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ C Language Changes
382382
------------------
383383

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

386387
C2y Feature Support
387388
^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/LangOptions.h

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,12 @@ 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.LangStd >= LangStandard::lang_c11))) {
265+
Builder.defineMacro("__STDC_NO_THREADS__");
266+
}
267+
// Builder.defineMacro("__STDC_NO_THREADS__");
264268
// Starting with VS 2022 17.1, MSVC predefines the below macro to inform
265269
// users of the execution character set defined at compile time.
266270
// The value given is the Windows Code Page Identifier:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
8+
// C89_MSVC33: #define __STDC_NO_THREADS__ 1
9+
// C99_MSVC33: #define __STDC_NO_THREADS__ 1
10+
// C11_MSVC33: #define __STDC_NO_THREADS__ 1
11+
// C89_MSVC39: #define __STDC_NO_THREADS__ 1
12+
// C99_MSVC39: #define __STDC_NO_THREADS__ 1
13+
// C11_MSVC39-NOT: #define __STDC_NO_THREADS__ 0

clang/test/Preprocessor/init-aarch64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@
747747
// AARCH64-MSVC: #define __WINT_WIDTH__ 16
748748
// AARCH64-MSVC: #define __aarch64__ 1
749749

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

752752
// ARM64EC-MSVC: #define _INTEGRAL_MAX_BITS 64
753753
// ARM64EC-MSVC: #define _M_AMD64 100

0 commit comments

Comments
 (0)