Skip to content

Commit d13c81d

Browse files
Merge pull request #37844 from adrian-prantl/78977132-5.5
Fix a debug info regression introduced with async support.
2 parents c6778c8 + 19203f2 commit d13c81d

File tree

4 files changed

+28
-36
lines changed

4 files changed

+28
-36
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
198198
void emitDbgIntrinsic(IRBuilder &Builder, llvm::Value *Storage,
199199
llvm::DILocalVariable *Var, llvm::DIExpression *Expr,
200200
unsigned Line, unsigned Col, llvm::DILocalScope *Scope,
201-
const SILDebugScope *DS, bool InCoroContext = false);
201+
const SILDebugScope *DS, bool InCoroContext);
202202

203203
void emitGlobalVariableDeclaration(llvm::GlobalVariable *Storage,
204204
StringRef Name, StringRef LinkageName,
@@ -2419,21 +2419,9 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
24192419
// Emit locationless intrinsic for variables that were optimized away.
24202420
if (Storage.empty())
24212421
emitDbgIntrinsic(Builder, llvm::ConstantInt::get(IGM.Int64Ty, 0), Var,
2422-
DBuilder.createExpression(), Line, Loc.column, Scope, DS);
2423-
}
2424-
2425-
static bool pointsIntoAlloca(llvm::Value *Storage) {
2426-
while (Storage) {
2427-
if (auto *LdInst = dyn_cast<llvm::LoadInst>(Storage))
2428-
Storage = LdInst->getOperand(0);
2429-
else if (auto *GEPInst = dyn_cast<llvm::GetElementPtrInst>(Storage))
2430-
Storage = GEPInst->getOperand(0);
2431-
else if (auto *BCInst = dyn_cast<llvm::BitCastInst>(Storage))
2432-
Storage = BCInst->getOperand(0);
2433-
else
2434-
return isa<llvm::AllocaInst>(Storage);
2435-
}
2436-
return false;
2422+
DBuilder.createExpression(), Line, Loc.column, Scope, DS,
2423+
Indirection == CoroDirectValue ||
2424+
Indirection == CoroIndirectValue);
24372425
}
24382426

24392427
void IRGenDebugInfoImpl::emitDbgIntrinsic(
@@ -2477,11 +2465,8 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic(
24772465
else
24782466
DBuilder.insertDeclare(Storage, Var, Expr, DL, &EntryBlock);
24792467
} else {
2480-
if (pointsIntoAlloca(Storage))
2481-
DBuilder.insertDeclare(Storage, Var, Expr, DL, BB);
2482-
else
2483-
// Insert a dbg.value at the current insertion point.
2484-
DBuilder.insertDbgValueIntrinsic(Storage, Var, Expr, DL, BB);
2468+
// Insert a dbg.value at the current insertion point.
2469+
DBuilder.insertDbgValueIntrinsic(Storage, Var, Expr, DL, BB);
24852470
}
24862471
}
24872472

