This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C6000 - Optimizer eliminates assignment to volatile subobject

#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.

  • Thank you for submitting a simple test case.  I can reproduce your results.  I filed SDSCM00052699 in the SDOWP system to have this investigated.  Feel free to follow it with the SDOWP link below in my signature.

    One workaround is to apply volatile to the variable dev, instead of apply it to one of the members of the structure.  For example ...

     struct device {
         unsigned tcc;
     };
    
     volatile struct device dev;

    Thanks and regards,

    -George