[Bug c/55770] New: when compiling code with -fwhole-program and -fipa-matrix-reorg,compiler will produce wrong code

hcj20080469 at 163 dot com gcc-bugzilla@gcc.gnu.org
Fri Dec 21 01:58:00 GMT 2012


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

             Bug #: 55770
           Summary: when compiling code with -fwhole-program and
                    -fipa-matrix-reorg,compiler will produce wrong code
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: hcj20080469@163.com


compiler version :gcc 4.7.1
--build=i586-suse-linux 
--host=i586-suse-linux
--target=i586-target-linux-gnu

test case test.c:

#include <string.h>

void __attribute__((noinline)) mem_init (void);
int **vel;
int *p;
int main (int argc, char **argv)
{
  int i, j, k;
  mem_init();
  p=malloc(4);
  *p=123;
 printf("p1:%d\n",*p);
  return 0;
}

void __attribute__((noinline))
mem_init (void)
{

  int i, j, k,d;

  d = 0;
  vel = (int **) malloc(2*sizeof(int *));
  for(i=0;i<2;i++)
    vel[i]=(int *)malloc(4*sizeof(int));
  for(i=0;i<2;i++)
        for(j=0;j<4;j++)
      vel[i][j]=i+j;

}


with command compile code
i586-target-linux-gnu-gcc test.c   -fno-ipa-matrix-reorg -fdump-tree-optimized 
-O3 -fwhole-program -fno-tree-fre -lm -S -o test-2.s

i586-target-linux-gnu-gcc test-2.s -o test-2.exe


assembling file test-2.s content following:

mem_init:
.LFB34:
    subl    $28, %esp
    movl    $8, (%esp)
    movl    $16, T.6
    movl    $32, T.7
    call    malloc # get 8 byte in the heap space 
    movl    %eax, vel
    movl    $0, (%eax)
    movl    $1, 4(%eax)
    movl    $2, 8(%eax)
    movl    $3, 12(%eax)
    movl    $1, 16(%eax)
    movl    $2, 20(%eax)
    movl    $3, 24(%eax)
    movl    $4, 28(%eax)# wring 32 byte date to the heap space
    addl    $28, %esp
    .cfi_def_cfa_offset 4
    ret
    .cfi_endproc

run the test-2.exe , give error  infomation
test-1.exe: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr)
(((char *) &((av)->bins[((1) - 1) * 2])) - _0x1) && ((unsigned long)old_end &
pagemask) == 0)' failed.
Aborted



More information about the Gcc-bugs mailing list