From: Iain Buclaw Date: Fri, 24 Jul 2020 11:49:37 +0000 (+0200) Subject: d: Fix ICE Segmentation fault during RTL pass: expand on armhf/armel/s390x X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6bebbc033d8bf2246745ffef7186b0424e08ba6b;p=gcc.git d: Fix ICE Segmentation fault during RTL pass: expand on armhf/armel/s390x 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. --- diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index 72c8a8cff06..295f780170a 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -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 index 00000000000..314904bbd06 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr96301a.d @@ -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 index 00000000000..3d978beebc8 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr96301b.d @@ -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 index 00000000000..c9094625016 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr96301c.d @@ -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]; +}