@@ -295,19 +295,30 @@ std::string DeclVisitor::mangledName(const swift::ValueDecl& decl) {
295295 // ASTMangler::mangleAnyDecl crashes when called on `ModuleDecl`
296296 // TODO find a more unique string working also when different modules are compiled with the same
297297 // name
298+ std::ostringstream ret;
298299 if (decl.getKind () == swift::DeclKind::Module) {
299- return static_cast <const swift::ModuleDecl&>(decl).getRealName ().str ().str ();
300+ ret << static_cast <const swift::ModuleDecl&>(decl).getRealName ().str ().str ();
301+ } else if (decl.getKind () == swift::DeclKind::TypeAlias) {
302+ // In cases like this (when coming from PCM)
303+ // typealias CFXMLTree = CFTree
304+ // typealias CFXMLTreeRef = CFXMLTree
305+ // mangleAnyDecl mangles both CFXMLTree and CFXMLTreeRef into 'So12CFXMLTreeRefa'
306+ // which is not correct and causes inconsistencies. mangleEntity makes these two distinct
307+ // prefix adds a couple of special symbols, we don't necessary need them
308+ ret << mangler.mangleEntity (&decl);
309+ } else {
310+ // prefix adds a couple of special symbols, we don't necessary need them
311+ ret << mangler.mangleAnyDecl (&decl, /* prefix = */ false );
300312 }
301- // In cases like this (when coming from PCM)
302- // typealias CFXMLTree = CFTree
303- // typealias CFXMLTreeRef = CFXMLTree
304- // mangleAnyDecl mangles both CFXMLTree and CFXMLTreeRef into 'So12CFXMLTreeRefa'
305- // which is not correct and causes inconsistencies. mangleEntity makes these two distinct
306- if (decl.getKind () == swift::DeclKind::TypeAlias ) {
307- return mangler. mangleEntity (&decl );
313+ // there can be separate declarations (`VarDecl` or `AccessorDecl`) which are effectively the same
314+ // (with equal mangled name) but come from different clang modules. This is the case for example
315+ // for glibc constants like `L_SET` that appear in both `SwiftGlibc` and `CDispatch`.
316+ // For the moment, we sidestep the problem by making them separate entities in the DB
317+ // TODO find a more solid solution
318+ if (decl.getModuleContext ()-> isNonSwiftModule () ) {
319+ ret << ' _ ' << decl. getModuleContext ()-> getRealName (). str (). str ( );
308320 }
309- // prefix adds a couple of special symbols, we don't necessary need them
310- return mangler.mangleAnyDecl (&decl, /* prefix = */ false );
321+ return ret.str ();
311322}
312323
313324void DeclVisitor::fillAbstractFunctionDecl (const swift::AbstractFunctionDecl& decl,
0 commit comments