diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-07-24 18:06:51 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-08-26 10:03:56 +0200 |
commit | 87e36d9baf41a8642ca8687e846764e0828a088b (patch) | |
tree | 4f47a339a73c3f4f6adeba766237380e15558dc6 /gcc/testsuite/gdc.test | |
parent | 27e5d7c77218c0b5dd1a421a55234573e687e927 (diff) | |
download | gcc-87e36d9baf41a8642ca8687e846764e0828a088b.zip gcc-87e36d9baf41a8642ca8687e846764e0828a088b.tar.gz gcc-87e36d9baf41a8642ca8687e846764e0828a088b.tar.bz2 |
d: Fix no RVO when returning struct literals initialized with constructor.
Backports a change from upstream dmd that moves front-end NRVO checking
from ReturnStatement semantic to the end of FuncDeclaration semantic.
In the codegen, retStyle has been partially implemented so that only
structs and static arrays return RETstack. This isn't accurate, but
don't need to be for the purposes of semantic analysis.
If a function either has TREE_ADDRESSABLE or must return in memory, then
DECL_RESULT is set as the shidden field for the function. This is used
in the codegen pass for ReturnStatement where it is now detected whether
a function is returning a struct literal or a constructor function, then
the DECL_RESULT is used to directly construct the return value, instead
of doing so via temporaries.
Reviewed-on: https://github.com/dlang/dmd/pull/11622
gcc/d/ChangeLog:
PR d/96156
* d-frontend.cc (retStyle): Only return RETstack for struct and static
array types.
* decl.cc (DeclVisitor::visit (FuncDeclaration *)): Use NRVO return
for all TREE_ADDRESSABLE types. Set shidden to the RESULT_DECL.
* expr.cc (ExprVisitor::visit (CallExp *)): Force TARGET_EXPR if the
'this' pointer reference is a CONSTRUCTOR.
(ExprVisitor::visit (StructLiteralExp *)): Generate assignment to the
symbol to initialize with literal.
* toir.cc (IRVisitor::visit (ReturnStatement *)): Detect returning
struct literals and write directly into the RESULT_DECL.
* dmd/MERGE: Merge upstream dmd fe5f388d8.
gcc/testsuite/ChangeLog:
PR d/96156
* gdc.dg/pr96156.d: New test.
Diffstat (limited to 'gcc/testsuite/gdc.test')
-rw-r--r-- | gcc/testsuite/gdc.test/runnable/sdtor.d | 5 | ||||
-rw-r--r-- | gcc/testsuite/gdc.test/runnable/test8.d | 8 |
2 files changed, 7 insertions, 6 deletions
diff --git a/gcc/testsuite/gdc.test/runnable/sdtor.d b/gcc/testsuite/gdc.test/runnable/sdtor.d index b776629..ed58bcf 100644 --- a/gcc/testsuite/gdc.test/runnable/sdtor.d +++ b/gcc/testsuite/gdc.test/runnable/sdtor.d @@ -1,4 +1,4 @@ -// PERMUTE_ARGS: -unittest -O -release -inline -g +// PERMUTE_ARGS: -unittest -O -release -inline -fPIC -g import core.vararg; @@ -2827,6 +2827,7 @@ struct S17457 { this(int seconds) { dg17457 = &mfunc; } + @disable this(this); void mfunc() {} } @@ -4612,7 +4613,7 @@ int main() test9899(); test9907(); test9985(); - //test17457(); // XBUG: NRVO implementation differs + test17457(); test9994(); test10094(); test10244(); diff --git a/gcc/testsuite/gdc.test/runnable/test8.d b/gcc/testsuite/gdc.test/runnable/test8.d index 932a0cf..f8b800f 100644 --- a/gcc/testsuite/gdc.test/runnable/test8.d +++ b/gcc/testsuite/gdc.test/runnable/test8.d @@ -746,19 +746,19 @@ int foo42(const(char) *x, ...) va_list ap; va_start!(typeof(x))(ap, x); - //printf("&x = %p, ap = %p\n", &x, ap); // XBUG: static array va_lists (eg: x86_64) cannot be passed as vararg. + assert(ap != va_list.init); int i; i = va_arg!(typeof(i))(ap); - printf("i = %d\n", i); + assert(i == 3); long l; l = va_arg!(typeof(l))(ap); - printf("l = %lld\n", l); + assert(l == 23); uint k; k = va_arg!(typeof(k))(ap); - printf("k = %u\n", k); + assert(k == 4); va_end(ap); |