From 4ec01a8c0500db928e14c51ca946ed224abece70 Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Mon, 16 Nov 2020 07:04:23 -0800 Subject: [PATCH 1/2] IRGen: Fix debug emission for dynamically sized stack vars rdar://71427419 --- lib/IRGen/IRGenSIL.cpp | 18 +++++++++++++++++- test/IRGen/async/debug.swift | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/IRGen/async/debug.swift diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index fb0aa07479832..f46805e49b44d 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -4627,6 +4627,17 @@ void IRGenSILFunction::visitIsEscapingClosureInst( setLoweredExplosion(i, out); } +static bool isCallToSwiftTaskAlloc(llvm::Value *val) { + auto *call = dyn_cast(val); + if (!call) + return false; + auto *callee = call->getCalledFunction(); + if (!callee) + return false; + auto isTaskAlloc = callee->getName().equals("swift_task_alloc"); + return isTaskAlloc; +} + void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i, const TypeInfo &type, llvm::Value *addr) { @@ -4644,6 +4655,11 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i, else if (auto *CoroAllocaGet = dyn_cast(Op0)) { if (CoroAllocaGet->getIntrinsicID() == llvm::Intrinsic::coro_alloca_get) addr = CoroAllocaGet; + } else if (auto *call = dyn_cast(Op0)) { + addr = call; + bool isTaskAlloc = isCallToSwiftTaskAlloc(call); + assert(isTaskAlloc && "expecting call to swift_task_alloc"); + (void)isTaskAlloc; } } @@ -4659,7 +4675,7 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i, // At this point addr must be an alloca or an undef. assert(isa(addr) || isa(addr) || - isa(addr)); + isa(addr) || isCallToSwiftTaskAlloc(addr)); auto Indirection = DirectValue; if (!IGM.IRGen.Opts.DisableDebuggerShadowCopies && diff --git a/test/IRGen/async/debug.swift b/test/IRGen/async/debug.swift new file mode 100644 index 0000000000000..3184cc4af27bc --- /dev/null +++ b/test/IRGen/async/debug.swift @@ -0,0 +1,14 @@ +// RUN: %target-swift-frontend -primary-file %s -emit-ir -enable-experimental-concurrency -g | %FileCheck %s + +// Don't assert on dynamically sized variables. +// CHECK: define swiftcc void @"$s5debug1fyxxYKlF" + +public func f(_ value: Success) async throws -> Success { + switch Result.success(value) { + case .success(let success): + return success + + case .failure(let error): + throw error; + } +} From d5d7f391305884289267efd1c8c0ad8ff7ea971f Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Mon, 16 Nov 2020 08:20:32 -0800 Subject: [PATCH 2/2] Fix test for windows/linux --- test/IRGen/async/debug.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/IRGen/async/debug.swift b/test/IRGen/async/debug.swift index 3184cc4af27bc..f0a8a255301fb 100644 --- a/test/IRGen/async/debug.swift +++ b/test/IRGen/async/debug.swift @@ -1,7 +1,7 @@ // RUN: %target-swift-frontend -primary-file %s -emit-ir -enable-experimental-concurrency -g | %FileCheck %s // Don't assert on dynamically sized variables. -// CHECK: define swiftcc void @"$s5debug1fyxxYKlF" +// CHECK: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s5debug1fyxxYKlF" public func f(_ value: Success) async throws -> Success { switch Result.success(value) {