Skip to content

Commit d8d18d3

Browse files
authored
[SerializeDoc] Don't crash in module-merging with a group info file (#27867)
Group info works by matching source filenames with groups, but in module merging the decls in the module no longer have associated SourceFiles. Long-term, maybe we should switch this to working on filenames directly (using the new support provided by swiftsourceinfo files), but for now just don't crash. rdar://problem/56592085
1 parent 6d178e8 commit d8d18d3

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/Serialization/SerializeDoc.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,16 @@ class DeclGroupNameContext {
153153
// We need the file path, so there has to be a location.
154154
if (VD->getLoc().isInvalid())
155155
return 0;
156-
StringRef FullPath =
157-
VD->getDeclContext()->getParentSourceFile()->getFilename();
156+
157+
// If the decl being serialized isn't actually from a source file, don't
158+
// put it in a group.
159+
// FIXME: How do we preserve group information through partial module
160+
// merging for multi-frontend builds, then?
161+
SourceFile *SF = VD->getDeclContext()->getParentSourceFile();
162+
if (!SF)
163+
return 0;
164+
165+
StringRef FullPath = SF->getFilename();
158166
if (FullPath.empty())
159167
return 0;
160168
StringRef FileName = llvm::sys::path::filename(FullPath);

test/SourceKit/InterfaceGen/gen_module_group.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33
// RUN: %sourcekitd-test -req=interface-gen -module MyModule -group-name A -- -I %t.mod -target %target-triple | %FileCheck -check-prefix=GROUPA %s
44
// RUN: %sourcekitd-test -req=interface-gen -module MyModule -group-name B -- -I %t.mod -target %target-triple | %FileCheck -check-prefix=GROUPB %s
55

6+
// FIXME: We don't currently handle group info for multi-file builds,
7+
// so just make sure we don't crash.
8+
// RUN: %empty-directory(%t.multifrontend)
9+
// RUN: %target-build-swift -module-name MyModule -emit-module -emit-module-path %t.multifrontend/MyModule.swiftmodule -Xfrontend -group-info-path -Xfrontend %S/Inputs/group.json %S/Inputs/swift_mod.swift %S/Inputs/swift_mod_syn.swift
10+
// RUN: %sourcekitd-test -req=interface-gen -module MyModule -group-name A -- -I %t.multifrontend -target %target-triple | %FileCheck -check-prefix=EMPTY %s
11+
612
// GROUPA: MyClass
713
// GROUPA-NOT: P1
814
// GROUPA-NOT: P2
915

1016
// GROUPB: P1
1117
// GROUPB: P2
1218
// GROUPB-NOT: MyClass
19+
20+
// EMPTY-NOT: P1
21+
// EMPTY-NOT: P2
22+
// EMPTY-NOT: MyClass

0 commit comments

Comments
 (0)