public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/26144]  New: with -O3 and pointer casts, gcc skips if
@ 2006-02-07  0:42 gcc-bugzilla at gcc dot gnu dot org
  2006-02-07  0:53 ` [Bug tree-optimization/26144] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2006-02-07  0:42 UTC (permalink / raw)
  To: gcc-bugs


        When casting a pointer and checking for == NULL, the check is skipped
        when -O3 is enabled.  I found this problem while compiling bind with
uClibc,
        but could reproduce the problem with the debian version of gcc and this
simple
        test file.

Environment:
System: Linux dungeon2 2.6.11-1-k7-smp #1 SMP Mon Jun 20 22:34:51 MDT 2005 i686
GNU/Linux
Architecture: i686


host: i486-pc-linux-gnu
build: i486-pc-linux-gnu
target: i486-pc-linux-gnu
configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr
--disable-werror --with-tune=i686 --enable-checking=release i486-linux-gnu

How-To-Repeat:
        Compile this file:

        #include <stdio.h>
        void foo(char **dee) {  *dee = ""; }
        int main(int argc, char *argv[])
            {
            struct blah *ptr = argv[1];
            if(ptr == NULL)
                foo(&ptr);
            printf("%p", ptr); // output: (nil) expected: 0xADDRESS
            return 0;
            }


-- 
           Summary: with -O3 and pointer casts, gcc skips if
           Product: gcc
           Version: 4.0.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: devin at dungeon2 dot cainetworks dot com
 GCC build triplet: i486-pc-linux-gnu
  GCC host triplet: i486-pc-linux-gnu
GCC target triplet: i486-pc-linux-gnu


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


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

* [Bug tree-optimization/26144] with -O3 and pointer casts, gcc skips if
  2006-02-07  0:42 [Bug tree-optimization/26144] New: with -O3 and pointer casts, gcc skips if gcc-bugzilla at gcc dot gnu dot org
@ 2006-02-07  0:53 ` pinskia at gcc dot gnu dot org
  2006-02-07 17:07 ` devin at freeshell dot org
  2006-02-09  1:02 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-07  0:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-02-07 00:53 -------
I cannot reproduce this at all with 4.0.3 20051105.


-- 


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


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

* [Bug tree-optimization/26144] with -O3 and pointer casts, gcc skips if
  2006-02-07  0:42 [Bug tree-optimization/26144] New: with -O3 and pointer casts, gcc skips if gcc-bugzilla at gcc dot gnu dot org
  2006-02-07  0:53 ` [Bug tree-optimization/26144] " pinskia at gcc dot gnu dot org
@ 2006-02-07 17:07 ` devin at freeshell dot org
  2006-02-09  1:02 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: devin at freeshell dot org @ 2006-02-07 17:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from devin at freeshell dot org  2006-02-07 17:07 -------
I could reproduce it with that dated build.  And it isn't just debian but also
the buildroot gcc.  Here is the assembly produced from -O3.  Following that is
the assembly from -O2.  What seems to happen is that with -O3 foo() is
optimized out and in it's place .LC0 is stored on the stack.  Seems fine.  But
then the original value of "ptr" is used for calling printf instead of the
updated value from the stack.

        .file   "test.c"
        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string ""
        .text
        .p2align 4,,15
.globl foo
        .type   foo, @function
foo:
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %eax
        movl    $.LC0, (%eax)
        popl    %ebp
        ret
        .size   foo, .-foo
        .section        .rodata.str1.1
.LC1:
        .string "%p"
        .text
        .p2align 4,,15
.globl main
        .type   main, @function
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $24, %esp
        movl    12(%ebp), %eax
        andl    $-16, %esp
        subl    $16, %esp
        movl    4(%eax), %eax
        testl   %eax, %eax
        movl    %eax, -4(%ebp)
        je      .L8
        movl    %eax, 4(%esp)
        movl    $.LC1, (%esp)
        call    printf
        xorl    %eax, %eax
        leave
        ret
        .p2align 4,,7
.L8:
        movl    $.LC0, -4(%ebp)
        movl    %eax, 4(%esp)
        movl    $.LC1, (%esp)
        call    printf
        xorl    %eax, %eax
        leave
        ret
        .size   main, .-main
        .ident  "GCC: (GNU) 4.0.3 20060128 (prerelease) (Debian 4.0.2-8)"
        .section        .note.GNU-stack,"",@progbits

############## Correct Version #########################

        .file   "test.c"
        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string ""
        .text
        .p2align 4,,15
.globl foo
        .type   foo, @function
foo:
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %eax
        movl    $.LC0, (%eax)
        popl    %ebp
        ret
        .size   foo, .-foo
        .section        .rodata.str1.1
.LC1:
        .string "%p"
        .text
        .p2align 4,,15
.globl main
        .type   main, @function
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $24, %esp
        movl    12(%ebp), %eax
        andl    $-16, %esp
        subl    $16, %esp
        movl    4(%eax), %eax
        testl   %eax, %eax
        movl    %eax, -4(%ebp)
        je      .L8
        movl    -4(%ebp), %eax
        movl    $.LC1, (%esp)
        movl    %eax, 4(%esp)
        call    printf
        xorl    %eax, %eax
        leave
        ret
        .p2align 4,,7
.L8:
        leal    -4(%ebp), %eax
        movl    %eax, (%esp)
        call    foo
        movl    -4(%ebp), %eax
        movl    $.LC1, (%esp)
        movl    %eax, 4(%esp)
        call    printf
        xorl    %eax, %eax
        leave
        ret
        .size   main, .-main
        .ident  "GCC: (GNU) 4.0.3 20060128 (prerelease) (Debian 4.0.2-8)"
        .section        .note.GNU-stack,"",@progbits


-- 


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


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

* [Bug tree-optimization/26144] with -O3 and pointer casts, gcc skips if
  2006-02-07  0:42 [Bug tree-optimization/26144] New: with -O3 and pointer casts, gcc skips if gcc-bugzilla at gcc dot gnu dot org
  2006-02-07  0:53 ` [Bug tree-optimization/26144] " pinskia at gcc dot gnu dot org
  2006-02-07 17:07 ` devin at freeshell dot org
@ 2006-02-09  1:02 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-09  1:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2006-02-09 01:02 -------
You are violating aliasing rules which is why this does not work at -O3. 
Either access the variable ptr as  a "struct blah *" or use
-fno-strict-aliasing.

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


-- 

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=26144


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

end of thread, other threads:[~2006-02-09  1:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-07  0:42 [Bug tree-optimization/26144] New: with -O3 and pointer casts, gcc skips if gcc-bugzilla at gcc dot gnu dot org
2006-02-07  0:53 ` [Bug tree-optimization/26144] " pinskia at gcc dot gnu dot org
2006-02-07 17:07 ` devin at freeshell dot org
2006-02-09  1:02 ` pinskia at gcc dot gnu dot 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).