Skip to content

Commit c55e4ee

Browse files
committed
[clang] guard __STDC_NO_THREADS__ defination for MSVCVersion 2022 17.9 and above
1 parent ebc7efb commit c55e4ee

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,19 @@ 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)) {
265+
Builder.defineMacro("__STDC_NO_THREADS__");
266+
} else {
267+
#if defined(__has_include) && !__has_include(<threads.h>)
268+
Builder.defineMacro("__STDC_NO_THREADS__");
269+
#endif
270+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L
271+
Builder.defineMacro("__STDC_NO_THREADS__");
272+
#endif
273+
}
274+
// Builder.defineMacro("__STDC_NO_THREADS__");
264275
// Starting with VS 2022 17.1, MSVC predefines the below macro to inform
265276
// users of the execution character set defined at compile time.
266277
// The value given is the Windows Code Page Identifier:

0 commit comments

Comments
 (0)