Skip to content

Fix a debug info regression introduced with async support. #37849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
void emitDbgIntrinsic(IRBuilder &Builder, llvm::Value *Storage,
llvm::DILocalVariable *Var, llvm::DIExpression *Expr,
unsigned Line, unsigned Col, llvm::DILocalScope *Scope,
const SILDebugScope *DS, bool InCoroContext = false);
const SILDebugScope *DS, bool InCoroContext);

void emitGlobalVariableDeclaration(llvm::GlobalVariable *Storage,
StringRef Name, StringRef LinkageName,
Expand Down Expand Up @@ -2419,21 +2419,9 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
// Emit locationless intrinsic for variables that were optimized away.
if (Storage.empty())
emitDbgIntrinsic(Builder, llvm::ConstantInt::get(IGM.Int64Ty, 0), Var,
DBuilder.createExpression(), Line, Loc.column, Scope, DS);
}

static bool pointsIntoAlloca(llvm::Value *Storage) {
while (Storage) {
if (auto *LdInst = dyn_cast<llvm::LoadInst>(Storage))
Storage = LdInst->getOperand(0);
else if (auto *GEPInst = dyn_cast<llvm::GetElementPtrInst>(Storage))
Storage = GEPInst->getOperand(0);
else if (auto *BCInst = dyn_cast<llvm::BitCastInst>(Storage))
Storage = BCInst->getOperand(0);
else
return isa<llvm::AllocaInst>(Storage);
}
return false;
DBuilder.createExpression(), Line, Loc.column, Scope, DS,
Indirection == CoroDirectValue ||
Indirection == CoroIndirectValue);
}

void IRGenDebugInfoImpl::emitDbgIntrinsic(
Expand Down Expand Up @@ -2477,11 +2465,8 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic(
else
DBuilder.insertDeclare(Storage, Var, Expr, DL, &EntryBlock);
} else {
if (pointsIntoAlloca(Storage))
DBuilder.insertDeclare(Storage, Var, Expr, DL, BB);
else
// Insert a dbg.value at the current insertion point.
DBuilder.insertDbgValueIntrinsic(Storage, Var, Expr, DL, BB);
// Insert a dbg.value at the current insertion point.
DBuilder.insertDbgValueIntrinsic(Storage, Var, Expr, DL, BB);
}
}

