d: Fix ICE Segmentation fault during RTL pass: expand on armhf/armel/s390x
authorIain Buclaw <ibuclaw@gdcproject.org>
Fri, 24 Jul 2020 11:49:37 +0000 (13:49 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Tue, 18 Aug 2020 07:55:09 +0000 (09:55 +0200)
gcc/d/ChangeLog:

PR d/96301
* decl.cc (DeclVisitor::visit (FuncDeclaration *)): Only return
non-trivial structs by invisible reference.

gcc/testsuite/ChangeLog:

PR d/96301
* gdc.dg/pr96301a.d: New test.
* gdc.dg/pr96301b.d: New test.
* gdc.dg/pr96301c.d: New test.

gcc/d/decl.cc
gcc/testsuite/gdc.dg/pr96301a.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/pr96301b.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/pr96301c.d [new file with mode: 0644]

index 72c8a8cff0628e8664125f8c69e3a75053bddbd9..295f780170a800e7aac9f056492b9e4264fc5871 100644 (file)
@@ -958,11 +958,14 @@ public:
       {
        tree resdecl = DECL_RESULT (fndecl);
 
-       TREE_TYPE (resdecl)
-         = build_reference_type (TREE_TYPE (resdecl));
-       DECL_BY_REFERENCE (resdecl) = 1;
-       TREE_ADDRESSABLE (resdecl) = 0;
-       relayout_decl (resdecl);
+       /* Return non-trivial structs by invisible reference.  */
+       if (TREE_ADDRESSABLE (TREE_TYPE (resdecl)))
+         {
+           TREE_TYPE (resdecl) = build_reference_type (TREE_TYPE (resdecl));
+           DECL_BY_REFERENCE (resdecl) = 1;
+           TREE_ADDRESSABLE (resdecl) = 0;
+           relayout_decl (resdecl);
+         }
 
        if (d->nrvo_var)
          {
@@ -972,7 +975,9 @@ public:
            DECL_NAME (resdecl) = DECL_NAME (var);
            /* Don't forget that we take its address.  */
            TREE_ADDRESSABLE (var) = 1;
-           resdecl = build_deref (resdecl);
+
+           if (DECL_BY_REFERENCE (resdecl))
+             resdecl = build_deref (resdecl);
 
            SET_DECL_VALUE_EXPR (var, resdecl);
            DECL_HAS_VALUE_EXPR_P (var) = 1;
diff --git a/gcc/testsuite/gdc.dg/pr96301a.d b/gcc/testsuite/gdc.dg/pr96301a.d
new file mode 100644 (file)
index 0000000..314904b
--- /dev/null
@@ -0,0 +1,31 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96301
+// { dg-additional-options "-fPIC" { target fpic } }
+// { dg-do compile }
+struct Type
+{
+    size_t length;
+    int* ptr;
+}
+
+class Container
+{
+    Type children;
+
+    void remove(void* data)
+    {
+        Type remove(Type range)
+        {
+            auto result = range;
+            if (result.front)
+                return result;
+            assert(0);
+        }
+        if (data)
+            remove(children);
+    }
+}
+
+int front(Type a)
+{
+    return a.ptr[0];
+}
diff --git a/gcc/testsuite/gdc.dg/pr96301b.d b/gcc/testsuite/gdc.dg/pr96301b.d
new file mode 100644 (file)
index 0000000..3d978be
--- /dev/null
@@ -0,0 +1,25 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96301
+// { dg-additional-options "-fPIC" { target fpic } }
+// { dg-do compile }
+class Container
+{
+    int[100] children;
+
+    void remove(void* data)
+    {
+        int[100] remove(int[100] range)
+        {
+            auto result = range;
+            if (result.front)
+                return result;
+            assert(0);
+        }
+        if (data)
+            remove(children);
+    }
+}
+
+int front(int[100] a)
+{
+    return a.ptr[0];
+}
diff --git a/gcc/testsuite/gdc.dg/pr96301c.d b/gcc/testsuite/gdc.dg/pr96301c.d
new file mode 100644 (file)
index 0000000..c909462
--- /dev/null
@@ -0,0 +1,25 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96301
+// { dg-additional-options "-fPIC" { target fpic } }
+// { dg-do compile }
+class Container
+{
+    int[] children;
+
+    void remove(void* data)
+    {
+        int[] remove(int[] range)
+        {
+            auto result = range;
+            if (result.front)
+                return result;
+            assert(0);
+        }
+        if (data)
+            remove(children);
+    }
+}
+
+int front(int[] a)
+{
+    return a.ptr[0];
+}