mve.c
void b(void) {
for (int i=0; i; i--) ;
#ifdef BAD
int a=0;
#endif
for (int i=0; i; i--) ;
}
When compiled with ./bin/sdcc -DBAD -S mve.c, I get the output
/Users/peteriannucci/git/radiolynx/v2-lion/mve/mve.c:6: error 0: Duplicate symbol 'i', symbol IGNORED
/Users/peteriannucci/git/radiolynx/v2-lion/mve/mve.c:2: error 177: previously defined here
/Users/peteriannucci/git/radiolynx/v2-lion/mve/mve.c:6: error 20: Undefined identifier 'i'
When compiled with ./bin/sdcc -S mve.c, compilation succeeds.
Expected behavior is that symbol "i" is scoped to the for loops, and there is no conflict either with or without -DBAD. Specifying --std-c11 doesn't change the behavior. Changing the order of the statements or enclosing loops in blocks changes the behavior.
Tested with the MacPorts version of sdcc,
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ez80_z80/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15 4.0.0 #11528 (Mac OS X x86_64)
published under GNU General Public License (GPL)
and with a fresh build of 4.1.0:
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/gbz80/tlcs90/ez80_z80/z80n/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15 4.1.0 #12069 (Mac OS X x86_64)
published under GNU General Public License (GPL)
This bug appears to be caused by an overly pedantic sanity check related to the handling of implicit blocks that the parser enters when it encounters a declaration after a statement within the same explicit block.
The example can be simplified as follows:
So far I have been able to circumvent the problem by removing the check that is supposed to prevent duplicate symbols in implicit sub-blocks of the same explicit block.
Fixed in [r12555]