https://gcc.gnu.org/g:9f0f81c5150284374adbb0c738cff4840c9921db
commit r16-7170-g9f0f81c5150284374adbb0c738cff4840c9921db Author: Iain Buclaw <[email protected]> Date: Fri Jan 30 08:14:34 2026 +0100 d: Fix ICE in dwarf2out_abstract_function, at dwarf2out.cc:23771 [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. 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. Diff: --- gcc/d/d-codegen.cc | 18 +++++++++++------- gcc/testsuite/gdc.dg/debug/pr123263.d | 10 ++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 3ff3d0628ab9..02023496cfa1 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 000000000000..e23d9d412057 --- /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; +}
