From: Iain Buclaw Date: Tue, 22 Dec 2020 08:47:22 +0000 (+0100) Subject: d: Force TYPE_MODE of classes and non-POD structs as BLKmode X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=feb3c40c8ee043cc893410c9985926439292caee;p=gcc.git d: Force TYPE_MODE of classes and non-POD structs 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. 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. --- 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()); +}