[committed] d: Force TYPE_MODE of classes and non-POD structs as BLKmode (PR98427)

Iain Buclaw ibuclaw@gdcproject.org
Wed Dec 23 16:41:00 GMT 2020


Hi,

This patch forces the TYPE_MODE of non-POD types as BLKmode.  Without
this being forced, the optimizer could still make decisions that require
objects of the non-POD types to need a temporary, which would result in
an ICE during the expand to RTL passes.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32,
committed to mainline.

Regards,
Iain.

---
gcc/d/ChangeLog:

	PR d/98427
	* types.cc (TypeVisitor::visit (TypeStruct *)): Set TYPE_MODE of all
	non-trivial types as BLKmode.
	(TypeVisitor::visit (TypeClass *)): Likewise.

gcc/testsuite/ChangeLog:

	PR d/98427
	* gdc.dg/pr98427.d: New test.
---
 gcc/d/types.cc                 | 10 ++++++++--
 gcc/testsuite/gdc.dg/pr98427.d | 23 +++++++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr98427.d

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 94aa1f6b9b3..acb8c409526 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -964,7 +964,10 @@ public:
     if (!t->sym->isPOD ())
       {
 	for (tree tv = t->ctype; tv != NULL_TREE; tv = TYPE_NEXT_VARIANT (tv))
-	  TREE_ADDRESSABLE (tv) = 1;
+	  {
+	    TREE_ADDRESSABLE (tv) = 1;
+	    SET_TYPE_MODE (tv, BLKmode);
+	  }
       }
   }
 
@@ -999,7 +1002,10 @@ public:
 
     /* Classes only live in memory, so always set the TREE_ADDRESSABLE bit.  */
     for (tree tv = basetype; tv != NULL_TREE; tv = TYPE_NEXT_VARIANT (tv))
-      TREE_ADDRESSABLE (tv) = 1;
+      {
+	TREE_ADDRESSABLE (tv) = 1;
+	SET_TYPE_MODE (tv, BLKmode);
+      }
 
     /* Type is final, there are no derivations.  */
     if (t->sym->storage_class & STCfinal)
diff --git a/gcc/testsuite/gdc.dg/pr98427.d b/gcc/testsuite/gdc.dg/pr98427.d
new file mode 100644
index 00000000000..225db8b8f2f
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr98427.d
@@ -0,0 +1,23 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98427
+// { dg-do compile }
+// { dg-options "-O2 -fno-inline" }
+
+@trusted memoizeExpr()
+{
+    struct CodepointSet
+    {
+        struct CowArray
+        {
+            uint *ptr;
+        }
+
+        const CodepointSet binary(U)(U rhs)
+        {
+            return rhs;
+        }
+
+        CowArray array;
+    }
+
+    CodepointSet().binary(CodepointSet());
+}
-- 
2.27.0



More information about the Gcc-patches mailing list