Ensure that #fileID wraps raw identifier module names in backticks.

`#fileID` never accounted for the possibility that someone one have
a module alias _itself_, so it always generated the module's real
(physical) name. This _technically_ changes the behavior of `#fileID`
for self-aliased modules, but since nobody would have ever had a reason
to do that before raw identifiers, it's unlikely that this change would
affect anyone in practice.
This commit is contained in:
Tony Allevato
2025-01-06 12:51:17 -05:00
parent 8752920875
commit 0844e274b0
2 changed files with 22 additions and 1 deletions

View File

@@ -3333,7 +3333,19 @@ getInfoForUsedFileNames(const ModuleDecl *module) {
static void computeFileID(const ModuleDecl *module, StringRef name,
SmallVectorImpl<char> &result) {
result.assign(module->getNameStr().begin(), module->getNameStr().end());
// The module might alias itself (e.g., to use a raw identifier as the name
// that it references itself with in its own source code), so we need to look
// that up.
Identifier moduleName = module->getASTContext().getRealModuleName(
module->getName(),
ASTContext::ModuleAliasLookupOption::aliasFromRealName);
if (moduleName.mustAlwaysBeEscaped()) {
result.push_back('`');
result.append(moduleName.str().begin(), moduleName.str().end());
result.push_back('`');
} else {
result.assign(moduleName.str().begin(), moduleName.str().end());
}
result.push_back('/');
result.append(name.begin(), name.end());
}