aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.dg
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2021-07-03 00:13:29 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2021-07-03 00:43:57 +0200
commitc77230856eac2d28eb7bf10985846885c3c8727b (patch)
treed77253582b8c4ac0a89be0a27b423ce53150e283 /gcc/testsuite/gdc.dg
parent6feb628a706e86eb3f303aff388c74bdb29e7381 (diff)
downloadgcc-c77230856eac2d28eb7bf10985846885c3c8727b.zip
gcc-c77230856eac2d28eb7bf10985846885c3c8727b.tar.gz
gcc-c77230856eac2d28eb7bf10985846885c3c8727b.tar.bz2
d: RHS value lost when a target_expr modifies LHS in a cond_expr
To prevent the RHS of an assignment modifying the LHS before the assignment proper, a target_expr is forced so that function calls that return with slot optimization modify the temporary instead. This did not work for conditional expressions however, to give one example. So now the RHS is always forced to a temporary. PR d/101282 gcc/d/ChangeLog: * d-codegen.cc (build_assign): Force target_expr on RHS for non-POD assignment expressions. gcc/testsuite/ChangeLog: * gdc.dg/torture/pr101282.d: New test.
Diffstat (limited to 'gcc/testsuite/gdc.dg')
-rw-r--r--gcc/testsuite/gdc.dg/torture/pr101282.d23
1 files changed, 23 insertions, 0 deletions
diff --git a/gcc/testsuite/gdc.dg/torture/pr101282.d b/gcc/testsuite/gdc.dg/torture/pr101282.d
new file mode 100644
index 0000000..b75d5fc
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr101282.d
@@ -0,0 +1,23 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101282
+// { dg-do run }
+
+void main()
+{
+ struct S101282
+ {
+ int impl;
+ S101282 opUnary(string op : "-")()
+ {
+ return S101282(-impl);
+ }
+ int opCmp(int i)
+ {
+ return (impl < i) ? -1 : (impl > i) ? 1 : 0;
+ }
+ }
+ auto a = S101282(120);
+ a = -a;
+ assert(a.impl == -120);
+ a = a >= 0 ? a : -a;
+ assert(a.impl == 120);
+}