Skip to content

Commit 6fa2daf

Browse files
committed
[cxx-interop] Do not crash when importing anonymous classes
This was discovered during interop adoption in SwiftCompilerSources. ``` /Volumes/Projects/swift/swift/include/swift/SIL/SILNode.h:180:5 <Spelling=/Volumes/Projects/swift/swift/include/swift/SIL/SILNode.h:171:3>: while adding SwiftName lookup table entries for clang declaration 'swift::SILNode::SharedUInt8Fields::(anonymous)' ```
1 parent a39c78b commit 6fa2daf

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

lib/ClangImporter/ImportName.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,8 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
17681768
const char *kind;
17691769
if (fieldTagDecl->isStruct())
17701770
kind = "struct";
1771+
else if (fieldTagDecl->isClass())
1772+
kind = "class";
17711773
else if (fieldTagDecl->isUnion())
17721774
kind = "union";
17731775
else if (fieldTagDecl->isEnum())

test/Interop/Cxx/class/Inputs/linked-records.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,11 @@ struct F {
3636
M m2;
3737
};
3838

39+
struct G {
40+
class {
41+
public:
42+
M m;
43+
} cc;
44+
};
45+
3946
#endif // TEST_INTEROP_CXX_CLASS_INPUTS_LINKED_RECORDS_H

test/Interop/Cxx/class/linked-records-module-interface.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,14 @@
4141
// CHECK: var m: M
4242
// CHECK: var m2: M
4343
// CHECK: }
44+
45+
// CHECK: struct G {
46+
// CHECK: init()
47+
// CHECK: init(cc: G.__Unnamed_class_cc)
48+
// CHECK: struct __Unnamed_class_cc {
49+
// CHECK: init()
50+
// CHECK: init(m: M)
51+
// CHECK: var m: M
52+
// CHECK: }
53+
// CHECK: var cc: G.__Unnamed_class_cc
54+
// CHECK: }

0 commit comments

Comments
 (0)