EmbDev.net

Forum: ARM programming with GCC/GNU tools Is this a BUG? (yagarto)

Author: A. S. (aleksazr)
Posted on:

In my first post (http://embdev.net/topic/166639)
I had problems with the -Wunreachable-code.

I have now removed that option, DLed latest yagarto,
and changed my prog like this:
typedef struct {
  int x, y;
} POINT, *pPOINT;

pPOINT TestProc (
        pPOINT start,
        pPOINT finish)
{

    pPOINT src, dst;
    POINT pt;

    src = start;
    dst = start;

    while (1) {
        // read point
        pt.x = src->x;
        pt.y = src->y;

        // store point & INC dst
        dst->x = pt.x;
        dst->y = pt.y;
        dst++;

        // skip same points (not just one, as before)
        do {
            src++;
            if (src == finish) return dst;
        } while ( (src->x == pt.x) && (src->y == pt.y) );
    }
}

and I get this:
warning: cannot optimize loop, the loop counter may overflow.

(the warning is on RETURN DST line)

Minimum command-line options to reproduce the warning are:

-Wunsafe-loop-optimizations
-Ox (-Os, -O1, -O2, -O3)

Is it really unsafe, or is it a bug?

-----------
This is a complete list of command-line options that I use,
should I add/remove some options?

-mcpu=arm926ej-s
-mfpu=fpa
-O3
-c
-MD
-MP
-gdwarf-2
-std=gnu99
-Wall
-Wextra
-pedantic
-Waggregate-return
-Wattributes
-Wcast-align
-Wcast-qual
-Wconversion
-Wdisabled-optimization
-Wdiv-by-zero
-Wfloat-equal
-Winit-self
-Winline
-Wint-to-pointer-cast
-Wlogical-op
-Wmissing-include-dirs
-Wnested-externs
-Wold-style-definition
-Wpadded
-Wpointer-arith
-Wpointer-to-int-cast
-Wpragmas
-Wredundant-decls
-Wstrict-prototypes
-Wundef
-Wunsafe-loop-optimizations
-Wunused
Author: Bernhard R. (barnyhh)
Posted on:

Just a hint:

What happens, if the parameters start and finish are equal ( start ==
finish ) !!!

Bernhard
Author: Clifford Slocombe (clifford)
Posted on:

What happens if you change

while(1)

to

while( finish > start )

and then have a 'default' return before the last brace.  The optimizer
will then be able to make safe assumptions about the relationship
between start and finish in the loop.

Alternatively you could try adding an assert( finish > start ) before
the while loop.  I am not sure whether the optimiser uses asserts as
hints to make assumptions, but it may be worth a try (if such
micro-optimisation is ever worth the effort in the first instance that
is, which often it is not)
Author: A. S. (aleksazr)
Posted on:

I didn't know compilers are that smart!

This removes the warning:
    if (src >= finish) return dst;

thanks
Author: Clifford Slocombe (clifford)
Posted on:

Aleksandar Stancic wrote:
> I didn't know compilers are that smart!
>
Optimizers are: http://en.wikipedia.org/wiki/Compiler_optimization

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.


webmaster@embdev.netContactAdvertising on EmbDev.net