@@ -1075,12 +1075,11 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
10751075 CanonicalName.clear ();
10761076 }
10771077
1078- bool IsTypeOriginallyDefinedIn =
1079- containsOriginallyDefinedIn (DbgTy.getType ());
1080- // TODO(https://github.com/apple/swift/issues/57699): We currently cannot round trip some C++ types.
1078+ bool IsTypeOriginallyDefinedIn = containsOriginallyDefinedIn (DbgTy.getType ());
1079+ bool IsCxxType = containsCxxType (DbgTy.getType ());
10811080 // There's no way to round trip when respecting @_originallyDefinedIn for a type.
1082- if (!Opts. DisableRoundTripDebugTypes &&
1083- !Ty-> getASTContext (). LangOpts . EnableCXXInterop && !IsTypeOriginallyDefinedIn) {
1081+ // TODO(https://github.com/apple/swift/issues/57699): We currently cannot round trip some C++ types.
1082+ if (!Opts. DisableRoundTripDebugTypes && !IsTypeOriginallyDefinedIn && !IsCxxType ) {
10841083 // Make sure we can reconstruct mangled types for the debugger.
10851084 auto &Ctx = Ty->getASTContext ();
10861085 Type Reconstructed = Demangle::getTypeForMangling (Ctx, SugaredName, Sig);
@@ -2504,6 +2503,42 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
25042503 return Walker.visitedOriginallyDefinedIn ;
25052504 }
25062505
2506+ // / Returns true if the type contains an imported C++ type. Due to
2507+ // / various unimplemented features these cannot round-trip through
2508+ // / the ASTDemangler.
2509+ // /
2510+ // / FIXME: Get these cases working with the ASTDemangler instead.
2511+ bool containsCxxType (Type T) {
2512+ return T.findIf ([&](Type t) -> bool {
2513+ if (auto *decl = t->getAnyNominal ()) {
2514+ if (auto *clangDecl = decl->getClangDecl ()) {
2515+ // Lookup of template instantiations is not implemented.
2516+ if (isa<clang::ClassTemplateSpecializationDecl>(clangDecl))
2517+ return true ;
2518+
2519+ // Lookup of types in weird contexts is not implemented.
2520+ if (isa<clang::EnumDecl>(clangDecl) ||
2521+ isa<clang::CXXRecordDecl>(clangDecl)) {
2522+ auto *dc = clangDecl->getDeclContext ();
2523+ while (!isa<clang::TranslationUnitDecl>(dc)) {
2524+ // ... in namespaces,
2525+ if (isa<clang::NamespaceDecl>(dc))
2526+ return true ;
2527+
2528+ // ... or inside other types.
2529+ if (isa<clang::CXXRecordDecl>(dc))
2530+ return true ;
2531+
2532+ dc = dc->getParent ();
2533+ }
2534+ }
2535+ }
2536+ }
2537+
2538+ return false ;
2539+ });
2540+ }
2541+
25072542 // / Returns the decl of the type's parent chain annotated by
25082543 // / @_originallyDefinedIn. Returns null if no type is annotated.
25092544 NominalTypeDecl *getDeclAnnotatedByOriginallyDefinedIn (DebugTypeInfo DbgTy) {
0 commit comments