https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/223156
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) <[email protected]> >From baa2354d6e6babdddb9b16015757b1477ffd1c92 Mon Sep 17 00:00:00 2001 From: Matt Arsenault <[email protected]> Date: Thu, 10 Sep 2026 20:26:47 +0200 Subject: [PATCH] clang: Emit the "thread-model" module flag 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) <[email protected]> --- clang/lib/CodeGen/CodeGenModule.cpp | 9 +++++++++ clang/test/CodeGen/thread-model.c | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 clang/test/CodeGen/thread-model.c 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" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
