Altera_Forum
Honored Contributor
22 years agoNios Compiler Bug - Any Workarounds
I have run into a bug with the version of GCC supplied with the Nios v3.02 development kit (2.9-nios-010801-20030520) when compiling with for 32 bit Nios (compiler flags -O0 -m32 -mflat). If I write a simple small function, like the following trivial example
int Test_With_Bug (int arg)
{
if (arg < 0)
return (-1);
return (1);
} the compiler will sometimes apply the leaf procedure optimization and omit the creation of a stack frame in the prolog (so the routine uses the callers stack frame). Unfortunately, the compiler doesn't omit the prolog code that saves the function arguments to the stack frame. Since the function is using the callers stack frame, this trashes the saved values of the caller's arguments, producing some surprising results! Does anyone know of a compiler option or version upgrage which will prevent GCC from producing code like this? As a workaround I can prevent GCC from applying this optimization to any particular function by adding a call to an external routine that does nothing. The trick is finding all the routines that might be affected by the bug.