Skip to content

Commit 187a9d1

Browse files
fixup! [NFC][LLVM] Refactor Autoupgrade function attributes from Module attributes.
1 parent f7370ed commit 187a9d1

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5182,7 +5182,14 @@ void llvm::UpgradeFunctionAttributes(Function &F) {
51825182
static bool isModuleAttributeSet(Module &M, const StringRef &ModAttr) {
51835183
const auto *Attr =
51845184
mdconst::extract_or_null<ConstantInt>(M.getModuleFlag(ModAttr));
5185-
return Attr && Attr->getZExtValue();
5185+
return Attr && Attr->isOne();
5186+
}
5187+
5188+
// Check if the function attribute is not present and set it.
5189+
static void SetFunctionAttrIfNotSet(Function &F, StringRef FnAttrName,
5190+
StringRef Value) {
5191+
if (!F.hasFnAttribute(FnAttrName))
5192+
F.addFnAttr(FnAttrName, Value);
51865193
}
51875194

51885195
void llvm::CopyModuleAttrToFunctions(Module &M) {
@@ -5191,10 +5198,10 @@ void llvm::CopyModuleAttrToFunctions(Module &M) {
51915198
return;
51925199

51935200
StringRef SignTypeValue = "none";
5194-
if (isModuleAttributeSet(M, "sign-return-address"))
5195-
SignTypeValue = "non-leaf";
51965201
if (isModuleAttributeSet(M, "sign-return-address-all"))
51975202
SignTypeValue = "all";
5203+
else if (isModuleAttributeSet(M, "sign-return-address"))
5204+
SignTypeValue = "non-leaf";
51985205

51995206
StringRef BTEValue =
52005207
isModuleAttributeSet(M, "branch-target-enforcement") ? "true" : "false";
@@ -5209,16 +5216,12 @@ void llvm::CopyModuleAttrToFunctions(Module &M) {
52095216
for (Function &F : M.getFunctionList()) {
52105217
if (F.isDeclaration())
52115218
continue;
5212-
auto SetFunctionAttrIfNotSet = [&](StringRef FnAttrName, StringRef Value) {
5213-
if (!F.hasFnAttribute(FnAttrName))
5214-
F.addFnAttr(FnAttrName, Value);
5215-
};
52165219

5217-
SetFunctionAttrIfNotSet("sign-return-address", SignTypeValue);
5218-
SetFunctionAttrIfNotSet("branch-target-enforcement", BTEValue);
5219-
SetFunctionAttrIfNotSet("branch-protection-pauth-lr", BPPLValue);
5220-
SetFunctionAttrIfNotSet("guarded-control-stack", GCSValue);
5221-
SetFunctionAttrIfNotSet("sign-return-address-key", SignKeyValue);
5220+
SetFunctionAttrIfNotSet(F, "sign-return-address", SignTypeValue);
5221+
SetFunctionAttrIfNotSet(F, "branch-target-enforcement", BTEValue);
5222+
SetFunctionAttrIfNotSet(F, "branch-protection-pauth-lr", BPPLValue);
5223+
SetFunctionAttrIfNotSet(F, "guarded-control-stack", GCSValue);
5224+
SetFunctionAttrIfNotSet(F, "sign-return-address-key", SignKeyValue);
52225225
}
52235226
}
52245227

llvm/test/LTO/AArch64/link-sign-return-address.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ entry:
2929
!3 = !{i32 8, !"sign-return-address-with-bkey", i32 0}
3030

3131
; CHECK-DUMP: <foo>:
32-
; CHECK-DUMP: paciasp
32+
; CHECK-DUMP: pacibsp
3333
; CHECK-DUMP: mov w0, #0x2a
34-
; CHECK-DUMP: autiasp
34+
; CHECK-DUMP: autibsp
3535
; CHECK-DUMP: ret
3636
; CHECK-DUMP: <main>:
3737
; CHECK-DUMP-NOT: paciasp

0 commit comments

Comments
 (0)