The following program has two unreferenced variables, both of which have static storage duration:
static int i = 99;
int main(void)
{
static int j = 101;
return 0;
}
When compiled with -mmos65c02 --stack-auto --std-c23 --max-allocs-per-node 1, storage is is allocated for both i (.area DATA) and j (in .area BSS). Code is also generated for j (in .area GSINIT):
.module example
.r65c02
.optsdcc -mmos65c02
.globl _main
.area ZP (PAG)
.area BSS
_main_j_10000_2:
.ds 2
.area DABS (ABS)
.area DATA
_i:
.ds 2
.area _CODE
.area GSINIT
.area GSFINAL
.area GSINIT
ldx #0x65
stx _main_j_10000_2
stz (_main_j_10000_2+1)
.area _CODE
.area _CODE
.area CODE
_main:
lda #0x00
tax
rts
.area CODE
.area RODATA
.area XINIT
__xinit__i:
.dw #0x0063
.area CABS (ABS)
See https://godbolt.org/z/Y398MnPhz
The redundant code in .area GSINIT and data in .area DATA/.area BSS should not be produced in the assembly language output. This feature request is somewhat related to https://sourceforge.net/p/sdcc/feature-requests/414/, which is the same complaint but relating to static functions rather than static objects.