Ticket #504 (Open)Thu Feb 11 02:02:20 UTC 2021
DDE30 C Compiler considers local variable not accessed by inline assembler BL
Reported by: | Timothy Baldwin (184) | Severity: | Normal |
Part: | RISC OS: C/C++ toolchain | Release: | |
Milestone: | Status | Open |
Details by Timothy Baldwin (184):
Consider this program which erroneously prints “FAIL”:
<code><pre>#include <stdio.h>
void set_x(int *x) {
*x = 1;
}
int test(void) {
int x = 0;
__asm {
MOV r0, &x
BL set_x, {r0}, {}, {r0-r3, ip, lr, psr}
}
return x;
}
int main(void) {
int x = test();
puts(x ? “OK” : “FAIL”);
return !x;
}</pre></code>
The function test compiles to:
<code><pre>test
STMDB sp!,{v1,lr}
SUB sp,sp,#4
MOV a1,sp
BL set_x
MOV a1,#0
ADD sp,sp,#4
LDMIA sp!,{v1,pc}</pre></code>
Which although it allocates storage for the local variable and passes it’s address to set_x neither initialises the memory nor reads it. In the practical problem I was trying to call a non-APCS routine.
GCC would require “memory” specifying in the clobber list, but for ROOL C no requirement nor method is documented. Arrays or structs appear to work.