Skip to content

Commit bda5f20

Browse files
vhscamposDhruvSrivastavaX
authored andcommitted
[Coroutines] Create C++ noop coroutine with default function attributes (llvm#134878)
This change makes the C++ noop coroutine to be built with attributes based on the module flags. Among other things, this adds function attributes related to the Pointer Authentication and Branch Target Enforcement module flags, which are set by command-line options. Before this patch, C++ programs built with either PAC-RET or BTI that had the noop coroutine emitted could have a runtime error because this function wasn't compatible with the rest of the program.
1 parent 008a5e7 commit bda5f20

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

llvm/lib/Transforms/Coroutines/CoroEarly.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@ void Lowerer::lowerCoroNoop(IntrinsicInst *II) {
131131
StructType::create({FnPtrTy, FnPtrTy}, "NoopCoro.Frame");
132132

133133
// Create a Noop function that does nothing.
134-
Function *NoopFn =
135-
Function::Create(FnTy, GlobalValue::LinkageTypes::PrivateLinkage,
136-
"__NoopCoro_ResumeDestroy", &M);
134+
Function *NoopFn = Function::createWithDefaultAttr(
135+
FnTy, GlobalValue::LinkageTypes::PrivateLinkage,
136+
M.getDataLayout().getProgramAddressSpace(), "__NoopCoro_ResumeDestroy",
137+
&M);
137138
NoopFn->setCallingConv(CallingConv::Fast);
138139
buildDebugInfoForNoopResumeDestroyFunc(NoopFn);
139140
auto *Entry = BasicBlock::Create(C, "entry", NoopFn);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
; RUN: opt < %s -S -passes=coro-early | FileCheck %s
3+
4+
; CHECK: define private fastcc void @__NoopCoro_ResumeDestroy(ptr %0) #1 {
5+
; CHECK-NEXT: entry:
6+
; CHECK-NEXT: ret void
7+
; CHECK-NEXT: }
8+
9+
; CHECK: attributes #1 = { "branch-target-enforcement" "sign-return-address"="all" "sign-return-address-key"="a_key" }
10+
11+
define ptr @noop() {
12+
entry:
13+
%n = call ptr @llvm.coro.noop()
14+
ret ptr %n
15+
}
16+
17+
declare ptr @llvm.coro.noop()
18+
19+
!llvm.module.flags = !{!0, !1, !2}
20+
21+
!0 = !{i32 8, !"branch-target-enforcement", i32 1}
22+
!1 = !{i32 8, !"sign-return-address", i32 1}
23+
!2 = !{i32 8, !"sign-return-address-all", i32 1}

0 commit comments

Comments
 (0)