Skip to content

Add initial support for debug info for coroutine allocas. #18717

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
Aug 15, 2018
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
18 changes: 11 additions & 7 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2003,21 +2003,25 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic(
return;

// A dbg.declare is only meaningful if there is a single alloca for
// the variable that is live throughout the function. With SIL
// optimizations this is not guaranteed and a variable can end up in
// two allocas (for example, one function inlined twice).
// the variable that is live throughout the function.
if (auto *Alloca = dyn_cast<llvm::AllocaInst>(Storage)) {
auto *ParentBB = Alloca->getParent();
auto InsertBefore = std::next(Alloca->getIterator());
if (InsertBefore != ParentBB->end())
DBuilder.insertDeclare(Alloca, Var, Expr, DL, &*InsertBefore);
else
DBuilder.insertDeclare(Alloca, Var, Expr, DL, ParentBB);
return;
} else if (isa<llvm::IntrinsicInst>(Storage) &&
cast<llvm::IntrinsicInst>(Storage)->getIntrinsicID() ==
llvm::Intrinsic::coro_alloca_get) {
// FIXME: The live range of a coroutine alloca within the function may be
// limited, so using a dbg.addr instead of a dbg.declare would be more
// appropriate.
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);
}

void IRGenDebugInfoImpl::emitGlobalVariableDeclaration(
Expand Down
14 changes: 11 additions & 3 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4001,9 +4001,15 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
VarDecl *Decl = i->getDecl();
// Describe the underlying alloca. This way an llvm.dbg.declare instrinsic
// is used, which is valid for the entire lifetime of the alloca.
if (auto *BitCast = dyn_cast<llvm::BitCastInst>(addr))
if (auto *Alloca = dyn_cast<llvm::AllocaInst>(BitCast->getOperand(0)))
if (auto *BitCast = dyn_cast<llvm::BitCastInst>(addr)) {
auto *Op0 = BitCast->getOperand(0);
if (auto *Alloca = dyn_cast<llvm::AllocaInst>(Op0))
addr = Alloca;
else if (auto *CoroAllocaGet = dyn_cast<llvm::IntrinsicInst>(Op0)) {
if (CoroAllocaGet->getIntrinsicID() == llvm::Intrinsic::coro_alloca_get)
addr = CoroAllocaGet;
}
}

auto DS = i->getDebugScope();
if (!DS)
Expand All @@ -4016,7 +4022,9 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
StringRef Name = getVarName(i, IsAnonymous);

// At this point addr must be an alloca or an undef.
assert(isa<llvm::AllocaInst>(addr) || isa<llvm::UndefValue>(addr));
assert(isa<llvm::AllocaInst>(addr) || isa<llvm::UndefValue>(addr) ||
isa<llvm::IntrinsicInst>(addr));

auto Indirection = DirectValue;
if (!IGM.IRGen.Opts.shouldOptimize())
if (auto *Alloca = dyn_cast<llvm::AllocaInst>(addr))
Expand Down