Skip to content

Commit

Permalink
[IRGen][DebugInfo] split method declaration and definition.
Browse files Browse the repository at this point in the history
  • Loading branch information
DianQK committed Jul 1, 2023
1 parent 66a7ebe commit bd1cc77
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,18 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
/*IsLocalToUnit=*/Fn ? Fn->hasInternalLinkage() : true,
/*IsDefinition=*/true, /*IsOptimized=*/Opts.shouldOptimize());

// When the function is a method, we only want a DW_AT_declaration there,
// because LLVM LTO can't unify type definitions when a child DIE is a full
// subprogram definition.
if (Rep == SILFunctionTypeRepresentation::Method) {
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::toSPFlags(
/*IsLocalToUnit=*/Fn ? Fn->hasInternalLinkage() : true,
/*IsDefinition=*/false, /*IsOptimized=*/Opts.shouldOptimize());
Decl = DBuilder.createMethod(Scope, Name, LinkageName, File, Line, DIFnTy,
0, 0, nullptr, Flags, SPFlags,
TemplateParameters, Error);
}

// Construct the DISubprogram.
llvm::DISubprogram *SP = DBuilder.createFunction(
Scope, Name, LinkageName, File, Line, DIFnTy, ScopeLine, Flags, SPFlags,
Expand Down
27 changes: 27 additions & 0 deletions test/DebugInfo/method.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir -gdwarf-types -o - | %FileCheck %s

// Verify that we added a declaration for a method.
public struct Foo {
static func static_method() {}
func method() {}
}

public class Bar {
static func static_method() {}
func method() {}
}

func a_function() {}

// CHECK: distinct !DISubprogram(name: "static_method",
// CHECK-SAME: declaration:
// CHECK: distinct !DISubprogram(name: "method",
// CHECK-SAME: declaration:
// CHECK: distinct !DISubprogram(name: "static_method",
// CHECK-SAME: declaration:
// CHECK: distinct !DISubprogram(name: "method",
// CHECK-SAME: declaration:

// CHECK: distinct !DISubprogram(name: "a_function",
// CHECK-NOT: declaration:
// CHECK-SAME: )

0 comments on commit bd1cc77

Please sign in to comment.