<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Oct 16, 2013 at 6:31 PM, Eric Christopher <span dir="ltr"><<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: echristo<br>
Date: Wed Oct 16 20:31:21 2013<br>
New Revision: 192862<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=192862&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=192862&view=rev</a><br>
Log:<br>
Add the context that a function was created in as the context for the<br>
function, not the context of the context.<br>
<br>
Added:<br>
    cfe/trunk/test/CodeGenCXX/debug-info-function-context.cpp<br>
Modified:<br>
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=192862&r1=192861&r2=192862&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=192862&r1=192861&r2=192862&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Oct 16 20:31:21 2013<br>
@@ -2475,11 +2475,11 @@ void CGDebugInfo::EmitFunctionStart(Glob<br>
<br>
     if (DebugKind >= CodeGenOptions::LimitedDebugInfo) {<br>
       if (const NamespaceDecl *NSDecl =<br>
-          dyn_cast_or_null<NamespaceDecl>(FD->getDeclContext()))<br>
+              dyn_cast_or_null<NamespaceDecl>(FD->getDeclContext()))<br>
         FDContext = getOrCreateNameSpace(NSDecl);<br>
       else if (const RecordDecl *RDecl =<br>
-               dyn_cast_or_null<RecordDecl>(FD->getDeclContext()))<br>
-        FDContext = getContextDescriptor(cast<Decl>(RDecl->getDeclContext()));<br>
+                   dyn_cast_or_null<RecordDecl>(FD->getDeclContext()))<br>
+        FDContext = getContextDescriptor(cast<Decl>(RDecl));<br>
<br>
       // Collect template parameters.<br>
       TParamsArray = CollectFunctionTemplateParams(FD, Unit);<br>
@@ -2499,11 +2499,13 @@ void CGDebugInfo::EmitFunctionStart(Glob<br>
   if (!HasDecl || D->isImplicit())<br>
     Flags |= llvm::DIDescriptor::FlagArtificial;<br>
<br>
-  llvm::DISubprogram SP = DBuilder.createFunction(<br>
-      FDContext, Name, LinkageName, Unit, LineNo,<br>
-      getOrCreateFunctionType(D, FnType, Unit), Fn->hasInternalLinkage(),<br>
-      true /*definition*/, getLineNumber(CurLoc), Flags,<br>
-      CGM.getLangOpts().Optimize, Fn, TParamsArray, getFunctionDeclaration(D));<br>
+  llvm::DISubprogram SP =<br>
+      DBuilder.createFunction(FDContext, Name, LinkageName, Unit, LineNo,<br>
+                              getOrCreateFunctionType(D, FnType, Unit),<br>
+                              Fn->hasInternalLinkage(), true /*definition*/,<br>
+                              getLineNumber(CurLoc), Flags,<br>
+                              CGM.getLangOpts().Optimize, Fn, TParamsArray,<br>
+                              getFunctionDeclaration(D));<br>
   if (HasDecl)<br>
     DeclCache.insert(std::make_pair(D->getCanonicalDecl(), llvm::WeakVH(SP)));<br>
<br>
<br>
Added: cfe/trunk/test/CodeGenCXX/debug-info-function-context.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-function-context.cpp?rev=192862&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-function-context.cpp?rev=192862&view=auto</a><br>

==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/debug-info-function-context.cpp (added)<br>
+++ cfe/trunk/test/CodeGenCXX/debug-info-function-context.cpp Wed Oct 16 20:31:21 2013<br>
@@ -0,0 +1,36 @@<br>
+// RUN: %clang_cc1 -emit-llvm -g -triple x86_64-pc-linux-gnu %s -o - | FileCheck %s<br>
+<br>
+struct C {<br>
+  void member_function();<br>
+  static int static_member_function();<br>
+  static int static_member_variable;<br>
+};<br>
+<br>
+int C::static_member_variable = 0;<br>
+<br>
+void C::member_function() { static_member_variable = 0; }<br>
+<br>
+int C::static_member_function() { return static_member_variable; }<br>
+<br>
+C global_variable;<br>
+<br>
+int global_function() { return -1; }<br>
+<br>
+namespace ns {<br>
+void global_namespace_function() { global_variable.member_function(); }<br>
+int global_namespace_variable = 1;<br>
+}<br>
+<br>
+// Check that the functions that belong to C have C as a context and the<br>
+// functions that belong to the namespace have it as a context, and the global<br>
+// function has the file as a context.<br></blockquote><div><br></div><div>Is this right, though? In the actual DWARF the parent of a member function definition is generally not the type itself - the definitions are out of line (so the parent is usually the CU, I guess?), aren't they? Is this change going to cause these definitions to end up as children of the type DIE?</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+// CHECK: metadata !"_ZTS1C", metadata !"member_function"{{.*}} [ DW_TAG_subprogram ] [line 11] [def] [member_function]<br>
+<br>
+// CHECK: metadata !"_ZTS1C", metadata !"static_member_function"{{.*}}  [ DW_TAG_subprogram ] [line 13] [def] [static_member_function]<br>
+<br>
+// CHECK: metadata !22, metadata !"global_function"{{.*}}  [ DW_TAG_subprogram ] [line 17] [def] [global_function]<br>
+// CHECK: !22 = {{.*}} [ DW_TAG_file_type ]<br>
+<br>
+// CHECK: metadata !24, metadata !"global_namespace_function"{{.*}} [ DW_TAG_subprogram ] [line 20] [def] [global_namespace_function]<br>
+// CHECK: !24 = {{.*}} [ DW_TAG_namespace ] [ns] [line 19]<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>