[clang] [ARM][clang] Add some build attributes support (PR #161106)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 28 17:01:03 PDT 2025
https://github.com/paperchalice created https://github.com/llvm/llvm-project/pull/161106
UnsafeFPMath and related flags will be removed in future, let frontend generate some hints for ARM backend to generate ABI tags.
>From 7fd51c64e29691f6b98bb1b0cb5843c5fd0611cf Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Sat, 27 Sep 2025 17:30:14 +0800
Subject: [PATCH] [ARM][clang] Add some build attributes support
---
clang/lib/CodeGen/CodeGenModule.cpp | 26 +++++++++++++++++++++++
clang/test/CodeGen/ARM/build-attributes.c | 15 +++++++++++++
2 files changed, 41 insertions(+)
create mode 100644 clang/test/CodeGen/ARM/build-attributes.c
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 0eac7c351b164..cd74b6091b251 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -61,6 +61,7 @@
#include "llvm/IR/ProfileSummary.h"
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/ProfileData/SampleProf.h"
+#include "llvm/Support/ARMBuildAttributes.h"
#include "llvm/Support/CRC.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/CommandLine.h"
@@ -1383,6 +1384,31 @@ void CodeGenModule::Release() {
}
}
}
+ if ((T.isARM() || T.isThumb()) && getTriple().isTargetAEABI() &&
+ getTriple().isOSBinFormatELF()) {
+ uint32_t TagVal = 0;
+ if (getCodeGenOpts().FPDenormalMode ==
+ llvm::DenormalMode::getPositiveZero())
+ TagVal = llvm::ARMBuildAttrs::PositiveZero;
+ else if (getCodeGenOpts().FPDenormalMode == llvm::DenormalMode::getIEEE())
+ TagVal = llvm::ARMBuildAttrs::IEEEDenormals;
+ else if (getCodeGenOpts().FPDenormalMode ==
+ llvm::DenormalMode::getPreserveSign())
+ TagVal = llvm::ARMBuildAttrs::PreserveFPSign;
+ getModule().addModuleFlag(llvm::Module::Warning, "arm-eabi-fp-denormal",
+ TagVal);
+
+ if (getLangOpts().getFPExceptionMode() != FPExceptionModeKind::FPE_Ignore)
+ getModule().addModuleFlag(llvm::Module::Warning, "arm-eabi-fp-exceptions",
+ llvm::ARMBuildAttrs::Allowed);
+
+ if (getLangOpts().NoHonorNaNs && getLangOpts().NoHonorInfs)
+ TagVal = llvm::ARMBuildAttrs::Allowed;
+ else
+ TagVal = llvm::ARMBuildAttrs::AllowIEEE754;
+ getModule().addModuleFlag(llvm::Module::Warning, "arm-eabi-fp-number-model",
+ TagVal);
+ }
if (CodeGenOpts.StackClashProtector)
getModule().addModuleFlag(
diff --git a/clang/test/CodeGen/ARM/build-attributes.c b/clang/test/CodeGen/ARM/build-attributes.c
new file mode 100644
index 0000000000000..670f0c34e8590
--- /dev/null
+++ b/clang/test/CodeGen/ARM/build-attributes.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple arm-none-eabi -fdenormal-fp-math=positive-zero -emit-llvm -o - | FileCheck %s --check-prefix=DM-PZ
+// RUN: %clang_cc1 -triple arm-none-eabi -fdenormal-fp-math=ieee -emit-llvm -o - | FileCheck %s --check-prefix=DM-IEEE
+// RUN: %clang_cc1 -triple arm-none-eabi -fdenormal-fp-math=preserve-sign -emit-llvm -o - | FileCheck %s --check-prefix=DM-PS
+
+// RUN: %clang_cc1 -triple arm-none-eabi -ffinite-math-only -emit-llvm -o - | FileCheck %s --check-prefix=NM-FIN
+// RUN: %clang_cc1 -triple arm-none-eabi -emit-llvm -o - | FileCheck %s --check-prefix=NM-IEEE
+
+// DM-PZ: !{i32 2, !"arm-eabi-fp-denormal", i32 0}
+// DM-IEEE: !{i32 2, !"arm-eabi-fp-denormal", i32 1}
+// DM-PS: !{i32 2, !"arm-eabi-fp-denormal", i32 2}
+
+// NM-FIN: !{i32 2, !"arm-eabi-fp-number-model", i32 1}
+// NM-IEEE: !{i32 2, !"arm-eabi-fp-number-model", i32 3}
+
+void foo() {}
More information about the cfe-commits
mailing list