diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-08-25 00:39:17 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-08-26 10:03:55 +0200 |
commit | 312ad889e99ff9458c01518325775e75ab57f272 (patch) | |
tree | 035ab56a65f80de27ca138bf322c70888fec1108 /gcc/d | |
parent | 3eefc04663f325a1c76fae4d0a54284e71a57eb1 (diff) | |
download | gcc-312ad889e99ff9458c01518325775e75ab57f272.zip gcc-312ad889e99ff9458c01518325775e75ab57f272.tar.gz gcc-312ad889e99ff9458c01518325775e75ab57f272.tar.bz2 |
d: Fix no NRVO when returning an array of a non-POD struct
TREE_ADDRESSABLE was not propagated from the RECORD_TYPE to the ARRAY_TYPE, so
NRVO code generation was not being triggered.
gcc/d/ChangeLog:
PR d/96157
* d-codegen.cc (d_build_call): Handle TREE_ADDRESSABLE static arrays.
* types.cc (make_array_type): Propagate TREE_ADDRESSABLE from base
type to static array.
gcc/testsuite/ChangeLog:
PR d/96157
* gdc.dg/pr96157a.d: New test.
* gdc.dg/pr96157b.d: New test.
Diffstat (limited to 'gcc/d')
-rw-r--r-- | gcc/d/d-codegen.cc | 4 | ||||
-rw-r--r-- | gcc/d/types.cc | 7 |
2 files changed, 7 insertions, 4 deletions
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 73a6a34..6a7ecc5 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -1987,11 +1987,11 @@ d_build_call (TypeFunction *tf, tree callable, tree object, targ = build2 (COMPOUND_EXPR, TREE_TYPE (t), targ, t); } - /* Parameter is a struct passed by invisible reference. */ + /* Parameter is a struct or array passed by invisible reference. */ if (TREE_ADDRESSABLE (TREE_TYPE (targ))) { Type *t = arg->type->toBasetype (); - StructDeclaration *sd = t->isTypeStruct ()->sym; + StructDeclaration *sd = t->baseElemOf ()->isTypeStruct ()->sym; /* Nested structs also have ADDRESSABLE set, but if the type has neither a copy constructor nor a destructor available, then we diff --git a/gcc/d/types.cc b/gcc/d/types.cc index 0d05e4d..994d0b9 100644 --- a/gcc/d/types.cc +++ b/gcc/d/types.cc @@ -186,8 +186,11 @@ make_array_type (Type *type, unsigned HOST_WIDE_INT size) return t; } - return build_array_type (build_ctype (type), - build_index_type (size_int (size - 1))); + tree t = build_array_type (build_ctype (type), + build_index_type (size_int (size - 1))); + /* Propagate TREE_ADDRESSABLE to the static array type. */ + TREE_ADDRESSABLE (t) = TREE_ADDRESSABLE (TREE_TYPE (t)); + return t; } /* Builds a record type whose name is NAME. NFIELDS is the number of fields, |