[PR,d/88989] Committed fix for ICE on recursive field initializers

Message ID CABOHX+cxHBzaC9A6YBGeq3XX8Q2qYOrdEzKAToLz-_f0dXbEqw@mail.gmail.com
State New
Headers show
Series
  • [PR,d/88989] Committed fix for ICE on recursive field initializers
Related show

Commit Message

Iain Buclaw Feb. 10, 2019, 9:13 a.m.
Hi,

This patch merges the D front-end implementation with dmd upstream
39edbe17e.  Only includes a backport from a latter version, fixing PR
d/88989.

Boostrapped and regression tested on x86_64-linux-gnu.

Committed to trunk as r268740.

-- 
Iain
---

Patch

diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index c1c6cc145c4..8b377015129 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -1,4 +1,4 @@ 
-e21c07e84bd9668e1c0fc1f45e514c5fd76988e7
+39edbe17e7b5c761d780c9d1d4376a06df7bf3d8
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
diff --git a/gcc/d/dmd/dstruct.c b/gcc/d/dmd/dstruct.c
index b44d63298e6..d35b005a47d 100644
--- a/gcc/d/dmd/dstruct.c
+++ b/gcc/d/dmd/dstruct.c
@@ -723,7 +723,14 @@  bool AggregateDeclaration::fill(Loc loc, Expressions *elements, bool ctorinit)
             else if (vx->_init)
             {
                 assert(!vx->_init->isVoidInitializer());
-                e = vx->getConstInitializer(false);
+                if (vx->inuse)   // https://issues.dlang.org/show_bug.cgi?id=18057
+                {
+                    vx->error(loc, "recursive initialization of field");
+                    errors = true;
+                    e = NULL;
+                }
+                else
+                    e = vx->getConstInitializer(false);
             }
             else
             {
diff --git a/gcc/testsuite/gdc.test/compilable/interpret3.d b/gcc/testsuite/gdc.test/compilable/interpret3.d
index 8e7025c7f59..386743e6ddc 100644
--- a/gcc/testsuite/gdc.test/compilable/interpret3.d
+++ b/gcc/testsuite/gdc.test/compilable/interpret3.d
@@ -7731,3 +7731,14 @@  bool foo17407()
 
 static assert(!foo17407);
 
+/**************************************************/
+// https://issues.dlang.org/show_bug.cgi?id=18057
+// Recursive field initializer causes segfault.
+
+struct RBNode(T)
+{
+    RBNode!T *copy = new RBNode!T;
+}
+
+static assert(!__traits(compiles, { alias bug18057 = RBNode!int; }));
+
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail18057.d b/gcc/testsuite/gdc.test/fail_compilation/fail18057.d
new file mode 100644
index 00000000000..5e2bab7f796
--- /dev/null
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail18057.d
@@ -0,0 +1,16 @@ 
+/**
+TEST_OUTPUT:
+---
+fail_compilation/fail18057.d(16): Error: template instance RBNode!int `RBNode` is not a template declaration, it is a struct
+fail_compilation/fail18057.d(13): Error: variable fail18057.RBNode.copy recursive initialization of field
+---
+*/
+
+// https://issues.dlang.org/show_bug.cgi?id=18057
+// Recursive field initializer causes segfault.
+struct RBNode
+{
+    RBNode *copy = new RBNode;
+}
+
+alias bug18057 = RBNode!int;
diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail18057b.d b/gcc/testsuite/gdc.test/fail_compilation/fail18057b.d
new file mode 100644
index 00000000000..14abbfd346f
--- /dev/null
+++ b/gcc/testsuite/gdc.test/fail_compilation/fail18057b.d
@@ -0,0 +1,13 @@ 
+/**
+TEST_OUTPUT:
+---
+fail_compilation/fail18057b.d(12): Error: variable `fail18057b.Recursive.field` recursive initialization of field
+---
+*/
+
+// https://issues.dlang.org/show_bug.cgi?id=18057
+// Recursive field initializer causes segfault.
+struct Recursive
+{
+    int field = Recursive();
+}