Hi,

This patch fixes PR123263.

Emit artificial functions as being part of the module context, so that
they are unaffected by dwarf early_finish pass removing the parent type
that they were generated for.

Regstrapped on x86_64-linux-gnu, committed to mainline.

Regards,
Iain.

---
        PR d/123263

gcc/d/ChangeLog:

        * d-codegen.cc (d_decl_context): Set DECL_CONTEXT of compiler
        generated functions to that of parent module.

gcc/testsuite/ChangeLog:

        * gdc.dg/debug/pr123263.d: New test.
---
 gcc/d/d-codegen.cc                    | 18 +++++++++++-------
 gcc/testsuite/gdc.dg/debug/pr123263.d | 10 ++++++++++
 2 files changed, 21 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/debug/pr123263.d

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 3ff3d0628ab..02023496cfa 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -78,6 +78,7 @@ d_decl_context (Dsymbol *dsym)
   Dsymbol *parent = dsym;
   Declaration *decl = dsym->isDeclaration ();
   AggregateDeclaration *ad = dsym->isAggregateDeclaration ();
+  FuncDeclaration *fd = dsym->isFuncDeclaration ();
 
   while ((parent = parent->toParent2 ()))
     {
@@ -98,18 +99,21 @@ d_decl_context (Dsymbol *dsym)
       if (decl != NULL && decl->isDataseg ())
        continue;
 
+      /* Likewise generated functions are part of module context.  */
+      if (fd != NULL && fd->isGenerated ()
+         && !(fd->isVirtual () && fd->vtblIndex != -1))
+       continue;
+
       /* Nested functions.  */
-      FuncDeclaration *fd = parent->isFuncDeclaration ();
-      if (fd != NULL)
-       return get_symbol_decl (fd);
+      if (FuncDeclaration *fdp = parent->isFuncDeclaration ())
+       return get_symbol_decl (fdp);
 
       /* Methods of classes or structs.  */
-      AggregateDeclaration *ad = parent->isAggregateDeclaration ();
-      if (ad != NULL)
+      if (AggregateDeclaration *adp = parent->isAggregateDeclaration ())
        {
-         tree context = build_ctype (ad->type);
+         tree context = build_ctype (adp->type);
          /* Want the underlying RECORD_TYPE.  */
-         if (ad->isClassDeclaration ())
+         if (adp->isClassDeclaration ())
            context = TREE_TYPE (context);
 
          return context;
diff --git a/gcc/testsuite/gdc.dg/debug/pr123263.d 
b/gcc/testsuite/gdc.dg/debug/pr123263.d
new file mode 100644
index 00000000000..e23d9d41205
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/pr123263.d
@@ -0,0 +1,10 @@
+// { dg-do compile }
+void pr123263()
+{
+    struct UDA(T)
+    {
+        string name;
+        T value;
+    }
+    @UDA!string() int k;
+}
-- 
2.43.0

Reply via email to