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/pr96429.d: Update test. * gdc.dg/pr101640.d: New test.
This commit is contained in:
parent
c936c39f86
commit
54ec50bada
@ -157,7 +157,7 @@ binary_op (tree_code code, tree type, tree arg0, tree arg1)
|
||||
eptype = type;
|
||||
}
|
||||
|
||||
ret = fold_build2 (code, eptype, arg0, arg1);
|
||||
ret = build2 (code, eptype, arg0, arg1);
|
||||
}
|
||||
|
||||
return d_convert (type, ret);
|
||||
|
11
gcc/testsuite/gdc.dg/pr101640.d
Normal file
11
gcc/testsuite/gdc.dg/pr101640.d
Normal file
@ -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);
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
// { dg-options "-fdump-tree-original" }
|
||||
ptrdiff_t subbyte(byte* bp1, byte* bp2)
|
||||
{
|
||||
// { dg-final { scan-tree-dump "bp1 - bp2;" "original" } }
|
||||
// { dg-final { scan-tree-dump "\\\(bp1 - bp2\\\) /\\\[ex\\\] 1;" "original" } }
|
||||
return bp1 - bp2;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user