Skip to content

Commit 85c21ec

Browse files
committed
Fix tests: don't init on call site, update in setTargetAttributes
1 parent 71d8526 commit 85c21ec

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,8 +2100,6 @@ static void getTrivialDefaultFunctionAttributes(
21002100

21012101
TargetInfo::BranchProtectionInfo BPI(LangOpts);
21022102
TargetCodeGenInfo::initBranchProtectionFnAttributes(BPI, FuncAttrs);
2103-
TargetCodeGenInfo::initPointerAuthFnAttributes(CodeGenOpts.PointerAuth,
2104-
FuncAttrs);
21052103
}
21062104

21072105
/// Merges `target-features` from \TargetOpts and \F, and sets the result in
@@ -2218,6 +2216,11 @@ void CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
22182216
llvm::AttrBuilder &FuncAttrs) {
22192217
getTrivialDefaultFunctionAttributes(Name, HasOptnone, AttrOnCallSite,
22202218
FuncAttrs);
2219+
2220+
if (!AttrOnCallSite)
2221+
TargetCodeGenInfo::initPointerAuthFnAttributes(CodeGenOpts.PointerAuth,
2222+
FuncAttrs);
2223+
22212224
// If we're just getting the default, get the default values for mergeable
22222225
// attributes.
22232226
if (!AttrOnCallSite)

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,21 @@ void TargetCodeGenInfo::initBranchProtectionFnAttributes(
258258
FuncAttrs.addAttribute("guarded-control-stack");
259259
}
260260

261+
void TargetCodeGenInfo::setPointerAuthFnAttributes(
262+
const PointerAuthOptions &Opts, llvm::Function &F) {
263+
auto UpdateAttr = [&F](bool AttrShouldExist, StringRef AttrName) {
264+
if (AttrShouldExist && !F.hasFnAttribute(AttrName))
265+
F.addFnAttr(AttrName);
266+
if (!AttrShouldExist && F.hasFnAttribute(AttrName))
267+
F.removeFnAttr(AttrName);
268+
};
269+
UpdateAttr(Opts.ReturnAddresses, "ptrauth-returns");
270+
UpdateAttr((bool)Opts.FunctionPointers, "ptrauth-calls");
271+
UpdateAttr(Opts.AuthTraps, "ptrauth-auth-traps");
272+
UpdateAttr(Opts.IndirectGotos, "ptrauth-indirect-gotos");
273+
UpdateAttr(Opts.AArch64JumpTableHardening, "aarch64-jump-table-hardening");
274+
}
275+
261276
void TargetCodeGenInfo::initPointerAuthFnAttributes(
262277
const PointerAuthOptions &Opts, llvm::AttrBuilder &FuncAttrs) {
263278
if (Opts.ReturnAddresses)

clang/lib/CodeGen/TargetInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ class TargetCodeGenInfo {
455455
initBranchProtectionFnAttributes(const TargetInfo::BranchProtectionInfo &BPI,
456456
llvm::AttrBuilder &FuncAttrs);
457457

458+
// Set the ptrauth-* attributes of the Function accordingly to the Opts.
459+
// Remove attributes that contradict with current Opts.
460+
static void setPointerAuthFnAttributes(const PointerAuthOptions &Opts,
461+
llvm::Function &F);
462+
458463
// Add the ptrauth-* Attributes to the FuncAttrs.
459464
static void initPointerAuthFnAttributes(const PointerAuthOptions &Opts,
460465
llvm::AttrBuilder &FuncAttrs);

clang/lib/CodeGen/Targets/AArch64.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class AArch64TargetCodeGenInfo : public TargetCodeGenInfo {
155155
}
156156
}
157157
setBranchProtectionFnAttributes(BPI, *Fn);
158+
setPointerAuthFnAttributes(CGM.getCodeGenOpts().PointerAuth, *Fn);
158159
}
159160

160161
bool isScalarizableAsmOperand(CodeGen::CodeGenFunction &CGF,

0 commit comments

Comments
 (0)