lib/IRGen/IRGenSIL.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ class IRGenSILFunction :
10571057
void emitDebugVariableDeclaration(StorageType Storage, DebugTypeInfo Ty,
10581058
SILType SILTy, const SILDebugScope *DS,
10591059
VarDecl *VarDecl, SILDebugVariable VarInfo,
1060-
IndirectionKind Indirection = DirectValue) {
1060+
IndirectionKind Indirection) {
10611061
// TODO: fix demangling for C++ types (SR-13223).
10621062
if (swift::TypeBase *ty = SILTy.getASTType().getPointer()) {
10631063
if (MetatypeType *metaTy = dyn_cast<MetatypeType>(ty))
@@ -4695,6 +4695,14 @@ void IRGenSILFunction::emitPoisonDebugValueInst(DebugValueInst *i) {
46954695
Builder.CreateStore(newShadowVal, shadowAddress, ptrAlign);
46964696
}
46974697

4698+
/// Determine whether the debug-info-carrying instruction \c i belongs to an
4699+
/// async function and thus may get allocated in the coroutine context. These
4700+
/// variables need to be marked with the Coro flag, so LLVM's CoroSplit pass can
4701+
/// recognize them.
4702+
static bool InCoroContext(SILFunction &f, SILInstruction &i) {
4703+
return f.isAsync() && !i.getDebugScope()->InlinedCallSite;
4704+
}
4705+
46984706
void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
46994707
if (i->poisonRefs()) {
47004708
emitPoisonDebugValueInst(i);
@@ -4739,11 +4747,8 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
47394747
if (!IGM.DebugInfo)
47404748
return;
47414749

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

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

5106-
auto Indirection = DirectValue;
5111+
auto Indirection =
5112+
InCoroContext(*CurSILFn, *i) ? CoroDirectValue : DirectValue;
51075113
if (!IGM.IRGen.Opts.DisableDebuggerShadowCopies &&
51085114
!IGM.IRGen.Opts.shouldOptimize())
51095115
if (auto *Alloca = dyn_cast<llvm::AllocaInst>(addr))
51105116
if (!Alloca->isStaticAlloca()) {
51115117
// Store the address of the dynamic alloca on the stack.
51125118
addr = emitShadowCopy(addr, DS, *VarInfo, IGM.getPointerAlignment(),
51135119
/*init*/ true);
5114-
Indirection = IndirectValue;
5120+
Indirection =
5121+
InCoroContext(*CurSILFn, *i) ? CoroIndirectValue : IndirectValue;
51155122
}
51165123

51175124
if (!Decl)
@@ -5352,9 +5359,9 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
53525359
if (!IGM.DebugInfo)
53535360
return;
53545361

5355-
IGM.DebugInfo->emitVariableDeclaration(Builder, Storage, DbgTy,
5356-
i->getDebugScope(), Decl, *VarInfo,
5357-
IndirectValue);
5362+
IGM.DebugInfo->emitVariableDeclaration(
5363+
Builder, Storage, DbgTy, i->getDebugScope(), Decl, *VarInfo,
5364+
InCoroContext(*CurSILFn, *i) ? CoroIndirectValue : IndirectValue);
53585365
}
53595366

53605367
void IRGenSILFunction::visitProjectBoxInst(swift::ProjectBoxInst *i) {

test/DebugInfo/async-lifetime-extension.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
// CHECK-NEXT: entryresume.0:
1111
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[RHS:[0-9]+]], {{.*}}!DIExpression(DW_OP
1212
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[LHS:[0-9]+]], {{.*}}!DIExpression(DW_OP
13-
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[N:[0-9]+]], {{.*}}!DIExpression(DW_OP
1413
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[R:[0-9]+]], {{.*}}!DIExpression(DW_OP
14+
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[N:[0-9]+]], {{.*}}!DIExpression(DW_OP
1515
// CHECK-NOT: {{ ret }}
1616
// CHECK: call void asm sideeffect ""
1717
// CHECK: ![[RHS]] = !DILocalVariable(name: "rhs"
1818
// CHECK: ![[LHS]] = !DILocalVariable(name: "lhs"
19-
// CHECK: ![[N]] = !DILocalVariable(name: "n"
2019
// CHECK: ![[R]] = !DILocalVariable(name: "retval"
20+
// CHECK: ![[N]] = !DILocalVariable(name: "n"
2121
public func fibo(_ n: Int) async -> Int {
2222
var retval = n
2323
if retval < 2 { return 1 }

test/DebugInfo/inlined-generics-basic.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public class C<R> {
6565
// IR: call {{.*}}3use
6666
#sourceLocation(file: "f.swift", line: 3)
6767
g(r)
68-
// IR: dbg.declare({{.*}}, metadata ![[GRS_T:[0-9]+]]
69-
// IR: dbg.declare({{.*}}, metadata ![[GRS_U:[0-9]+]]
68+
// IR: dbg.value({{.*}}, metadata ![[GRS_T:[0-9]+]]
69+
// IR: dbg.value({{.*}}, metadata ![[GRS_U:[0-9]+]]
7070
// IR: call {{.*}}3use
7171
#sourceLocation(file: "f.swift", line: 4)
7272
g((r, s))

0 commit comments

Comments
 (0)