Code generated in following example only tests for bit #0
struct sBITS {
unsigned b0 : 1;
unsigned b1 : 1;
unsigned b2 : 1;
unsigned b3 : 1;
unsigned b4 : 1;
unsigned b5 : 1;
unsigned b6 : 1;
unsigned b7 : 1;
};
struct sBITS vb;
__bit not_0;
void SetIf(uint8_t x) {
vb.b3 = (x != 0); // only bit 0 of 'x' testet
not_0 = (x != 0); // works
}
void main() {
SetIf(13);
}
Resulting Code (from rst-file)
_SetIf:
mov r7,dpl
; sd1.c:17: vb.b3 = (x != 0); // only bit 0 of 'x' testet
mov r0,#_vb
mov a,r7
rrc a ; <-- BUG: only bit 0 tested
mov a,@r0
mov acc.3,c
mov @r0,a
; sd1.c:18: not_0 = (x != 0); // works
mov a,r7
add a,#0xff
mov _not_0,c
ret
Compiler Version:
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.6.0 #9615 (MINGW32)
command to compile:
sdcc.exe -mmcs51 --std-sdcc99 sample.c
I can reproduce the issue in sdcc 3.6.1 #9667. And it really is mcs51-specific: The code for stm8 and z80 looks okay.
Philipp
I am afraid this is a bug will affect all ports.
The following test case fails.
Here is the wrong AST
Seems this got fixed with the double negation stuff a while ago. To be sure it doesn't come back I added a test in rev. #9873.
Philipp