The following code, compiled with --std-sdcc2x -mmcs51 --model-large --stack-auto --fomit-frame-pointer --opt-code-speed --peep-return
typedef unsigned long uint32_t;
struct my_data_t
{
const char* a;
const void* b;
uint32_t c;
};
const struct my_data_t my_data2 = { "AAA", "AAA", (uint32_t)"AAA" };
will output the wrong field initialization data:
_my_data2:
.byte __str_0, (__str_0 >> 8), (__str_0 >> 16) + 0x80
; generic printIvalPtr
.byte #0xb0,#0xeb,#0x28
.byte #0xb0, #0xeb, #0x28, #0x06 ; 103345072
It should use the same initialization data for all the fields. Looks like the init data output type is determined by the type of the initialized field, which seems to be not be not a correct assumption here.
Haven't checked if this happens on anythingg else than mcs51, but my guess is it will be so.
Maybe somewhat related to https://sourceforge.net/p/sdcc/bugs/3971/
Note: The output in the original description above has been obtained with this patch applied https://sourceforge.net/p/sdcc/feature-requests/_discuss/thread/20d0835c81/6ce1/attachment/0001-issue-892-preserve-high-byte-of-gptr.patch
Without the patch it will output: