Skip to content

Commit e6a3905

Browse files
committed
Mangling: treat C++ namespaces as enums
C++ namespaces are imported as Swift enums, so let's mangle them as enums. This fixes lookup of nested namespaces, for example, `std.__1`: previously during demangling the `__1` decl was filtered out in `ASTBuilder::getAcceptableTypeDeclCandidate` as it expects `Demangle::Node::Kind::Structure` instead of `Demangle::Node::Kind::Enum`. This caused "Failed to reconstruct type for x" error.
1 parent 0b31642 commit e6a3905

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,9 +2303,9 @@ void ASTMangler::appendAnyGenericType(const GenericTypeDecl *decl) {
23032303
isa<clang::ObjCCompatibleAliasDecl>(namedDecl)) {
23042304
appendOperator("a");
23052305
} else if (isa<clang::NamespaceDecl>(namedDecl)) {
2306-
// Note: Namespaces are not really structs, but since namespaces are
2306+
// Note: Namespaces are not really enums, but since namespaces are
23072307
// imported as enums, be consistent.
2308-
appendOperator("V");
2308+
appendOperator("O");
23092309
} else {
23102310
llvm_unreachable("unknown imported Clang type");
23112311
}

test/ClangImporter/cxx_interop_ir.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ func indirectUsage() {
99
useT(makeT())
1010
}
1111

12-
// CHECK-LABEL: define hidden swiftcc %swift.type* @"$s6cxx_ir14reflectionInfo3argypXpSo2nsV10CXXInteropE1TV_tF"
13-
// CHECK: %0 = call swiftcc %swift.metadata_response @"$sSo2nsV10CXXInteropE1TVMa"({{i64|i32}} 0)
12+
// CHECK-LABEL: define hidden swiftcc %swift.type* @"$s6cxx_ir14reflectionInfo3argypXpSo2nsO10CXXInteropE1TV_tF"
13+
// CHECK: %0 = call swiftcc %swift.metadata_response @"$sSo2nsO10CXXInteropE1TVMa"({{i64|i32}} 0)
1414
func reflectionInfo(arg: namespacedT) -> Any.Type {
1515
return type(of: arg)
1616
}
1717

18-
// CHECK: define hidden swiftcc void @"$s6cxx_ir24namespaceManglesIntoName3argySo2nsV10CXXInteropE1TV_tF"
18+
// CHECK: define hidden swiftcc void @"$s6cxx_ir24namespaceManglesIntoName3argySo2nsO10CXXInteropE1TV_tF"
1919
func namespaceManglesIntoName(arg: namespacedT) {
2020
}
2121

22-
// CHECK: define hidden swiftcc void @"$s6cxx_ir42namespaceManglesIntoNameForUsingShadowDecl3argySo2nsV10CXXInteropE14NamespacedTypeV_tF"
22+
// CHECK: define hidden swiftcc void @"$s6cxx_ir42namespaceManglesIntoNameForUsingShadowDecl3argySo2nsO10CXXInteropE14NamespacedTypeV_tF"
2323
func namespaceManglesIntoNameForUsingShadowDecl(arg: NamespacedType) {
2424
}
2525

0 commit comments

Comments
 (0)