{
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)
{
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;
--- /dev/null
+// 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];
+}
--- /dev/null
+// 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];
+}
--- /dev/null
+// 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];
+}