aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.dg
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/testsuite/gdc.dg
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/testsuite/gdc.dg')
-rw-r--r--gcc/testsuite/gdc.dg/torture/imports/pr108055conv.d26
-rw-r--r--gcc/testsuite/gdc.dg/torture/imports/pr108055spec.d18
-rw-r--r--gcc/testsuite/gdc.dg/torture/imports/pr108055write.d19
-rw-r--r--gcc/testsuite/gdc.dg/torture/pr108055.d12
4 files changed, 75 insertions, 0 deletions
diff --git a/gcc/testsuite/gdc.dg/torture/imports/pr108055conv.d b/gcc/testsuite/gdc.dg/torture/imports/pr108055conv.d
new file mode 100644
index 0000000..93ebba7
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/imports/pr108055conv.d
@@ -0,0 +1,26 @@
+module imports.pr108055conv;
+
+T toStr(T, S)(S src)
+{
+ static if (is(typeof(T.init[0]) E))
+ {
+ struct Appender
+ {
+ inout(E)[] data;
+ }
+
+ import imports.pr108055spec;
+ import imports.pr108055write;
+
+ auto w = Appender();
+ FormatSpec!E f;
+ formatValue(w, src, f);
+ return w.data;
+ }
+}
+
+T to(T, A)(A args)
+{
+ return toStr!T(args);
+}
+
diff --git a/gcc/testsuite/gdc.dg/torture/imports/pr108055spec.d b/gcc/testsuite/gdc.dg/torture/imports/pr108055spec.d
new file mode 100644
index 0000000..801c581
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/imports/pr108055spec.d
@@ -0,0 +1,18 @@
+module imports.pr108055spec;
+
+template Unqual(T : const U, U)
+{
+ alias Unqual = U;
+}
+
+template FormatSpec(Char)
+if (!is(Unqual!Char == Char))
+{
+ alias FormatSpec = FormatSpec!(Unqual!Char);
+}
+
+struct FormatSpec(Char)
+if (is(Unqual!Char == Char))
+{
+ const(Char)[] nested;
+}
diff --git a/gcc/testsuite/gdc.dg/torture/imports/pr108055write.d b/gcc/testsuite/gdc.dg/torture/imports/pr108055write.d
new file mode 100644
index 0000000..fe41d7b
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/imports/pr108055write.d
@@ -0,0 +1,19 @@
+module imports.pr108055write;
+import imports.pr108055spec;
+
+void formatValueImpl(Writer, T, Char)(ref Writer , const(T) ,
+ scope const ref FormatSpec!Char )
+{
+ T val;
+ char spec;
+
+ (ref val) @trusted {
+ return (cast(const char*) &val)[0 .. val.sizeof];
+ }(val);
+
+}
+
+void formatValue(Writer, T, Char)(Writer w, T val, Char f)
+{
+ formatValueImpl(w, val, f);
+}
diff --git a/gcc/testsuite/gdc.dg/torture/pr108055.d b/gcc/testsuite/gdc.dg/torture/pr108055.d
new file mode 100644
index 0000000..c4ffad2
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr108055.d
@@ -0,0 +1,12 @@
+// { dg-do link }
+// { dg-additional-files "imports/pr108055conv.d imports/pr108055spec.d imports/pr108055write.d" }
+// { dg-additional-options "-I[srcdir] -fno-druntime" }
+import imports.pr108055conv;
+
+extern(C) int main()
+{
+ float zis;
+ static if (is(typeof(to!string(&zis))))
+ to!string(&zis);
+ return 0;
+}