Expand Down
29 changes: 18 additions & 11 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ class IRGenSILFunction :
void emitDebugVariableDeclaration(StorageType Storage, DebugTypeInfo Ty,
SILType SILTy, const SILDebugScope *DS,
VarDecl *VarDecl, SILDebugVariable VarInfo,
IndirectionKind Indirection = DirectValue) {
IndirectionKind Indirection) {
// TODO: fix demangling for C++ types (SR-13223).
if (swift::TypeBase *ty = SILTy.getASTType().getPointer()) {
if (MetatypeType *metaTy = dyn_cast<MetatypeType>(ty))
Expand Down Expand Up @@ -4695,6 +4695,14 @@ void IRGenSILFunction::emitPoisonDebugValueInst(DebugValueInst *i) {
Builder.CreateStore(newShadowVal, shadowAddress, ptrAlign);
}

/// Determine whether the debug-info-carrying instruction \c i belongs to an
/// async function and thus may get allocated in the coroutine context. These
/// variables need to be marked with the Coro flag, so LLVM's CoroSplit pass can
/// recognize them.
static bool InCoroContext(SILFunction &f, SILInstruction &i) {
return f.isAsync() && !i.getDebugScope()->InlinedCallSite;
}

void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
if (i->poisonRefs()) {
emitPoisonDebugValueInst(i);
Expand Down Expand Up @@ -4739,11 +4747,8 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
if (!IGM.DebugInfo)
return;

IndirectionKind Indirection = DirectValue;
if (CurSILFn->isAsync() && !i->getDebugScope()->InlinedCallSite &&
(Copy.empty() || !isa<llvm::Constant>(Copy[0]))) {
Indirection = CoroDirectValue;
}
IndirectionKind Indirection =
InCoroContext(*CurSILFn, *i) ? CoroDirectValue : DirectValue;

emitDebugVariableDeclaration(Copy, DbgTy, SILTy, i->getDebugScope(),
i->getDecl(), *VarInfo, Indirection);
Expand Down Expand Up @@ -5103,15 +5108,17 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
assert(isa<llvm::AllocaInst>(addr) || isa<llvm::UndefValue>(addr) ||
isa<llvm::IntrinsicInst>(addr) || isCallToSwiftTaskAlloc(addr));

auto Indirection = DirectValue;
auto Indirection =
InCoroContext(*CurSILFn, *i) ? CoroDirectValue : DirectValue;
if (!IGM.IRGen.Opts.DisableDebuggerShadowCopies &&
!IGM.IRGen.Opts.shouldOptimize())
if (auto *Alloca = dyn_cast<llvm::AllocaInst>(addr))
if (!Alloca->isStaticAlloca()) {
// Store the address of the dynamic alloca on the stack.
addr = emitShadowCopy(addr, DS, *VarInfo, IGM.getPointerAlignment(),
/*init*/ true);
Indirection = IndirectValue;
Indirection =
InCoroContext(*CurSILFn, *i) ? CoroIndirectValue : IndirectValue;
}

if (!Decl)
Expand Down Expand Up @@ -5352,9 +5359,9 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
if (!IGM.DebugInfo)
return;

IGM.DebugInfo->emitVariableDeclaration(Builder, Storage, DbgTy,
i->getDebugScope(), Decl, *VarInfo,
IndirectValue);
IGM.DebugInfo->emitVariableDeclaration(
Builder, Storage, DbgTy, i->getDebugScope(), Decl, *VarInfo,
InCoroContext(*CurSILFn, *i) ? CoroIndirectValue : IndirectValue);
}

void IRGenSILFunction::visitProjectBoxInst(swift::ProjectBoxInst *i) {
Expand Down
4 changes: 2 additions & 2 deletions test/DebugInfo/async-lifetime-extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
// CHECK-NEXT: entryresume.0:
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[RHS:[0-9]+]], {{.*}}!DIExpression(DW_OP
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[LHS:[0-9]+]], {{.*}}!DIExpression(DW_OP
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[N:[0-9]+]], {{.*}}!DIExpression(DW_OP
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[R:[0-9]+]], {{.*}}!DIExpression(DW_OP
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[N:[0-9]+]], {{.*}}!DIExpression(DW_OP
// CHECK-NOT: {{ ret }}
// CHECK: call void asm sideeffect ""
// CHECK: ![[RHS]] = !DILocalVariable(name: "rhs"
// CHECK: ![[LHS]] = !DILocalVariable(name: "lhs"
// CHECK: ![[N]] = !DILocalVariable(name: "n"
// CHECK: ![[R]] = !DILocalVariable(name: "retval"
// CHECK: ![[N]] = !DILocalVariable(name: "n"
public func fibo(_ n: Int) async -> Int {
var retval = n
if retval < 2 { return 1 }
Expand Down
4 changes: 2 additions & 2 deletions test/DebugInfo/inlined-generics-basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public class C<R> {
// IR: call {{.*}}3use
#sourceLocation(file: "f.swift", line: 3)
g(r)
// IR: dbg.declare({{.*}}, metadata ![[GRS_T:[0-9]+]]
// IR: dbg.declare({{.*}}, metadata ![[GRS_U:[0-9]+]]
// IR: dbg.value({{.*}}, metadata ![[GRS_T:[0-9]+]]
// IR: dbg.value({{.*}}, metadata ![[GRS_U:[0-9]+]]
// IR: call {{.*}}3use
#sourceLocation(file: "f.swift", line: 4)
g((r, s))
Expand Down