[clang] clang: Emit the "thread-model" module flag (PR #223156)

via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 12 08:44:47 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-codegen

Author: Matt Arsenault (arsenm)

<details>
<summary>Changes</summary>

Emit the threading model as the "thread-model" IR module flag. This
will eventually replace the TargetOptions field.

Co-authored-by: Claude (Claude-Opus-4.8) <noreply@<!-- -->anthropic.com>

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+9) 
- (added) clang/test/CodeGen/thread-model.c (+11) 


``````````diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 40feb4b30f98c..e208c2ca153b2 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1434,6 +1434,15 @@ void CodeGenModule::Release() {
                             llvm::FloatABI::getABITypeName(FloatABI)));
   }
 
+  // Record the thread model as a module flag when it differs from the target
+  // default.
+  llvm::ThreadModel ThreadModel =
+      LangOpts.getThreadModel() == LangOptions::ThreadModelKind::Single
+          ? llvm::ThreadModel::Single
+          : llvm::ThreadModel::POSIX;
+  if (ThreadModel != getTriple().getDefaultThreadModel())
+    getModule().setThreadModel(ThreadModel);
+
   if (getTypes().isLongDoubleReferenced()) {
     const llvm::fltSemantics *flt = &getTarget().getLongDoubleFormat();
 
diff --git a/clang/test/CodeGen/thread-model.c b/clang/test/CodeGen/thread-model.c
new file mode 100644
index 0000000000000..cf6eb82c948a0
--- /dev/null
+++ b/clang/test/CodeGen/thread-model.c
@@ -0,0 +1,11 @@
+// Check that the "thread-model" module flag is emitted for -mthread-model
+// single, and omitted when the model matches the target default (posix).
+
+// RUN: %clang_cc1 -triple arm-none-linux-gnueabi -mthread-model single -emit-llvm %s -o - | FileCheck %s --check-prefix=SINGLE
+// RUN: %clang_cc1 -triple arm-none-linux-gnueabi -mthread-model posix -emit-llvm %s -o - | FileCheck %s --check-prefix=POSIX
+// RUN: %clang_cc1 -triple arm-none-linux-gnueabi -emit-llvm %s -o - | FileCheck %s --check-prefix=POSIX
+
+void f(void) {}
+
+// SINGLE: !{i32 1, !"thread-model", !"single"}
+// POSIX-NOT: "thread-model"

``````````

</details>


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


More information about the cfe-commits mailing list