Skip to content

Commit 35297b3

Browse files
[DebugInfo] Dont emit info for __swift_async_resume_project_context or __swift_async_resume_get_context
Those functions are effectively outlined functions with an alwaysinline attribute. By removing their debug info and relying on the inliner to propagate the call site location to the inlined instructions, we restore the "original" locations as if the function had never been outlined. This is technically relying on an implementation detail of the inliner, but it seems to be the simplest way of addressing this issue.
1 parent 2880517 commit 35297b3

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3114,7 +3114,7 @@ void IRGenModule::createReplaceableProlog(IRGenFunction &IGF, SILFunction *f) {
31143114
// Index of swiftasync context | ((index of swiftself) << 8).
31153115
arguments.push_back(IGM.getInt32(paramAttributeFlags));
31163116
arguments.push_back(currentResumeFn);
3117-
auto resumeProjFn = IGF.getOrCreateResumePrjFn(true /*forProlog*/);
3117+
auto resumeProjFn = IGF.getOrCreateResumePrjFn();
31183118
arguments.push_back(
31193119
Builder.CreateBitOrPointerCast(resumeProjFn, IGM.Int8PtrTy));
31203120
auto dispatchFn = IGF.createAsyncDispatchFn(

lib/IRGen/GenFunc.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,11 +2846,12 @@ IRGenFunction::emitAsyncResumeProjectContext(llvm::Value *calleeContext) {
28462846
return callerContext;
28472847
}
28482848

2849-
llvm::Function *IRGenFunction::getOrCreateResumePrjFn(bool forPrologue) {
2850-
// The prologue version lacks artificial debug info as this would cause
2851-
// verification errors when it gets inlined.
2852-
auto name = forPrologue ? "__swift_async_resume_project_context_prologue"
2853-
: "__swift_async_resume_project_context";
2849+
llvm::Function *IRGenFunction::getOrCreateResumePrjFn() {
2850+
auto name = "__swift_async_resume_project_context";
2851+
// This is effectively an outlined function with `alwaysinline`. Don't emit
2852+
// debug locations for those to avoid creating unnecessary inlined frames.
2853+
// Instead, rely on the inliner to propagate the call site debug location.
2854+
const bool skipDebugInfo = true;
28542855
auto Fn = cast<llvm::Function>(IGM.getOrCreateHelperFunction(
28552856
name, IGM.Int8PtrTy, {IGM.Int8PtrTy},
28562857
[&](IRGenFunction &IGF) {
@@ -2860,7 +2861,7 @@ llvm::Function *IRGenFunction::getOrCreateResumePrjFn(bool forPrologue) {
28602861
auto callerContext = IGF.emitAsyncResumeProjectContext(addr);
28612862
Builder.CreateRet(callerContext);
28622863
},
2863-
false /*isNoInline*/, forPrologue));
2864+
false /*isNoInline*/, skipDebugInfo));
28642865
Fn->addFnAttr(llvm::Attribute::AlwaysInline);
28652866
return Fn;
28662867
}
@@ -2955,7 +2956,7 @@ llvm::Function *IRGenFunction::getOrCreateResumeFromSuspensionFn() {
29552956
auto &Builder = IGF.Builder;
29562957
Builder.CreateRet(&*IGF.CurFn->arg_begin());
29572958
},
2958-
false /*isNoInline*/));
2959+
false /*isNoInline*/, true /*forPrologue*/));
29592960
fn->addFnAttr(llvm::Attribute::AlwaysInline);
29602961
return fn;
29612962
}

lib/IRGen/IRGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class IRGenFunction {
178178
bool restoreCurrentContext = true);
179179

180180
llvm::Value *emitAsyncResumeProjectContext(llvm::Value *callerContextAddr);
181-
llvm::Function *getOrCreateResumePrjFn(bool forPrologue = false);
181+
llvm::Function *getOrCreateResumePrjFn();
182182
llvm::Function *createAsyncDispatchFn(const FunctionPointer &fnPtr,
183183
ArrayRef<llvm::Value *> args);
184184
llvm::Function *createAsyncDispatchFn(const FunctionPointer &fnPtr,

test/DebugInfo/async-await-no-debug-info-outlined-funcs.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@ func ASYNC___2___() async -> Int {
2222
// CHECK: ret void
2323
// CHECK-NEXT: }
2424

25+
// CHECK-LABEL: define {{.*}} @__swift_async_resume_get_context
26+
// CHECK-NOT: !dbg
27+
// CHECK: ret ptr
28+
// CHECK-NEXT: }
29+
2530
// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___2___SiyYaF.1"
2631
// CHECK-NOT: !dbg
2732
// CHECK: ret void
2833
// CHECK-NEXT: }
2934

35+
// CHECK-LABEL: define {{.*}} @__swift_async_resume_project_context
36+
// CHECK-NOT: !dbg
37+
// CHECK: ret ptr
38+
// CHECK-NEXT: }
39+
3040
// CHECK-LABEL: define {{.*}} @"$s1M12ASYNC___2___SiyYaF.0"
3141
// CHECK-NOT: !dbg
3242
// CHECK: ret void

0 commit comments

Comments
 (0)