diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index 0cb0d9daef2c4..dc3854b3b367c 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -2328,7 +2328,11 @@ llvm::DIScope *IRGenDebugInfoImpl::getOrCreateScope(const SILDebugScope *DS) { // Force the debug info for the function to be emitted, even if it // is external or has been inlined. llvm::Function *Fn = nullptr; - if (!SILFn->getName().empty() && !SILFn->isZombie()) + // Avoid materializing generic functions in embedded Swift mode. + bool genericInEmbedded = + IGM.Context.LangOpts.hasFeature(Feature::Embedded) && + SILFn->isGeneric(); + if (!SILFn->getName().empty() && !SILFn->isZombie() && !genericInEmbedded) Fn = IGM.getAddrOfSILFunction(SILFn, NotForDefinition); auto *SP = emitFunction(*SILFn, Fn); diff --git a/test/embedded/generic-classes-debuginfo.swift b/test/embedded/generic-classes-debuginfo.swift new file mode 100644 index 0000000000000..b7c0fb5d35491 --- /dev/null +++ b/test/embedded/generic-classes-debuginfo.swift @@ -0,0 +1,49 @@ +// RUN: %target-run-simple-swift(-g %S/Inputs/print.swift -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s +// RUN: %target-run-simple-swift(-g -Osize %S/Inputs/print.swift -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s + +// REQUIRES: executable_test +// REQUIRES: optimized_stdlib +// REQUIRES: VENDOR=apple +// REQUIRES: OS=macosx + +struct User { + let o: BaseClass +} + +class BaseClass { + func foo() {} +} + +protocol Protocol { + func protofoo() +} + +class Implementor: Protocol { + func protofoo() { print("Implementor.protofoo") } +} + +class GenericSubClass: BaseClass { + let p: P + + init(p: P) { + self.p = p + } + + override func foo() { + let x = { self.p.protofoo() } + x() + } +} + +@main +struct Main { + static func main() { + let p = Implementor() + let o = GenericSubClass(p: p) + let user = User(o: o) + user.o.foo() + } +} + +// CHECK: Implementor.protofoo +