Skip to content

Commit a0dccc5

Browse files
Merge pull request #34762 from aschwaighofer/irgen_var_sized_alloca_async
IRGen: Fix debug emission for dynamically sized stack vars
2 parents 744767b + d5d7f39 commit a0dccc5

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4627,6 +4627,17 @@ void IRGenSILFunction::visitIsEscapingClosureInst(
46274627
setLoweredExplosion(i, out);
46284628
}
46294629

4630+
static bool isCallToSwiftTaskAlloc(llvm::Value *val) {
4631+
auto *call = dyn_cast<llvm::CallInst>(val);
4632+
if (!call)
4633+
return false;
4634+
auto *callee = call->getCalledFunction();
4635+
if (!callee)
4636+
return false;
4637+
auto isTaskAlloc = callee->getName().equals("swift_task_alloc");
4638+
return isTaskAlloc;
4639+
}
4640+
46304641
void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
46314642
const TypeInfo &type,
46324643
llvm::Value *addr) {
@@ -4644,6 +4655,11 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
46444655
else if (auto *CoroAllocaGet = dyn_cast<llvm::IntrinsicInst>(Op0)) {
46454656
if (CoroAllocaGet->getIntrinsicID() == llvm::Intrinsic::coro_alloca_get)
46464657
addr = CoroAllocaGet;
4658+
} else if (auto *call = dyn_cast<llvm::CallInst>(Op0)) {
4659+
addr = call;
4660+
bool isTaskAlloc = isCallToSwiftTaskAlloc(call);
4661+
assert(isTaskAlloc && "expecting call to swift_task_alloc");
4662+
(void)isTaskAlloc;
46474663
}
46484664
}
46494665

@@ -4659,7 +4675,7 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
46594675

46604676
// At this point addr must be an alloca or an undef.
46614677
assert(isa<llvm::AllocaInst>(addr) || isa<llvm::UndefValue>(addr) ||
4662-
isa<llvm::IntrinsicInst>(addr));
4678+
isa<llvm::IntrinsicInst>(addr) || isCallToSwiftTaskAlloc(addr));
46634679

46644680
auto Indirection = DirectValue;
46654681
if (!IGM.IRGen.Opts.DisableDebuggerShadowCopies &&

test/IRGen/async/debug.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-frontend -primary-file %s -emit-ir -enable-experimental-concurrency -g | %FileCheck %s
2+
3+
// Don't assert on dynamically sized variables.
4+
// CHECK: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s5debug1fyxxYKlF"
5+
6+
public func f<Success>(_ value: Success) async throws -> Success {
7+
switch Result<Success, Error>.success(value) {
8+
case .success(let success):
9+
return success
10+
11+
case .failure(let error):
12+
throw error;
13+
}
14+
}

0 commit comments

Comments
 (0)