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

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 21 04:31:29 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Dipesh Sharma (dipeshs809)

<details>
<summary>Changes</summary>

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 

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


2 Files Affected:

- (modified) clang/include/clang/Basic/LangOptions.h (+1) 
- (modified) clang/lib/Basic/Targets/OSTargets.cpp (+13-2) 


``````````diff
diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h
index 949c8f5d448bcf..114a5d34a008bd 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -144,6 +144,7 @@ class LangOptionsBase {
     MSVC2019_5 = 1925,
     MSVC2019_8 = 1928,
     MSVC2022_3 = 1933,
+    MSVC2022_9 = 1939,
   };
 
   enum SYCLMajorVersion {
diff --git a/clang/lib/Basic/Targets/OSTargets.cpp b/clang/lib/Basic/Targets/OSTargets.cpp
index 88c054150ab224..f8d974e9979e4d 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -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
+  }
+  // Builder.defineMacro("__STDC_NO_THREADS__");
   // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
   // users of the execution character set defined at compile time.
   // The value given is the Windows Code Page Identifier:

``````````

</details>


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


More information about the cfe-commits mailing list