Skip to content

Commit 4e7fb73

Browse files
committed
Provide the buffer ID for source files created for C swift_attr attributes
When rendering a swift_attr attribute for parsing, we were creating both the backing buffer and a source file, but not providing the buffer's ID to the source file, so we couldn't find the source code again. Fix that. While here, also register the source file with the module, so we can find the source file again based on location.
1 parent e916e9e commit 4e7fb73

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8063,14 +8063,18 @@ unsigned ClangImporter::Implementation::getClangSwiftAttrSourceBuffer(
80638063
}
80648064

80658065
SourceFile &ClangImporter::Implementation::getClangSwiftAttrSourceFile(
8066-
ModuleDecl &module) {
8066+
ModuleDecl &module, unsigned bufferID) {
80678067
auto known = ClangSwiftAttrSourceFiles.find(&module);
80688068
if (known != ClangSwiftAttrSourceFiles.end())
80698069
return *known->second;
80708070

80718071
auto sourceFile = new (SwiftContext)
8072-
SourceFile(module, SourceFileKind::Library, std::nullopt);
8072+
SourceFile(module, SourceFileKind::Library, bufferID);
80738073
ClangSwiftAttrSourceFiles.insert({&module, sourceFile});
8074+
8075+
// Record this attribute in the module.
8076+
module.addAuxiliaryFile(*sourceFile);
8077+
80748078
return *sourceFile;
80758079
}
80768080

@@ -8228,7 +8232,7 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
82288232

82298233
// Dig out a source file we can use for parsing.
82308234
auto &sourceFile = getClangSwiftAttrSourceFile(
8231-
*MappedDecl->getDeclContext()->getParentModule());
8235+
*MappedDecl->getDeclContext()->getParentModule(), bufferID);
82328236

82338237
// Spin up a parser.
82348238
swift::Parser parser(

lib/ClangImporter/ImporterImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
10621062

10631063
/// Retrieve the placeholder source file for use in parsing Swift attributes
10641064
/// in the given module.
1065-
SourceFile &getClangSwiftAttrSourceFile(ModuleDecl &module);
1065+
SourceFile &getClangSwiftAttrSourceFile(ModuleDecl &module, unsigned bufferID);
10661066

10671067
/// Utility function to import Clang attributes from a source Swift decl to
10681068
/// synthesized Swift decl.

0 commit comments

Comments
 (0)