@@ -303,13 +303,15 @@ std::optional<codeql::ModuleDecl> DeclTranslator::translateModuleDecl(
303
303
}
304
304
305
305
std::string DeclTranslator::mangledName (const swift::ValueDecl& decl) {
306
+ std::string_view moduleName = decl.getModuleContext ()->getRealName ().str ();
306
307
// ASTMangler::mangleAnyDecl crashes when called on `ModuleDecl`
307
- // TODO find a more unique string working also when different modules are compiled with the same
308
- // name
309
- std::ostringstream ret;
310
308
if (decl.getKind () == swift::DeclKind::Module) {
311
- ret << static_cast <const swift::ModuleDecl&>(decl).getRealName ().str ().str ();
312
- } else if (decl.getKind () == swift::DeclKind::TypeAlias) {
309
+ return std::string{moduleName};
310
+ }
311
+ std::ostringstream ret;
312
+ // stamp all declarations with an id-ref of the containing module
313
+ ret << ' {' << ModuleDeclTag::prefix << ' _' << moduleName << ' }' ;
314
+ if (decl.getKind () == swift::DeclKind::TypeAlias) {
313
315
// In cases like this (when coming from PCM)
314
316
// typealias CFXMLTree = CFTree
315
317
// typealias CFXMLTreeRef = CFXMLTree
@@ -321,14 +323,6 @@ std::string DeclTranslator::mangledName(const swift::ValueDecl& decl) {
321
323
// prefix adds a couple of special symbols, we don't necessary need them
322
324
ret << mangler.mangleAnyDecl (&decl, /* prefix = */ false );
323
325
}
324
- // there can be separate declarations (`VarDecl` or `AccessorDecl`) which are effectively the same
325
- // (with equal mangled name) but come from different clang modules. This is the case for example
326
- // for glibc constants like `L_SET` that appear in both `SwiftGlibc` and `CDispatch`.
327
- // For the moment, we sidestep the problem by making them separate entities in the DB
328
- // TODO find a more solid solution
329
- if (decl.getModuleContext ()->isNonSwiftModule ()) {
330
- ret << ' _' << decl.getModuleContext ()->getRealName ().str ().str ();
331
- }
332
326
return ret.str ();
333
327
}
334
328
0 commit comments