Tool/software: TI C/C++ Compiler
I believe I've come across a compiler bug that results in multiple local variables being assigned to the same location in memory. It occurs with optimizations off (-Ooff) in certain cases when a variadic function begins with a block that contains a variable declaration.
The following function returns 3000 instead of 1110:
int test(int arg, ...)
{
{ int a = 0; } // movs r0, #0
// str r0, [sp, #4]
int b = 10; // movs r0, #0xa
// str r0, [sp]
int c = 100; // movs r0, #0x64
// str r0, [sp]
int d = 1000; // mov.w r0, #0x3e8
// str r0, [sp]
return b + c + d; // ldr r2, [sp]
// ldr r0, [sp]
// ldr r1, [sp]
// adds r0, r0, r2
// adds r0, r0, r1
}
If the initializer is removed from line 3 ("{ int a; }") then the function behaves as expected.
If that block is made conditional ("if (arg) { int a; }"), the problem reappears.
Compiler Options:
Building file: "../main.c" Invoking: ARM Compiler "C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.2.LTS/bin/armcl" -mv7M4 -me -Ooff --include_path="C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.2.LTS/include" --define=ccs="ccs" --define=PART_TM4C123GH6PM --c99 --preproc_with_compile --preproc_dependency="main.d_raw" "../main.c" "../main.c", line 3: warning: variable "a" was declared but never referenced Finished building: "../main.c"
I've also been able to reproduce it with in C89 mode but the trigger conditions are slightly different.