From: Devang Patel Date: Mon, 11 Oct 2010 21:58:41 +0000 (+0000) Subject: Fix debug info for functions whose context is a namespace. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0692f838794fc8d2d5692dd31209af891c40ebf1;p=clang Fix debug info for functions whose context is a namespace. This is tested by namespace.exp in gdb testsuite. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116248 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 8764babd63..f3a3420c5a 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -1529,6 +1529,8 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, const Decl *D = GD.getDecl(); unsigned Flags = 0; + llvm::DIFile Unit = getOrCreateFile(CurLoc); + llvm::DIDescriptor FDContext(Unit); if (const FunctionDecl *FD = dyn_cast(D)) { // If there is a DISubprogram for this function available then use it. llvm::DenseMap::iterator @@ -1547,6 +1549,9 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, LinkageName = CGM.getMangledName(GD); if (FD->hasPrototype()) Flags |= llvm::DIDescriptor::FlagPrototyped; + if (const NamespaceDecl *NSDecl = + dyn_cast_or_null(FD->getDeclContext())) + FDContext = getOrCreateNameSpace(NSDecl, Unit); } else if (const ObjCMethodDecl *OMD = dyn_cast(D)) { Name = getObjCMethodName(OMD); LinkageName = Name; @@ -1563,12 +1568,11 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, // It is expected that CurLoc is set before using EmitFunctionStart. // Usually, CurLoc points to the left bracket location of compound // statement representing function body. - llvm::DIFile Unit = getOrCreateFile(CurLoc); unsigned LineNo = getLineNumber(CurLoc); if (D->isImplicit()) Flags |= llvm::DIDescriptor::FlagArtificial; llvm::DISubprogram SP = - DebugFactory.CreateSubprogram(Unit, Name, Name, LinkageName, Unit, LineNo, + DebugFactory.CreateSubprogram(FDContext, Name, Name, LinkageName, Unit, LineNo, getOrCreateType(FnType, Unit), Fn->hasInternalLinkage(), true/*definition*/, 0, 0, llvm::DIType(),