[clang] [clang] __STDC_NO_THREADS__ is no longer necessary for VS 2022 1939 and above (PR #117149)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 21 11:03:31 PST 2024


================
@@ -248,8 +248,19 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) {
     Builder.defineMacro("_KERNEL_MODE");
 
   Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
-  Builder.defineMacro("__STDC_NO_THREADS__");
-
+  // Define __STDC_NO_THREADS__ based on MSVC version, threads.h availability,
+  // and language standard.
+  if (!Opts.isCompatibleWithMSVC(LangOptions::MSVC2022_9)) {
+    Builder.defineMacro("__STDC_NO_THREADS__");
+  } else {
+#if defined(__has_include) && !__has_include(<threads.h>)
+    Builder.defineMacro("__STDC_NO_THREADS__");
+#endif
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L
+    Builder.defineMacro("__STDC_NO_THREADS__");
+#endif
----------------
AaronBallman wrote:

These changes are looking at the host compiler's behavior when building Clang, not the state of the system on which Clang is running, so they won't do what you expect.

Trying to determine if the system has a threads.h header on the search path is possible, but would be really tricky to do from here because this function doesn't have access to what's needed to do that work.

As for checking for C11, that can be done via `!Opts.C11`

https://github.com/llvm/llvm-project/pull/117149


More information about the cfe-commits mailing list