Skip to content

Commit cf1d8e1

Browse files
author
git apple-llvm automerger
committed
Merge commit '3ab71dd19641' from apple/stable/20200714 into swift/main
2 parents 7f7bb39 + 3ab71dd commit cf1d8e1

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,14 +1797,6 @@ void CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
17971797
FuncAttrs.addAttribute("stackrealign");
17981798
if (CodeGenOpts.Backchain)
17991799
FuncAttrs.addAttribute("backchain");
1800-
if (CodeGenOpts.PointerAuth.ReturnAddresses)
1801-
FuncAttrs.addAttribute("ptrauth-returns");
1802-
if (CodeGenOpts.PointerAuth.FunctionPointers)
1803-
FuncAttrs.addAttribute("ptrauth-calls");
1804-
if (CodeGenOpts.PointerAuth.IndirectGotos)
1805-
FuncAttrs.addAttribute("ptrauth-indirect-gotos");
1806-
if (CodeGenOpts.PointerAuth.AuthTraps)
1807-
FuncAttrs.addAttribute("ptrauth-auth-traps");
18081800
if (CodeGenOpts.EnableSegmentedStacks)
18091801
FuncAttrs.addAttribute("split-stack");
18101802

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,17 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
771771
FD->getBody()->getStmtClass() == Stmt::CoroutineBodyStmtClass)
772772
SanOpts.Mask &= ~SanitizerKind::Null;
773773

774+
// Add pointer authentication attributes.
775+
const CodeGenOptions &CodeGenOpts = CGM.getCodeGenOpts();
776+
if (CodeGenOpts.PointerAuth.ReturnAddresses)
777+
Fn->addFnAttr("ptrauth-returns");
778+
if (CodeGenOpts.PointerAuth.FunctionPointers)
779+
Fn->addFnAttr("ptrauth-calls");
780+
if (CodeGenOpts.PointerAuth.IndirectGotos)
781+
Fn->addFnAttr("ptrauth-indirect-gotos");
782+
if (CodeGenOpts.PointerAuth.AuthTraps)
783+
Fn->addFnAttr("ptrauth-auth-traps");
784+
774785
// Apply xray attributes to the function (as a string, for now)
775786
if (const auto *XRayAttr = D ? D->getAttr<XRayInstrumentAttr>() : nullptr) {
776787
if (CGM.getCodeGenOpts().XRayInstrumentationBundle.has(

clang/test/CodeGenCXX/ptrauth.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -fptrauth-returns -fptrauth-intrinsics -emit-llvm -std=c++11 -fexceptions -fcxx-exceptions -o - %s | FileCheck %s
2+
3+
void foo1();
4+
5+
void test_terminate() noexcept {
6+
foo1();
7+
}
8+
9+
// CHECK: define void @_ZSt9terminatev() #[[ATTR4:.*]] {
10+
11+
namespace std {
12+
void terminate() noexcept {
13+
}
14+
}
15+
16+
// CHECK: attributes #[[ATTR4]] = {{{.*}}"ptrauth-calls" "ptrauth-returns"{{.*}}}

0 commit comments

Comments
 (0)