Skip to content

Emit compiler-generated debug locations for outlined transparent functions #16701

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
May 18, 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
3 changes: 2 additions & 1 deletion lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3332,7 +3332,8 @@ irgen::emitAssociatedTypeMetadataRef(IRGenFunction &IGF,
FunctionPointer witnessFnPtr(witness, sig);

// Call the accessor.
assert((!IGF.IGM.DebugInfo || IGF.Builder.getCurrentDebugLocation()) &&
assert((!IGF.IGM.DebugInfo || IGF.Builder.getCurrentDebugLocation() ||
!IGF.CurFn->getSubprogram()) &&
"creating a function call without a debug location");
auto call = IGF.Builder.CreateCall(witnessFnPtr,
{ request.get(IGF),
Expand Down
23 changes: 16 additions & 7 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {

auto L = decodeDebugLoc(CS->Loc);
auto Scope = getOrCreateScope(CS->Parent.dyn_cast<const SILDebugScope *>());
// Pretend transparent functions don't exist.
if (!Scope)
return createInlinedAt(CS);
auto InlinedAt =
llvm::DebugLoc::get(L.Line, L.Column, Scope, createInlinedAt(CS));
InlinedAtCache.insert(
Expand Down Expand Up @@ -1563,7 +1566,7 @@ void IRGenDebugInfoImpl::setCurrentLoc(IRBuilder &Builder,

SILLocation::DebugLoc L;
SILFunction *Fn = DS->getInlinedFunction();
if (Fn && Fn->isThunk()) {
if (Fn && (Fn->isThunk() || Fn->isTransparent())) {
L = SILLocation::getCompilerGeneratedDebugLoc();
} else if (DS == LastScope && Loc.isAutoGenerated()) {
// Reuse the last source location if we are still in the same
Expand Down Expand Up @@ -1735,6 +1738,7 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
// Some IRGen-generated helper functions don't have a corresponding
// SIL function, hence the dyn_cast.
auto *SILFn = DS ? DS->Parent.dyn_cast<SILFunction *>() : nullptr;

StringRef LinkageName;
if (Fn)
LinkageName = Fn->getName();
Expand All @@ -1754,17 +1758,18 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
/// The source line used for the function prologue.
unsigned ScopeLine = 0;
SILLocation::DebugLoc L;
if (DS && (!SILFn || (!SILFn->isBare() && !SILFn->isThunk()))) {
if (!DS || (SILFn && (SILFn->isBare() || SILFn->isThunk() ||
SILFn->isTransparent()))) {
// Bare functions and thunks should not have any line numbers. This
// is especially important for shared functions like reabstraction
// thunk helpers, where DS->Loc is an arbitrary location of whichever use
// was emitted first.
L = SILLocation::getCompilerGeneratedDebugLoc();
} else {
L = decodeDebugLoc(DS->Loc);
ScopeLine = L.Line;
if (!DS->Loc.isDebugInfoLoc())
L = decodeSourceLoc(DS->Loc.getSourceLoc());
} else {
L = SILLocation::getCompilerGeneratedDebugLoc();
}

auto Line = L.Line;
Expand Down Expand Up @@ -1882,7 +1887,7 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
if (!DbgTy.size)
DbgTy.size = getStorageSize(IGM.DataLayout, Storage);

auto *Scope = dyn_cast<llvm::DILocalScope>(getOrCreateScope(DS));
auto *Scope = dyn_cast_or_null<llvm::DILocalScope>(getOrCreateScope(DS));
assert(Scope && "variable has no local scope");
auto Loc = getDebugLoc(*this, VarDecl);

Expand Down Expand Up @@ -2028,13 +2033,17 @@ void IRGenDebugInfoImpl::emitTypeMetadata(IRGenFunction &IGF,
if (Opts.DebugInfoKind <= IRGenDebugInfoKind::LineTables)
return;

// Don't emit debug info in transparent functions.
auto *DS = IGF.getDebugScope();
if (!DS || DS->getInlinedFunction()->isTransparent())
return;

auto TName = BumpAllocatedString(("$swift.type." + Name).str());
auto DbgTy = DebugTypeInfo::getMetadata(
getMetadataType()->getDeclaredInterfaceType().getPointer(),
Metadata->getType(), Size(CI.getTargetInfo().getPointerWidth(0)),
Alignment(CI.getTargetInfo().getPointerAlign(0)));
emitVariableDeclaration(IGF.Builder, Metadata, DbgTy, IGF.getDebugScope(),
nullptr, TName, 0,
emitVariableDeclaration(IGF.Builder, Metadata, DbgTy, DS, nullptr, TName, 0,
// swift.type is already a pointer type,
// having a shadow copy doesn't add another
// layer of indirection.
Expand Down
18 changes: 15 additions & 3 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1771,8 +1771,8 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
for (auto &I : *BB) {
if (IGM.DebugInfo) {
// Set the debug info location for I, if applicable.
SILLocation ILoc = I.getLoc();
auto DS = I.getDebugScope();
SILLocation ILoc = I.getLoc();
// Handle cleanup locations.
if (ILoc.is<CleanupLocation>()) {
// Cleanup locations point to the decl of the value that is
Expand Down Expand Up @@ -1830,9 +1830,8 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
emitDebugVariableRangeExtension(BB);
}
visit(&I);

}

assert(Builder.hasPostTerminatorIP() && "SIL bb did not terminate block?!");
}

Expand Down Expand Up @@ -3647,6 +3646,9 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
if (!IGM.DebugInfo)
return;

if (i->getDebugScope()->getInlinedFunction()->isTransparent())
return;

auto VarInfo = i->getVarInfo();
assert(VarInfo && "debug_value without debug info");
auto SILVal = i->getOperand();
Expand Down Expand Up @@ -3689,6 +3691,10 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
void IRGenSILFunction::visitDebugValueAddrInst(DebugValueAddrInst *i) {
if (!IGM.DebugInfo)
return;

if (i->getDebugScope()->getInlinedFunction()->isTransparent())
return;

VarDecl *Decl = i->getDecl();
if (!Decl)
return;
Expand Down Expand Up @@ -3968,6 +3974,9 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
if (!DS)
return;

if (i->getDebugScope()->getInlinedFunction()->isTransparent())
return;

bool IsAnonymous = false;
StringRef Name = getVarName(i, IsAnonymous);

Expand Down Expand Up @@ -4171,6 +4180,9 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
DbgName);
setLoweredBox(i, boxWithAddr);

if (i->getDebugScope()->getInlinedFunction()->isTransparent())
return;

if (IGM.DebugInfo && Decl) {
// FIXME: This is a workaround to not produce local variables for
// capture list arguments like "[weak self]". The better solution
Expand Down
2 changes: 1 addition & 1 deletion test/DebugInfo/autoclosure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func &&&&&(lhs: Bool, rhs: @autoclosure () -> Bool) -> Bool {
func call_me(_ input: Int64) -> Void {
// rdar://problem/14627460
// An autoclosure should have a line number in the debug info and a scope line of 0.
// CHECK-DAG: !DISubprogram({{.*}}linkageName: "$S11autoclosure7call_meyys5Int64VFSbyXKfu_",{{.*}} line: [[@LINE+3]],{{.*}} isLocal: true, isDefinition: true
// CHECK-DAG: !DISubprogram({{.*}}linkageName: "$S11autoclosure7call_meyys5Int64VFSbyXKfu_",{{.*}} isLocal: true, isDefinition: true
// But not in the line table.
// CHECK-DAG: ![[DBG]] = !DILocation(line: [[@LINE+1]],
if input != 0 &&&&& ( get_truth (input * 2 + 1) > 0 ) {
Expand Down
5 changes: 2 additions & 3 deletions test/DebugInfo/generic_enum_closure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ struct CErrorOr<T>
// CHECK-SAME: !DIExpression(DW_OP_deref))
// CHECK-DAG: store i8* %[[DYN:.*]], i8** %[[SHADOW]]
// CHECK-DAG: %[[DYN]] = alloca i8, i{{32|64}} %
// CHECK: ![[T1:.*]] = !DICompositeType({{.*}}, identifier: "$S20generic_enum_closure8CErrorOrVyACQq_GD")
// CHECK: ![[SELF]] = !DILocalVariable(name: "self", scope:
// CHECK-SAME: type: ![[T1]])
// CHECK-DAG: ![[T1:.*]] = !DICompositeType({{.*}}, identifier: "$S20generic_enum_closure8CErrorOrVyACQq_GD")
// CHECK-DAG: ![[SELF]] = !DILocalVariable(name: "self", scope:{{.*}}, type: ![[T1]])
value = .none
}
}
29 changes: 29 additions & 0 deletions test/DebugInfo/transparent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %target-swift-frontend %s -O -I %t -emit-ir -g -o - | %FileCheck %s

func use<T>(_ t: T) {}

@inline(never)
public func noinline(_ x: Int64) -> Int64 { return x }

@_transparent
public func transparent(_ y: Int64) -> Int64 {
var local = y
return noinline(local)
}

let z = transparent(0)
use(z)

// Check that a transparent function has no debug information.
// CHECK: define {{.*}}$S11transparentAA
// CHECK-SAME: !dbg ![[SP:[0-9]+]]
// CHECK-NEXT: entry:
// CHECK-NEXT: !dbg ![[ZERO:[0-9]+]]
// CHECK-NEXT: !dbg ![[ZERO]]
// CHECK-NEXT: }

// CHECK: ![[SP]] = {{.*}}name: "transparent"
// CHECK-SAME: file: ![[FILE:[0-9]+]]
// CHECK-NOT: line:
// CHECK: ![[FILE]] = {{.*}}"<compiler-generated>"
// CHECK: ![[ZERO]] = !DILocation(line: 0,