avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] WinAVR 20050214 (gcc 3.4.3) and optimizer bug.


From: Vesa Jääskeläinen
Subject: Re: [avr-gcc-list] WinAVR 20050214 (gcc 3.4.3) and optimizer bug.
Date: Mon, 09 May 2005 10:42:32 +0300
User-agent: Mozilla Thunderbird (Windows/20050412)

Dmitry K. wrote:
On Monday 09 May 2005 08:26, Vesa Jääskeläinen wrote:
...

--- begin of code snippet ---
#define u_long unsigned long
#define u_char unsigned char

void test(int req, void *conf)
{
    void **ppv = (void **) conf;
    u_long *lvp = (u_long *) conf;
    u_long lv = *lvp;
    u_char bv = (u_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");

        if (ppv && (*ppv != 0)) {
            asm ( "nop ; ppv and *ppv are not zeros");
        } else {
            asm ( "nop ; either ppv or *ppv is zero");
        }

        break;
    }
}

...

We can see that one compare is missing and this causes functional change
to code.

Could someone verify this bug and possibly fix it ;)

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


You program read from `*ppv' BEFORE checking. This is a reason.
Look 'gcc.info (3.3.5)':

`-fdelete-null-pointer-checks'
     Use global dataflow analysis to identify and eliminate useless
     checks for null pointers.  The compiler assumes that dereferencing
     a null pointer would have halted the program.  If a pointer is
     checked after it has already been dereferenced, it cannot be null.

     In some environments, this assumption is not true, and programs can
     safely dereference null pointers.  Use
     `-fno-delete-null-pointer-checks' to disable this optimization for
     programs which depend on that behavior.

     Enabled at levels `-O2', `-O3', `-Os'.

Regards.

Thank you for this information. This indeed seems to cure the problem in this case. But shouldn't this be default for AVR ?

Is there a "right" way to write this code then ?

I have personally used this in numerous places (except that I compare it to NULL). I usually has some elements that pass either NULL pointer or pointer to some structure. First one usually disables option and latter one enables it.

I would like to know what is wrong in this and how could it be invalid in some architectures ?

Thanks,
Vesa Jääskeläinen





reply via email to

[Prev in Thread] Current Thread [Next in Thread]