}
// Check namespace.
- if (const auto *NSDecl = dyn_cast<NamespaceDecl>(Context)) {
- auto *ParentModule = dyn_cast<llvm::DIModule>(Default);
- return getOrCreateNamespace(NSDecl, ParentModule);
- }
+ if (const auto *NSDecl = dyn_cast<NamespaceDecl>(Context))
+ return getOrCreateNamespace(NSDecl);
if (const auto *RDecl = dyn_cast<RecordDecl>(Context))
if (!RDecl->isDependentType())
if (DebugKind >= codegenoptions::LimitedDebugInfo) {
if (const NamespaceDecl *NSDecl =
- dyn_cast_or_null<NamespaceDecl>(FD->getDeclContext()))
- FDContext = getOrCreateNamespace(NSDecl, getParentModuleOrNull(FD));
+ dyn_cast_or_null<NamespaceDecl>(FD->getLexicalDeclContext()))
+ FDContext = getOrCreateNamespace(NSDecl);
else if (const RecordDecl *RDecl =
dyn_cast_or_null<RecordDecl>(FD->getDeclContext())) {
llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
CGM.getCodeGenOpts().DebugExplicitImport) {
DBuilder.createImportedModule(
getCurrentContextDescriptor(cast<Decl>(UD.getDeclContext())),
- getOrCreateNamespace(NSDecl, getParentModuleOrNull(&UD)),
+ getOrCreateNamespace(NSDecl),
getLineNumber(UD.getLocation()));
}
}
else
R = DBuilder.createImportedDeclaration(
getCurrentContextDescriptor(cast<Decl>(NA.getDeclContext())),
- getOrCreateNamespace(cast<NamespaceDecl>(NA.getAliasedNamespace()),
- getParentModuleOrNull(&NA)),
+ getOrCreateNamespace(cast<NamespaceDecl>(NA.getAliasedNamespace())),
getLineNumber(NA.getLocation()), NA.getName());
VH.reset(R);
return R;
}
llvm::DINamespace *
-CGDebugInfo::getOrCreateNamespace(const NamespaceDecl *NSDecl,
- llvm::DIModule *ParentModule) {
- NSDecl = NSDecl->getCanonicalDecl();
- // The AST merges NamespaceDecls, but for module debug info it is important to
- // put a namespace decl (or rather its children) into the correct
- // (sub-)module, so use the parent module of the decl that triggered this
- // namespace to be serialized as a second key.
- NamespaceKey Key = {NSDecl, ParentModule};
- auto I = NamespaceCache.find(Key);
+CGDebugInfo::getOrCreateNamespace(const NamespaceDecl *NSDecl) {
+ // Don't canonicalize the NamespaceDecl here: The DINamespace will be uniqued
+ // if necessary, and this way multiple declarations of the same namespace in
+ // different parent modules stay distinct.
+ auto I = NamespaceCache.find(NSDecl);
if (I != NamespaceCache.end())
return cast<llvm::DINamespace>(I->second);
llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
// Don't trust the context if it is a DIModule (see comment above).
- llvm::DINamespace *NS = DBuilder.createNameSpace(
- isa<llvm::DIModule>(Context) ? ParentModule : Context, NSDecl->getName(),
- NSDecl->isInline());
- NamespaceCache[Key].reset(NS);
+ llvm::DINamespace *NS =
+ DBuilder.createNameSpace(Context, NSDecl->getName(), NSDecl->isInline());
+ NamespaceCache[NSDecl].reset(NS);
return NS;
}
/// Cache declarations relevant to DW_TAG_imported_declarations (C++
/// using declarations) that aren't covered by other more specific caches.
llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
- typedef std::pair<const NamespaceDecl *, const llvm::DIModule *> NamespaceKey;
- llvm::DenseMap<NamespaceKey, llvm::TrackingMDRef> NamespaceCache;
+ llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NamespaceCache;
llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
NamespaceAliasCache;
llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIDerivedType>>
llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
/// \return namespace descriptor for the given namespace decl.
- ///
- /// \return namespace descriptor for the given namespace decl.
- /// \param ParentModule The parent module (or nullptr) of this particular
- /// namespace decl. This needs to be passed in because
- /// the AST merges namespace decls.
- llvm::DINamespace *getOrCreateNamespace(const NamespaceDecl *N,
- llvm::DIModule *ParentModule);
+ llvm::DINamespace *getOrCreateNamespace(const NamespaceDecl *N);
llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag, const Type *Ty,
QualType PointeeTy, llvm::DIFile *F);
llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&Cache);