-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[ARM][clang] Add some build attributes support #161106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
paperchalice
wants to merge
1
commit into
llvm:main
Choose a base branch
from
paperchalice:arm-abi-tag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4627b47
to
b0984e7
Compare
b0984e7
to
005a0ff
Compare
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: None (paperchalice) ChangesUnsafeFPMath and related flags will be removed in future, let frontend generate some hints for ARM backend to generate ABI tags. Full diff: https://github.com/llvm/llvm-project/pull/161106.diff 4 Files Affected:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 0eac7c351b164..6baa66ed84791 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,32 @@ 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() !=
+ LangOptions::FPExceptionModeKind::FPE_Ignore)
+ getModule().addModuleFlag(llvm::Module::Warning, "arm-eabi-fp-exceptions",
+ llvm::ARMBuildAttrs::Allowed);
+
+ if (getLangOpts().NoHonorNaNs && getLangOpts().NoHonorInfs)
+ TagVal = llvm::ARMBuildAttrs::AllowIEEENormal;
+ 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..2f7ff17df0526
--- /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 -menable-no-infs -menable-no-nans -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() {}
diff --git a/clang/test/CodeGen/ubsan-function-sugared.cpp b/clang/test/CodeGen/ubsan-function-sugared.cpp
index fb2487c024ba9..2eb1e5239de50 100644
--- a/clang/test/CodeGen/ubsan-function-sugared.cpp
+++ b/clang/test/CodeGen/ubsan-function-sugared.cpp
@@ -10,9 +10,9 @@ auto fun() {}
// GNU-LABEL: define{{.*}} void @_Z6callerv()
// MSVC-LABEL: define{{.*}} void @"?caller@@YAXXZ"()
-// ARM: ptrtoint ptr {{.*}} to i32, !nosanitize !4
-// ARM: and i32 {{.*}}, -2, !nosanitize !4
-// ARM: inttoptr i32 {{.*}} to ptr, !nosanitize !4
+// ARM: ptrtoint ptr {{.*}} to i32, !nosanitize !7
+// ARM: and i32 {{.*}}, -2, !nosanitize !7
+// ARM: inttoptr i32 {{.*}} to ptr, !nosanitize !7
// CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 0, !nosanitize
// CHECK: load i32, ptr {{.*}}, align {{.*}}, !nosanitize
// CHECK: icmp eq i32 {{.*}}, -1056584962, !nosanitize
diff --git a/clang/test/CodeGen/ubsan-function.cpp b/clang/test/CodeGen/ubsan-function.cpp
index 76d4237383f83..33c110eb6a404 100644
--- a/clang/test/CodeGen/ubsan-function.cpp
+++ b/clang/test/CodeGen/ubsan-function.cpp
@@ -13,9 +13,9 @@ void fun() {}
// GNU-LABEL: define{{.*}} void @_Z6callerPFvvE(ptr noundef %f)
// MSVC-LABEL: define{{.*}} void @"?caller@@YAXP6AXXZ@Z"(ptr noundef %f)
-// ARM: ptrtoint ptr {{.*}} to i32, !nosanitize !5
-// ARM: and i32 {{.*}}, -2, !nosanitize !5
-// ARM: inttoptr i32 {{.*}} to ptr, !nosanitize !5
+// ARM: ptrtoint ptr {{.*}} to i32, !nosanitize !8
+// ARM: and i32 {{.*}}, -2, !nosanitize !8
+// ARM: inttoptr i32 {{.*}} to ptr, !nosanitize !8
// AUTH: %[[STRIPPED:.*]] = ptrtoint ptr {{.*}} to i64, !nosanitize
// AUTH: call i64 @llvm.ptrauth.auth(i64 %[[STRIPPED]], i32 0, i64 0), !nosanitize
// CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 0, !nosanitize
|
statham-arm
approved these changes
Sep 29, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:codegen
IR generation bugs: mangling, exceptions, etc.
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
UnsafeFPMath and related flags will be removed in future, let frontend generate some hints for ARM backend to generate ABI tags.