This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/30785] New: Test to null pointer optimised away at -O2


$ cat tmp.c
typedef unsigned size_t;
char *xxcpy(  char *pDest, const char *pSrc, size_t n);
char *strncpy(  char *pDest, const char *pSrc, size_t n) {
  if (pDest == 0 || pSrc == 0) {
      if (pDest)
          *pDest = 0;
      return pDest;
      }
  return xxcpy (pDest, pSrc, n);
  }
$ powerpc-eabi-gcc -Wall -S tmp.c -o tmp.s -O2 -mcpu=440
$ cat tmp.s .file   "tmp.c"
        .section        ".text"
        .align 2
        .globl strncpy
        .type   strncpy, @function strncpy: stwu 1,-8(1)
        mflr 0
        stw 0,12(1)
        bl xxcpy
        lwz 0,12(1)
        addi 1,1,8
        mtlr 0
        blr
        .size   strncpy, .-strncpy
        .ident  "GCC: (GNU) 4.1.1"
$ powerpc-eabi-gcc -Wall -S tmp.c -o tmp.s -O1 -mcpu=440
$ cat tmp.s .file   "tmp.c"
        .section        ".text"
        .align 2
        .globl strncpy
        .type   strncpy, @function strncpy: stwu 1,-8(1)
        mflr 0
        stw 0,12(1)
        cmpwi 0,3,0
        beq- 0,.L2
        cmpwi 7,4,0
        bne+ 7,.L4
        stb 4,0(3)
        b .L2 .L4: bl xxcpy .L2: lwz 0,12(1)
        mtlr 0
        addi 1,1,8
        blr
        .size   strncpy, .-strncpy
        .ident  "GCC: (GNU) 4.1.1"
$ powerpc-eabi-gcc -v
Using built-in specs.
Target: powerpc-eabi Configured with: ../gcc-4.1.1/configure
--target=powerpc-eabi --with-cpu=440 --enable-languages=c,c++
Thread model: single
gcc version 4.1.1 

  Seems quite clear some optimisation assumes pointers cannot be null.
  Is there a flag to disable this option?
  Thanks,
  Etienne.


-- 
           Summary: Test to null pointer optimised away at -O2
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: etienne_lorrain at yahoo dot fr
 GCC build triplet: i686-pc-cygwin
  GCC host triplet: i686-pc-cygwin
GCC target triplet: powerpc-eabi


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]