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

via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 13 11:59:51 PDT 2026


Author: Matt Arsenault
Date: 2026-09-13T20:59:46+02:00
New Revision: 0485ad7e469a56443094872c0f57f2870eccb654

URL: https://github.com/llvm/llvm-project/commit/0485ad7e469a56443094872c0f57f2870eccb654
DIFF: https://github.com/llvm/llvm-project/commit/0485ad7e469a56443094872c0f57f2870eccb654.diff

LOG: clang: Emit the "thread-model" module flag (#223156)

Added: 
    clang/test/CodeGen/thread-model.c

Modified: 
    clang/lib/CodeGen/CodeGenModule.cpp

Removed: 
    


################################################################################
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 
diff ers 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"


        


More information about the cfe-commits mailing list