[Bug middle-end/46458] New: Volatile status ignored for "(j > j)" during fold_comparison of fold-const.c
burnus at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Nov 12 23:03:00 GMT 2010
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46458
Summary: Volatile status ignored for "(j > j)" during
fold_comparison of fold-const.c
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: burnus@gcc.gnu.org
Blocks: 45742
Split off from PR 45742. This might be a WONTFIX item, however, Fortran and C
behave differently.
For the C program
int main() {
int volatile j;
if (j > j) notfound();
return 0;
}
one gets a link error ("undefined reference to `notfound'"). However, for the
equivalent Fortran program, the "if (j > j)" condition is folded away:
program main
integer, volatile :: j
if (j>j) call notfound
end program main
The "j > j" condition enters the middle end as:
fold_build2_stat_loc (loc=260, code=GT_EXPR, type=0x2aaaace48b28,
op0=0x2aaaacf20000, op1=0x2aaaacf20000)
then one calls at some point
fold_comparison (loc=260, code=GT_EXPR, type=0x2aaaace48b28,
op0=0x2aaaacf20000, op1=0x2aaaacf20000)
which contains
/* Simplify comparison of something with itself. (For IEEE
floating-point, we can only do some of these simplifications.) */
if (operand_equal_p (arg0, arg1, 0))
{
switch (code)
...
case GT_EXPR:
case LT_EXPR:
return constant_boolean_node (0, type);
Thus, the "if" condition is folded away without checking for the volatile.
One can argue that that's OK as "j > j" is always false. Or that the chance
that the result being different is minute for "j1 = {v} j; j2 = {v} j; if(j1 >
j2)". But somehow I had expected that C and Fortran give the same result.
More information about the Gcc-bugs
mailing list