Skip to content

[SerializeDoc] Don't crash in module-merging with a group info file #27867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/Serialization/SerializeDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,16 @@ class DeclGroupNameContext {
// We need the file path, so there has to be a location.
if (VD->getLoc().isInvalid())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VD->getLoc(false) works too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah. I guess I'll leave it this way because eventually we'll want group info to work in non-single-frontend mode anyway.

return 0;
StringRef FullPath =
VD->getDeclContext()->getParentSourceFile()->getFilename();

// If the decl being serialized isn't actually from a source file, don't
// put it in a group.
// FIXME: How do we preserve group information through partial module
// merging for multi-frontend builds, then?
SourceFile *SF = VD->getDeclContext()->getParentSourceFile();
if (!SF)
return 0;

StringRef FullPath = SF->getFilename();
if (FullPath.empty())
return 0;
StringRef FileName = llvm::sys::path::filename(FullPath);
Expand Down
10 changes: 10 additions & 0 deletions test/SourceKit/InterfaceGen/gen_module_group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@
// RUN: %sourcekitd-test -req=interface-gen -module MyModule -group-name A -- -I %t.mod -target %target-triple | %FileCheck -check-prefix=GROUPA %s
// RUN: %sourcekitd-test -req=interface-gen -module MyModule -group-name B -- -I %t.mod -target %target-triple | %FileCheck -check-prefix=GROUPB %s

// FIXME: We don't currently handle group info for multi-file builds,
// so just make sure we don't crash.
// RUN: %empty-directory(%t.multifrontend)
// 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
// RUN: %sourcekitd-test -req=interface-gen -module MyModule -group-name A -- -I %t.multifrontend -target %target-triple | %FileCheck -check-prefix=EMPTY %s

// GROUPA: MyClass
// GROUPA-NOT: P1
// GROUPA-NOT: P2

// GROUPB: P1
// GROUPB: P2
// GROUPB-NOT: MyClass

// EMPTY-NOT: P1
// EMPTY-NOT: P2
// EMPTY-NOT: MyClass