[Top][All Lists]
[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: |
Dmitry K. |
Subject: |
Re: [avr-gcc-list] WinAVR 20050214 (gcc 3.4.3) and optimizer bug. |
Date: |
Mon, 9 May 2005 10:51:56 +1100 |
User-agent: |
KMail/1.5 |
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.