Skip to content

Commit dd0db18

Browse files
committed
Debug Info: Unify the handling of indirect values and fix a bug where
ParenTypes were not recognized as generic. Fixes rdar://problem/23681035
1 parent 2e1c4fa commit dd0db18

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,12 @@ void IRGenDebugInfo::emitVariableDeclaration(
10001000
if (Artificial || DITy->isArtificial() || DITy == InternalType)
10011001
Flags |= llvm::DINode::FlagArtificial;
10021002

1003+
// LValues, inout args, and Archetypes are implicitly indirect by
1004+
// virtue of their DWARF type.
1005+
if (DbgTy.getType()->getKind() == TypeKind::InOut ||
1006+
DbgTy.getType()->hasArchetype())
1007+
Indirection = DirectValue;
1008+
10031009
// Create the descriptor for the variable.
10041010
llvm::DILocalVariable *Var = nullptr;
10051011

lib/IRGen/IRGenSIL.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2957,17 +2957,6 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
29572957
i->getVarInfo().getArgNo());
29582958
}
29592959

2960-
/// InOut- and Archetypes are already implicitly indirect.
2961-
static IndirectionKind getIndirectionForDebugValueAddr(swift::TypeBase *Ty) {
2962-
switch (Ty->getKind()) {
2963-
case TypeKind::InOut:
2964-
case TypeKind::Archetype:
2965-
return DirectValue;
2966-
default:
2967-
return IndirectValue;
2968-
}
2969-
}
2970-
29712960
void IRGenSILFunction::visitDebugValueAddrInst(DebugValueAddrInst *i) {
29722961
if (!IGM.DebugInfo)
29732962
return;
@@ -2983,10 +2972,9 @@ void IRGenSILFunction::visitDebugValueAddrInst(DebugValueAddrInst *i) {
29832972
auto Addr = getLoweredAddress(SILVal).getAddress();
29842973
DebugTypeInfo DbgTy(Decl, Decl->getType(), getTypeInfo(SILVal.getType()));
29852974
// Put the value into a stack slot at -Onone and emit a debug intrinsic.
2986-
emitDebugVariableDeclaration(
2987-
emitShadowCopy(Addr, Name), DbgTy, i->getDebugScope(), Name,
2988-
i->getVarInfo().getArgNo(),
2989-
getIndirectionForDebugValueAddr(DbgTy.getType()));
2975+
emitDebugVariableDeclaration(emitShadowCopy(Addr, Name), DbgTy,
2976+
i->getDebugScope(), Name,
2977+
i->getVarInfo().getArgNo(), IndirectValue);
29902978
}
29912979

29922980
void IRGenSILFunction::visitLoadWeakInst(swift::LoadWeakInst *i) {
@@ -3400,16 +3388,11 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
34003388
// arguments.
34013389
if (Name == IGM.Context.Id_self.str())
34023390
return;
3403-
auto Indirection = IndirectValue;
3404-
// LValues and inout args are implicitly indirect because of their type.
3405-
if (Decl->getType()->getKind() == TypeKind::LValue ||
3406-
Decl->getType()->getKind() == TypeKind::InOut)
3407-
Indirection = DirectValue;
34083391

34093392
IGM.DebugInfo->emitVariableDeclaration(
34103393
Builder, emitShadowCopy(addr.getAddress(), Name),
34113394
DebugTypeInfo(Decl, i->getElementType().getSwiftType(), type),
3412-
i->getDebugScope(), Name, 0, Indirection);
3395+
i->getDebugScope(), Name, 0, IndirectValue);
34133396
}
34143397
}
34153398

test/DebugInfo/generic_arg3.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -g -o - | FileCheck %s
2+
3+
func apply<Type>(T : Type, fn: (Type) -> Type) -> Type { return fn(T) }
4+
5+
public func f<Type>(value : Type)
6+
{
7+
// CHECK: define {{.*}}_TFF12generic_arg31furFxT_U_FQ_Q_
8+
// CHECK: store %swift.opaque* %1, %swift.opaque** %[[ALLOCA:.*]], align
9+
// CHECK: call void @llvm.dbg.declare(metadata %swift.opaque** %[[ALLOCA]],
10+
// CHECK-SAME: metadata ![[ARG:.*]], metadata ![[EXPR:.*]])
11+
// A generic argument is implictly indirect and should not be dereferenced.
12+
// CHECK: ![[EXPR]] = !DIExpression()
13+
// CHECK: ![[ARG]] = !DILocalVariable(name: "arg", arg: 1,
14+
// CHECK-SAME: line: [[@LINE+1]], type: !"_TtQq_F12generic_arg31furFxT_")
15+
apply(value) { arg in return arg }
16+
}

0 commit comments

Comments
 (0)