aboutsummaryrefslogtreecommitdiff
path: root/gcc/d
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2022-12-10 22:11:41 +0100
committerIain Buclaw <ibuclaw@gdcproject.org>2022-12-12 20:10:25 +0100
commit9fe7d3debbf60ed9fef8053123ad542a99d62100 (patch)
tree1d955d496d79e4daa1b37bb1d6a89f6592a14681 /gcc/d
parent2d7c73ee5eae47eee16ddab3df2928ff5a7dd89c (diff)
downloadgcc-9fe7d3debbf60ed9fef8053123ad542a99d62100.zip
gcc-9fe7d3debbf60ed9fef8053123ad542a99d62100.tar.gz
gcc-9fe7d3debbf60ed9fef8053123ad542a99d62100.tar.bz2
d: Fix undefined reference to nested lambda in template (PR108055)
Sometimes, nested lambdas of templated functions get no code generation due to them being marked as instantianted outside of all modules being compiled in the current compilation unit. This despite enclosing template instances being marked as instantiated inside the current compilation unit. To fix, all enclosing templates are now checked in `function_defined_in_root_p'. Because of this change, `function_needs_inline_definition_p' has also been fixed up to only check whether the regular function definition itself is to be emitted in the current compilation unit. PR d/108055 gcc/d/ChangeLog: * decl.cc (function_defined_in_root_p): Check all enclosing template instances for definition in a root module. (function_needs_inline_definition_p): Replace call to function_defined_in_root_p with test for outer module `isRoot'. gcc/testsuite/ChangeLog: * gdc.dg/torture/imports/pr108055conv.d: New. * gdc.dg/torture/imports/pr108055spec.d: New. * gdc.dg/torture/imports/pr108055write.d: New. * gdc.dg/torture/pr108055.d: New test.
Diffstat (limited to 'gcc/d')
-rw-r--r--gcc/d/decl.cc14
1 files changed, 9 insertions, 5 deletions
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index bed1632..3508108 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -1028,7 +1028,8 @@ build_decl_tree (Dsymbol *d)
input_location = saved_location;
}
-/* Returns true if function FD is defined or instantiated in a root module. */
+/* Returns true if function FD, or any lexically enclosing scope function of FD
+ is defined or instantiated in a root module. */
static bool
function_defined_in_root_p (FuncDeclaration *fd)
@@ -1037,9 +1038,11 @@ function_defined_in_root_p (FuncDeclaration *fd)
if (md && md->isRoot ())
return true;
- TemplateInstance *ti = fd->isInstantiated ();
- if (ti && ti->minst && ti->minst->isRoot ())
- return true;
+ for (TemplateInstance *ti = fd->isInstantiated (); ti != NULL; ti = ti->tinst)
+ {
+ if (ti->minst && ti->minst->isRoot ())
+ return true;
+ }
return false;
}
@@ -1067,7 +1070,8 @@ function_needs_inline_definition_p (FuncDeclaration *fd)
/* Check whether function will be regularly defined later in the current
translation unit. */
- if (function_defined_in_root_p (fd))
+ Module *md = fd->getModule ();
+ if (md && md->isRoot ())
return false;
/* Non-inlineable functions are always external. */