[Bug target/21479] New: optimizer removes incorrectly variable comparision in if clause

chaac at nic dot fi gcc-bugzilla@gcc.gnu.org
Mon May 9 22:20:00 GMT 2005


Hi,

avr-gcc seems to occasinally remove compare for ppv in following code. This 
changes semantics in the if clause and causes incorrect code execution as ppv is 
not compared first before *ppv compare.

void test(int req, void *conf)
{
    void **ppv = (void **) conf;
    unsigned long *lvp = (unsigned long *) conf;
    unsigned long lv = *lvp;
    unsigned char bv = (unsigned char) lv;

    switch (req) {
    case 1:
        if (bv)
        {
            asm ( "nop ; bv needs to be defined and used");
        }
        break;

    case 2:
        asm ( "nop ; entry to case 2");

        /* bug: first compare for ppv is missing, second is only left */
        if (ppv && (*ppv != 0)) {
            asm ( "nop ; ppv and *ppv are not zeros");
        } else {
            asm ( "nop ; either ppv or *ppv is zero");
        }

        break;
    }
}

Known workaround is to use -fno-delete-null-pointer-checks.

After a small debate on this issue on avr-gcc mailing list I was adviced to post 
a bug report.

I used following command line:
avr-gcc -c -mmcu=atmega128 -Os -Wall -Wstrict-prototypes -Wa,-ahlms=test.lst 
test.c -o test.o 

I am using avr-gcc supplied in WinAVR-20050214 (gcc 3.4.3).

> avr-gcc -v
Reading specs from C:/WinAVR/bin/../lib/gcc/avr/3.4.3/specs
Configured with: ../gcc-3.4.3/configure --prefix=m:/WinAVR --build=mingw32 --
host=mingw32 --target=avr --enable-languages=c,c++ --with-dwarf2
Thread model: single
gcc version 3.4.3

-- 
           Summary: optimizer removes incorrectly variable comparision in if
                    clause
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: chaac at nic dot fi
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-winxp-sp2
GCC target triplet: avr-*-*


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



More information about the Gcc-bugs mailing list