public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/46458] New: Volatile status ignored for  "(j > j)" during fold_comparison of fold-const.c
@ 2010-11-12 23:03 burnus at gcc dot gnu.org
  2010-11-12 23:10 ` [Bug middle-end/46458] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-11-12 23:03 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/46458] Volatile status ignored for  "(j > j)" during fold_comparison of fold-const.c
  2010-11-12 23:03 [Bug middle-end/46458] New: Volatile status ignored for "(j > j)" during fold_comparison of fold-const.c burnus at gcc dot gnu.org
@ 2010-11-12 23:10 ` pinskia at gcc dot gnu.org
  2010-11-12 23:19 ` burnus at gcc dot gnu.org
  2010-11-12 23:53 ` burnus at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2010-11-12 23:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46458

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-11-12 23:05:55 UTC ---
operand_equal_p should have return false for volatile declarations which it
does in the C case.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/46458] Volatile status ignored for  "(j > j)" during fold_comparison of fold-const.c
  2010-11-12 23:03 [Bug middle-end/46458] New: Volatile status ignored for "(j > j)" during fold_comparison of fold-const.c burnus at gcc dot gnu.org
  2010-11-12 23:10 ` [Bug middle-end/46458] " pinskia at gcc dot gnu.org
@ 2010-11-12 23:19 ` burnus at gcc dot gnu.org
  2010-11-12 23:53 ` burnus at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-11-12 23:19 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46458

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2010-11-12 23:17:58 UTC ---
(In reply to comment #1)
> operand_equal_p should have return false for volatile declarations which it
> does in the C case.

That probably means that C has TREE_SIDE_EFFECTS set while Fortran does not.
Should one set TREE_SIDE_EFFECTS for volatile variables?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/46458] Volatile status ignored for  "(j > j)" during fold_comparison of fold-const.c
  2010-11-12 23:03 [Bug middle-end/46458] New: Volatile status ignored for "(j > j)" during fold_comparison of fold-const.c burnus at gcc dot gnu.org
  2010-11-12 23:10 ` [Bug middle-end/46458] " pinskia at gcc dot gnu.org
  2010-11-12 23:19 ` burnus at gcc dot gnu.org
@ 2010-11-12 23:53 ` burnus at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-11-12 23:53 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46458

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2010-11-12 23:30:00 UTC ---
Answer from #gcc: Yes, for decl the front end needs to set TREE_SIDE_EFFECTS in
addition to TREE_THIS_VOLATILE.

Close as duplicate of the original issue.

*** This bug has been marked as a duplicate of bug 45742 ***


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-11-12 23:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-12 23:03 [Bug middle-end/46458] New: Volatile status ignored for "(j > j)" during fold_comparison of fold-const.c burnus at gcc dot gnu.org
2010-11-12 23:10 ` [Bug middle-end/46458] " pinskia at gcc dot gnu.org
2010-11-12 23:19 ` burnus at gcc dot gnu.org
2010-11-12 23:53 ` burnus at gcc dot gnu.org

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).