Skip to content

[ClangImporter] don't add swift_attr files to a module's auxiliary files #65867

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 4 commits into from
May 17, 2023

Conversation

QuietMisdreavus
Copy link
Contributor

Resolves rdar://107624995

The source-file location map used to determine which source files correspond to which locations assumes that all the source files used in the comparison have backing buffers. This holds for regular library files and macro expansions, but when Objective-C code with __attribute__((swift_attr)) attributes is imported, the attributes get a fake source file with no backing buffer added to the module's auxiliary files.

When SourceEntityWalker tries to determine whether a source location corresponds to a macro expansion, it uses this file map to look up a corresponding source file. When a module contains imported Objective-C code with swift_attr attributes as well as a Swift extension of that type, an empty optional containing the file's buffer ID is unwrapped, causing a crash. This is consistently triggered by SymbolGraphGen, as it is one of the major users of SourceEntityWalker.

This PR updates the source-file location map to skip auxiliary files that don't have a backing buffer, the same as the module's regular files.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

for (auto *sourceFile : AuxiliaryFiles)
sourceFileLocationMap->allSourceFiles.push_back(sourceFile);
for (auto *sourceFile : AuxiliaryFiles) {
if (sourceFile->getBufferID())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only use of AuxiliaryFiles and in general it doesn't really make sense to me to have an auxiliary file without a backing buffer. IMO we should just not add the auxiliary file in getClangSwiftAttrSourceFile.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus QuietMisdreavus changed the title don't use files without a backing buffer for location checks [ClangImporter] don't add swift_attr files to a module's auxiliary files May 12, 2023
@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please clean test macOS

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test Linux

@QuietMisdreavus QuietMisdreavus merged commit 34faa58 into main May 17, 2023
@QuietMisdreavus QuietMisdreavus deleted the QuietMisdreavus/swift-attr-extension branch May 17, 2023 15:10
QuietMisdreavus added a commit that referenced this pull request May 17, 2023
meg-gupta pushed a commit to meg-gupta/swift that referenced this pull request May 22, 2023
NuriAmari pushed a commit to NuriAmari/swift that referenced this pull request May 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants