[llvm-branch-commits] [clang] clang: Emit "target-abi" module flag for ARM (PR #217601)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Aug 20 05:20:52 PDT 2026
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/217601
Previously only RISCV emitted the "target-abi" module flag.
We probably should just generally emit this for non-empty ABI names
but that's a broader behavior change. I'm also confused because the
clang side defines a non-empty value for many targets with no apparent
use in llvm.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
>From 86fca790c3db2f93dd9523229e7d9b2417b3c22c Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Tue, 18 Aug 2026 20:40:10 +0200
Subject: [PATCH] clang: Emit "target-abi" module flag for ARM
Previously only RISCV emitted the "target-abi" module flag.
We probably should just generally emit this for non-empty ABI names
but that's a broader behavior change. I'm also confused because the
clang side defines a non-empty value for many targets with no apparent
use in llvm.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
---
clang/lib/CodeGen/CodeGenModule.cpp | 14 +++++++++++---
.../test/CodeGen/arm-target-abi-module-flag.c | 19 +++++++++++++++++++
2 files changed, 30 insertions(+), 3 deletions(-)
create mode 100644 clang/test/CodeGen/arm-target-abi-module-flag.c
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index d348e80780ee9..50901fe388140 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1472,6 +1472,17 @@ void CodeGenModule::Release() {
}
llvm::Triple T = Context.getTargetInfo().getTriple();
+
+ // TODO: This should probably be just generally emitted for non-empty ABI
+ // names. LoongArch actively consumes the flag, but it is excluded here.
+ // Other targets have no apparent need for the ABI name, but set a non-empty
+ // value.
+ if (StringRef ABIStr = Target.getABI();
+ !ABIStr.empty() && (T.isARM() || T.isThumb() || T.isRISCV())) {
+ getModule().addModuleFlag(llvm::Module::Error, "target-abi",
+ llvm::MDString::get(VMContext, ABIStr));
+ }
+
if (T.isARM() || T.isThumb()) {
// The minimum width of an enum in bytes
uint32_t EnumWidth = Context.getLangOpts().ShortEnums ? 1 : 4;
@@ -1479,10 +1490,7 @@ void CodeGenModule::Release() {
}
if (T.isRISCV()) {
- StringRef ABIStr = Target.getABI();
llvm::LLVMContext &Ctx = TheModule.getContext();
- getModule().addModuleFlag(llvm::Module::Error, "target-abi",
- llvm::MDString::get(Ctx, ABIStr));
// Add the canonical ISA string as metadata so the backend can set the ELF
// attributes correctly. We use AppendUnique so LTO will keep all of the
diff --git a/clang/test/CodeGen/arm-target-abi-module-flag.c b/clang/test/CodeGen/arm-target-abi-module-flag.c
new file mode 100644
index 0000000000000..9707372b2a3fd
--- /dev/null
+++ b/clang/test/CodeGen/arm-target-abi-module-flag.c
@@ -0,0 +1,19 @@
+// Check that clang emits the "target-abi" module flag for ARM/Thumb using the
+// target ABI string.
+
+// Default ABIs (no -target-abi override).
+// RUN: %clang_cc1 -triple armv7-linux-gnueabihf -emit-llvm -o - %s | FileCheck --check-prefix=AAPCS-LINUX %s
+// RUN: %clang_cc1 -triple armv7-none-eabi -emit-llvm -o - %s | FileCheck --check-prefix=AAPCS %s
+// RUN: %clang_cc1 -triple armv7-apple-darwin -emit-llvm -o - %s | FileCheck --check-prefix=APCS-GNU %s
+// RUN: %clang_cc1 -triple armv7k-apple-watchos -emit-llvm -o - %s | FileCheck --check-prefix=AAPCS16 %s
+// RUN: %clang_cc1 -triple thumbv7-linux-gnueabihf -emit-llvm -o - %s | FileCheck --check-prefix=AAPCS-LINUX %s
+
+// Explicit -target-abi override differing from the triple default.
+// RUN: %clang_cc1 -triple armv7-linux-gnueabihf -target-abi apcs-gnu -emit-llvm -o - %s | FileCheck --check-prefix=APCS-GNU %s
+
+// AAPCS-LINUX: !{i32 1, !"target-abi", !"aapcs-linux"}
+// AAPCS: !{i32 1, !"target-abi", !"aapcs"}
+// APCS-GNU: !{i32 1, !"target-abi", !"apcs-gnu"}
+// AAPCS16: !{i32 1, !"target-abi", !"aapcs16"}
+
+int x;
More information about the llvm-branch-commits
mailing list