Altera_Forum
Honored Contributor
14 years agogcc generates incorrect code
Hi,
It appears that there is a bug in this version of the nios2 compiler at higher optimisation levels. $ nios2-elf-gcc --version nios2-elf-gcc (Altera 11.1sp2 Build 259) 4.1.2 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. I can isolate to a small source code as follows. # include <stdint.h> uint32_t makeMask ( const uint32_t l ) { uint32_t mask; if ( l < 32u ) { static const uint32_t one = 1u; const unsigned idx = 32u - l; uint32_t mask = one; mask <<= idx; mask -= one; } else { mask = 31u; } return mask; } Running gcc with these options (highest level of optimisation and producing an assembler listing) appears to indicate that there is a bug in the nios2 compiler. nios2-elf-gcc -c -O3 -S test.c .file "test.c" .section .text .align 2 .global makeMask .type makeMask, @function makeMask: movi r2, 31 ret .size makeMask, .-makeMask .ident "GCC: (Altera 11.1sp2 Build 259) 4.1.2"