]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: Fix ICE in dwarf2out_abstract_function, at dwarf2out.cc:23771 [PR123263]
authorIain Buclaw <ibuclaw@gdcproject.org>
Fri, 30 Jan 2026 07:14:34 +0000 (08:14 +0100)
committerIain Buclaw <ibuclaw@gdcproject.org>
Fri, 30 Jan 2026 07:31:12 +0000 (08:31 +0100)
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.

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
gcc/testsuite/gdc.dg/debug/pr123263.d [new file with mode: 0644]

index 3ff3d0628ab97d25339ac654e9758f7ec8b64942..02023496cfa1dd9af5aa9d89132eacce1f215c9a 100644 (file)
@@ -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 (file)
index 0000000..e23d9d4
--- /dev/null
@@ -0,0 +1,10 @@
+// { dg-do compile }
+void pr123263()
+{
+    struct UDA(T)
+    {
+        string name;
+        T value;
+    }
+    @UDA!string() int k;
+}