public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/36232]  New: Optimizer removes condition check to terminate loop
@ 2008-05-13 19:47 nick dot spence at freescale dot com
  2008-05-13 19:51 ` [Bug c/36232] " nick dot spence at freescale dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: nick dot spence at freescale dot com @ 2008-05-13 19:47 UTC (permalink / raw)
  To: gcc-bugs

This section of code is used in a bootloader to test DRAM.

It loops over the DRAM performing various operations of reads and writes.

When optimization (O2 or Os) is switched on the second loop in this example no
longer terminates, but continues indefinitely because the loop condition has
been removed from the optimized code


-- 
           Summary: Optimizer removes condition check to terminate loop
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: nick dot spence at freescale dot com
 GCC build triplet: gcc version 4.1.2 20070626 (Red Hat 4.1.2-13)
  GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux


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


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

* [Bug c/36232] Optimizer removes condition check to terminate loop
  2008-05-13 19:47 [Bug c/36232] New: Optimizer removes condition check to terminate loop nick dot spence at freescale dot com
@ 2008-05-13 19:51 ` nick dot spence at freescale dot com
  2008-05-13 19:53 ` nick dot spence at freescale dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: nick dot spence at freescale dot com @ 2008-05-13 19:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from nick dot spence at freescale dot com  2008-05-13 19:51 -------
Created an attachment (id=15636)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15636&action=view)
Example code source file 

Compile with 'gcc -Os test.c' or 'gcc -O2 test.c' and examine assembly output.
Note this code cannot be run in user space becuase it will generate a
segmentation fault.


-- 


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


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

* [Bug c/36232] Optimizer removes condition check to terminate loop
  2008-05-13 19:47 [Bug c/36232] New: Optimizer removes condition check to terminate loop nick dot spence at freescale dot com
  2008-05-13 19:51 ` [Bug c/36232] " nick dot spence at freescale dot com
@ 2008-05-13 19:53 ` nick dot spence at freescale dot com
  2008-05-13 19:56 ` nick dot spence at freescale dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: nick dot spence at freescale dot com @ 2008-05-13 19:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from nick dot spence at freescale dot com  2008-05-13 19:52 -------
Created an attachment (id=15637)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15637&action=view)
Compiler intermediate file


-- 


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


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

* [Bug c/36232] Optimizer removes condition check to terminate loop
  2008-05-13 19:47 [Bug c/36232] New: Optimizer removes condition check to terminate loop nick dot spence at freescale dot com
  2008-05-13 19:51 ` [Bug c/36232] " nick dot spence at freescale dot com
  2008-05-13 19:53 ` nick dot spence at freescale dot com
@ 2008-05-13 19:56 ` nick dot spence at freescale dot com
  2008-05-13 20:02 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: nick dot spence at freescale dot com @ 2008-05-13 19:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from nick dot spence at freescale dot com  2008-05-13 19:56 -------
The code has two loops, which compile correctly when no optimization, or
-O1 are used, but the second loop becomes infinite if -Os or -O2 is used.

        .file   "test.c"
        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string "\n reads %d, 0x%08X"
        .text
.globl main
        .type   main, @function
main:
        leal    4(%esp), %ecx
        andl    $-16, %esp
        pushl   -4(%ecx)
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %esi
        pushl   %ebx
        xorl    %ebx, %ebx
        pushl   %ecx
        subl    $12, %esp
.L2:
        movl    $0, (%ebx)
        addl    $4, %ebx
        cmpl    $64, %ebx
        jne     .L2         /* branch condition for first loop */
        xorl    %esi, %esi
.L4:
        pushl   %eax
        pushl   %ebx
        subl    $4, %ebx
        pushl   %esi
        incl    %esi
        pushl   $.LC0
        call    printf
        movl    (%ebx), %eax
        addl    $16, %esp
        jmp     .L4            /* branch condition for second loop was lost */
        .size   main, .-main
        .ident  "GCC: (GNU) 4.1.2 20070626 (Red Hat 4.1.2-13)"
        .section        .note.GNU-stack,"",@progbits


-- 


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


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

* [Bug c/36232] Optimizer removes condition check to terminate loop
  2008-05-13 19:47 [Bug c/36232] New: Optimizer removes condition check to terminate loop nick dot spence at freescale dot com
                   ` (2 preceding siblings ...)
  2008-05-13 19:56 ` nick dot spence at freescale dot com
@ 2008-05-13 20:02 ` pinskia at gcc dot gnu dot org
  2008-05-13 20:03 ` pinskia at gcc dot gnu dot org
  2008-05-13 20:42 ` nick dot spence at freescale dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-05-13 20:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2008-05-13 20:02 -------
a pointer cannot go from a valid pointer to a NULL pointer.  See PR 36124.

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


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

* [Bug c/36232] Optimizer removes condition check to terminate loop
  2008-05-13 19:47 [Bug c/36232] New: Optimizer removes condition check to terminate loop nick dot spence at freescale dot com
                   ` (3 preceding siblings ...)
  2008-05-13 20:02 ` pinskia at gcc dot gnu dot org
@ 2008-05-13 20:03 ` pinskia at gcc dot gnu dot org
  2008-05-13 20:42 ` nick dot spence at freescale dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-05-13 20:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2008-05-13 20:02 -------
>This section of code is used in a bootloader to test DRAM.

You cannot use C for that code because of how C defines pointers.


-- 


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


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

* [Bug c/36232] Optimizer removes condition check to terminate loop
  2008-05-13 19:47 [Bug c/36232] New: Optimizer removes condition check to terminate loop nick dot spence at freescale dot com
                   ` (4 preceding siblings ...)
  2008-05-13 20:03 ` pinskia at gcc dot gnu dot org
@ 2008-05-13 20:42 ` nick dot spence at freescale dot com
  5 siblings, 0 replies; 7+ messages in thread
From: nick dot spence at freescale dot com @ 2008-05-13 20:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from nick dot spence at freescale dot com  2008-05-13 20:41 -------
1) Since most bootloaders are written in C your view is very interesting but
probably not shared by everyone else working with embedded software.

2) If the compiler now treats this as an undefined condition it should report a
warning instead of silently creating invalid code.


-- 


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


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

end of thread, other threads:[~2008-05-13 20:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-13 19:47 [Bug c/36232] New: Optimizer removes condition check to terminate loop nick dot spence at freescale dot com
2008-05-13 19:51 ` [Bug c/36232] " nick dot spence at freescale dot com
2008-05-13 19:53 ` nick dot spence at freescale dot com
2008-05-13 19:56 ` nick dot spence at freescale dot com
2008-05-13 20:02 ` pinskia at gcc dot gnu dot org
2008-05-13 20:03 ` pinskia at gcc dot gnu dot org
2008-05-13 20:42 ` nick dot spence at freescale 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).