Help on GCC optimization bug

Alan Liu hongming.liu at gmail.com
Mon Aug 4 04:01:56 UTC 2008


Hi All,

I am using uClibc(GCC 4.2.3) for development on MIPS R3000 platform.
And I found one optimization bug using the following C codes:
---------------------------------------------------------------------------------------------------------
#include<stdio.h>

typedef struct list{
    struct list *left;
    struct list *right;
}list_t;
list_t a;

int test()
{
    a.left = 0x12345678;
}

int fun1()
{
    unsigned  int c = 1;

    c = *(int  *)(&a.left);
    a.left = &a;
    printf("fun1:c:%x  a.left:%x    &a:%x\n", c,a.left,&a);
    return 0;

}
int fun2()
{
    unsigned  int c = 1;

    c = *(int  *)(&a.left);
    a.left = &a;

printf("fun2:-----------------\n");

    printf("fun2:c:%x  a.left:%x    &a:%x\n", c,a.left,&a);
    return 0;

}

main()
{
test();
fun1();
fun2();
}
---------------------------------------------------------------------------------------------------
The console output after running the executable check(mips-linux-gcc -O2 -o
check check.c) is:

fun1:c:12345678  a.left:4409b0  &a:4409b0
fun2:-----------------
fun2:c:4409b0  a.left:4409b0    &a:4409b0

It seems fun2() prints wrong data of variable c.

Who could help ?

Thanks,
Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/uclibc/attachments/20080804/2205b725/attachment-0002.htm 


More information about the uClibc mailing list