Skip to content

Commit bafcb9d

Browse files
committed
[cxx-interop] Do not get private discriminator for private Clang types (#80485)
When generating debug symbols for private Clang types (which we started importing recently), the compiler crashes due to an assertion failure from ClangModuleUnit::getDiscriminatorForPrivateDecl(), which is called by getFilePrivateScope(). This patch fixes the issue crash by not calling getFilePrivateScope() for Clang types. A discriminator is usually needed to disambiguate private Swift types declared in different files, but Clang types follow different scoping conventions that make this discriminator unnecessary. rdar://148481025 (cherry picked from commit dd2f465)
1 parent bbe10ec commit bafcb9d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2577,8 +2577,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
25772577

25782578
// Scope outermost fileprivate decls in an inline private discriminator
25792579
// namespace.
2580+
//
2581+
// We need to don't do this for decls imported from Clang modules because
2582+
// the scopes of C/C++ symbols are not restricted to a particular file unit.
25802583
if (auto *Decl = DbgTy.getDecl())
2581-
if (Decl->isOutermostPrivateOrFilePrivateScope())
2584+
if (Decl->isOutermostPrivateOrFilePrivateScope() &&
2585+
!isa<ClangModuleUnit>(
2586+
Decl->getDeclContext()->getModuleScopeContext()))
25822587
Scope = getFilePrivateScope(Scope, Decl);
25832588

25842589
return Scope;

test/Interop/Cxx/class/access/private-fileid-irgen.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//--- blessed.swift
22
// RUN: split-file %s %t
33
// RUN: %target-swift-frontend -emit-ir -module-name main %t/blessed.swift -I %S/Inputs -cxx-interoperability-mode=default -Onone | %FileCheck %s
4+
// RUN: %target-swift-frontend -emit-ir -module-name main %t/blessed.swift -I %S/Inputs -cxx-interoperability-mode=default -Onone -g | %FileCheck %s
45

56
import NonPublic
67

0 commit comments

Comments
 (0)