GCC optimization re-order statements

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello
This isn't real code, it's just an example to ask this question:

Would GCC optimizer ever re-order these statements and cause a NULL ptr de-reference SIGSEGV? I recall reading a Chris Lattner paper indicating it could happen.

void f(int * p)
{
    if(!p)
    {
        return;
    }

    printf("%d\n", *p);
}

I which case, a lot of production code faces issues, must be changed to:

void f(int * p)
{
    if(p)
    {
        printf("%d\n", *p);
    }
}

Jonny



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux