public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10008] d: Wrong evaluation order of binary expressions (PR101640)
@ 2021-07-28 11:50 Iain Buclaw
0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2021-07-28 11:50 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:9a16492f524eb46b4ba0375d2e2ebe0f62b72fa4
commit r10-10008-g9a16492f524eb46b4ba0375d2e2ebe0f62b72fa4
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date: Tue Jul 27 13:24:34 2021 +0200
d: Wrong evaluation order of binary expressions (PR101640)
The use of fold_build2 can in some cases swap the order of its operands
if that is the more optimal thing to do. However this breaks semantic
guarantee of left-to-right evaluation in D.
PR d/101640
gcc/d/ChangeLog:
* expr.cc (binary_op): Use build2 instead of fold_build2.
gcc/testsuite/ChangeLog:
* gdc.dg/pr101640.d: New test.
(cherry picked from commit 54ec50bada94a8ff92edb04ee5216c27fa4bf942)
Diff:
---
gcc/d/expr.cc | 2 +-
gcc/testsuite/gdc.dg/pr101640.d | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 2e70bf3a8e7..955a0ad4ad4 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -162,7 +162,7 @@ class ExprVisitor : public Visitor
eptype = type;
}
- ret = fold_build2 (code, eptype, arg0, arg1);
+ ret = build2 (code, eptype, arg0, arg1);
}
return d_convert (type, ret);
diff --git a/gcc/testsuite/gdc.dg/pr101640.d b/gcc/testsuite/gdc.dg/pr101640.d
new file mode 100644
index 00000000000..68de4088512
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr101640.d
@@ -0,0 +1,11 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101640
+// { dg-do compile }
+// { dg-options "-fdump-tree-original" }
+
+int fun101640(ref int);
+
+int test101640(int val)
+{
+ // { dg-final { scan-tree-dump "= val \\\+ fun101640 \\\(\\\(int &\\\) &val\\\);" "original" } }
+ return val + fun101640(val);
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-07-28 11:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28 11:50 [gcc r10-10008] d: Wrong evaluation order of binary expressions (PR101640) Iain Buclaw
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).