Skip to content

Commit a8dfbec

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

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
@@ -248,8 +248,19 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) {
248248
Builder.defineMacro("_KERNEL_MODE");
249249

250250
Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
251-
Builder.defineMacro("__STDC_NO_THREADS__");
252-
251+
// Define __STDC_NO_THREADS__ based on MSVC version, threads.h availability,
252+
// and language standard.
253+
if (!Opts.isCompatibleWithMSVC(LangOptions::MSVC2022_9)) {
254+
Builder.defineMacro("__STDC_NO_THREADS__");
255+
} else {
256+
#if defined(__has_include) && !__has_include(<threads.h>)
257+
Builder.defineMacro("__STDC_NO_THREADS__");
258+
#endif
259+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L
260+
Builder.defineMacro("__STDC_NO_THREADS__");
261+
#endif
262+
}
263+
// Builder.defineMacro("__STDC_NO_THREADS__");
253264
// Starting with VS 2022 17.1, MSVC predefines the below macro to inform
254265
// users of the execution character set defined at compile time.
255266
// The value given is the Windows Code Page Identifier:

0 commit comments

Comments
 (0)