Hi, While using GCC 4.3.1, I observed that the specialized inline code is generated automatically which causes problem in the following case. --------------------------------------------------------------------- /* File name: t.c */ static int WaitLoop (unsigned int count) { asm (" _loop: tst %0, %0 \n" "bf/s _loop \n" "add #-1, %0": "=r" (count):"0" (count)); return count; }
int main () { volatile int a = WaitLoop (100); a = WaitLoop (200); return 0; } --------------------------------------------------------------------- When I compiled this test case using GCC 4.3.1, using following command line: #sh-elf-gcc -O2 t.c -c I got the following error: /tmp/cczqWWXN.s: Assembler messages: /tmp/cczqWWXN.s:25: Error: symbol '_loop' is already defined Note: This error was observed only when "-O2" and "-O3" are used as optimization options. There is no error for "-O0" and "-O1" options. For further investigation, I generated an assembly file. It seems that, the function "WaitLoop" is getting in-lined. As the "WaitLoop" function is called twice from the "main", it was in-lined twice by the compiler. Below is the assembly file generated from "t.c". --------------------------------------------------------------------- .file "t.c" .text .little .text .align 1 .align 2 .global _main .type _main, @function _main: mov.l r14,@-r15 mov #0,r0 add #-4,r15 mov r15,r14 mov r14,r2 add #-60,r2 mov #100,r1 add #4,r14 ! 4 "t.c" 1 _loop: tst r1, r1 bf/s _loop add #-1, r1 ! 0 "" 2 mov.l r1,@(60,r2) mov.w .L3,r1 ! 4 "t.c" 1 _loop: tst r1, r1 bf/s _loop add #-1, r1 ! 0 "" 2 mov.l r1,@(60,r2) mov r14,r15 rts mov.l @r15+,r14 .align 1 .L3: --------------------------------------------------------------------- As a workaround for the above issue, one can use either of the following: 1. "-fno-inline" switch used during compilation. OR 2. Used "noinline" attribute to the "WaitLoop" function. Thanks and Regards, Prafulla -- Summary: Auto inline when optimisation is enabled, causes problem. Product: gcc Version: 4.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: prafullat at kpitcummins dot com GCC build triplet: i686-pc-linux GCC host triplet: i686-pc-linux GCC target triplet: sh*-unknown-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37493