public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/49779] New: Wrong code generated for while loop with guard containing continue
@ 2011-07-18 17:32 bagnara at cs dot unipr.it
  2011-07-18 17:36 ` [Bug c/49779] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: bagnara at cs dot unipr.it @ 2011-07-18 17:32 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Wrong code generated for while loop with guard
                    containing continue
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: bagnara@cs.unipr.it


GCC turns a program that should loop forever into one that terminates:

$ cat q.c
int main() {
  do {
    while (({ continue; 1; })) {
      return 1;
    }
  } while (0);
  return 0;
}
$ gcc q.c
$ a.out && echo yes
yes

Apparently, GCC erroneously associates the `continue' to the outer `do' loop.


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

* [Bug c/49779] Wrong code generated for while loop with guard containing continue
  2011-07-18 17:32 [Bug c/49779] New: Wrong code generated for while loop with guard containing continue bagnara at cs dot unipr.it
@ 2011-07-18 17:36 ` pinskia at gcc dot gnu.org
  2011-07-18 17:42 ` bagnara at cs dot unipr.it
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-07-18 17:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-07-18 17:36:38 UTC ---
Hmm, statement expressions are an extension to the C language.


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

* [Bug c/49779] Wrong code generated for while loop with guard containing continue
  2011-07-18 17:32 [Bug c/49779] New: Wrong code generated for while loop with guard containing continue bagnara at cs dot unipr.it
  2011-07-18 17:36 ` [Bug c/49779] " pinskia at gcc dot gnu.org
@ 2011-07-18 17:42 ` bagnara at cs dot unipr.it
  2011-07-18 17:51 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: bagnara at cs dot unipr.it @ 2011-07-18 17:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from bagnara at cs dot unipr.it 2011-07-18 17:42:39 UTC ---
An extension that is still supported by GCC, right?

Here is another testcase showing the same phenomenon with `break':

int main() {
  do {
    while (({ break; 1; })) {
      ;
    }
    return 0;
  } while (0);
  return 1;
}


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

* [Bug c/49779] Wrong code generated for while loop with guard containing continue
  2011-07-18 17:32 [Bug c/49779] New: Wrong code generated for while loop with guard containing continue bagnara at cs dot unipr.it
  2011-07-18 17:36 ` [Bug c/49779] " pinskia at gcc dot gnu.org
  2011-07-18 17:42 ` bagnara at cs dot unipr.it
@ 2011-07-18 17:51 ` pinskia at gcc dot gnu.org
  2011-07-20  6:46 ` bagnara at cs dot unipr.it
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-07-18 17:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-07-18 17:47:49 UTC ---
(In reply to comment #2)
> An extension that is still supported by GCC, right?

Yes but the semantics are not well defined in this area IIRC.


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

* [Bug c/49779] Wrong code generated for while loop with guard containing continue
  2011-07-18 17:32 [Bug c/49779] New: Wrong code generated for while loop with guard containing continue bagnara at cs dot unipr.it
                   ` (2 preceding siblings ...)
  2011-07-18 17:51 ` pinskia at gcc dot gnu.org
@ 2011-07-20  6:46 ` bagnara at cs dot unipr.it
  2011-07-20  7:11 ` jakub at gcc dot gnu.org
  2011-07-21 14:26 ` joseph at codesourcery dot com
  5 siblings, 0 replies; 7+ messages in thread
From: bagnara at cs dot unipr.it @ 2011-07-20  6:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from bagnara at cs dot unipr.it 2011-07-20 06:44:25 UTC ---
Well...  do you agree that the condition of a while loop has to be
evaluated at each iteration?  If so, then we agree that the condition
is inside the while loop, not outside.  Hence, if the condition
contains unnested breaks or continues these have to refer to the while
loop in question, not to the while/for/do/switch construction that may
(or may not) contain it.


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

* [Bug c/49779] Wrong code generated for while loop with guard containing continue
  2011-07-18 17:32 [Bug c/49779] New: Wrong code generated for while loop with guard containing continue bagnara at cs dot unipr.it
                   ` (3 preceding siblings ...)
  2011-07-20  6:46 ` bagnara at cs dot unipr.it
@ 2011-07-20  7:11 ` jakub at gcc dot gnu.org
  2011-07-21 14:26 ` joseph at codesourcery dot com
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-07-20  7:11 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-07-20 07:09:56 UTC ---
The break/continue/goto out of the condition in the do/while/for condition (or
for increment or for init) might very well be considered undefined behavior,
the statement expression extension isn't specified precisely enough to say what
exactly happens.


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

* [Bug c/49779] Wrong code generated for while loop with guard containing continue
  2011-07-18 17:32 [Bug c/49779] New: Wrong code generated for while loop with guard containing continue bagnara at cs dot unipr.it
                   ` (4 preceding siblings ...)
  2011-07-20  7:11 ` jakub at gcc dot gnu.org
@ 2011-07-21 14:26 ` joseph at codesourcery dot com
  5 siblings, 0 replies; 7+ messages in thread
From: joseph at codesourcery dot com @ 2011-07-21 14:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2011-07-21 14:26:05 UTC ---
See PR 44715 for previous discussion of issues with loop control 
statements in statement expressions.


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

end of thread, other threads:[~2011-07-21 14:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-18 17:32 [Bug c/49779] New: Wrong code generated for while loop with guard containing continue bagnara at cs dot unipr.it
2011-07-18 17:36 ` [Bug c/49779] " pinskia at gcc dot gnu.org
2011-07-18 17:42 ` bagnara at cs dot unipr.it
2011-07-18 17:51 ` pinskia at gcc dot gnu.org
2011-07-20  6:46 ` bagnara at cs dot unipr.it
2011-07-20  7:11 ` jakub at gcc dot gnu.org
2011-07-21 14:26 ` joseph at codesourcery dot com

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