#include <stdlib.h>
_Pragma("FUNC_CANNOT_INLINE") void test_device()
{
struct device {
volatile unsigned tcc;
} dev;
unsigned tcc = rand();
dev.tcc = tcc;
}
I expected this code to generate a store to dev.tcc, but that was not the case. The generated code looks like this:
.sect ".text"
.clink
.global _Z11test_devicev
_Z11test_devicev:
CALLRET .S1 rand ;
NOP 5
$C$RL582: ; CALL-RETURN OCCURS {rand} 0 ;
The compiler version I used is 7.4.13. The compiler flags are the following:
-mv6600 --abi=eabi -O3 --symdebug:none --optimize_with_debug=off --program_level_compile --gcc --no_bad_aliases --speculate_loads=auto --remove_hooks_when_inlining --opt_for_speed=5 --gen_opt_info=2 --call_assumptions=0 -k
I do get a warning about dev being set but not used, which is misleading as dev is not being set, but dev.tcc is, and assigning to dev.tcc is observable behavior according to the C++ standard.