A bug of bitwise and ( &) in SDCC 3.0

centennian
2010-11-20
2013-03-12
  • centennian
    centennian
    2010-11-20

    I used SDCC 3.0 to compile the following code without using any option:

    #include <8052.h>

    __sbit __at 0x95 R1;  
    __sbit __at 0x96 R2;   
    __sbit __at 0x97 R3;  
    __sbit __at 0xb0 R4;   

    void main(void)
    {

    if (R1 & R2 & R3 &R4)
    {
      R1 = 0;
    }
    }

    Error message:
    v3test.c|20|error 9: FATAL Compiler Internal Error in file '/home/sdcc-builder/build/sdcc-build/orig/sdcc/src/mcs51/gen.c' line number '6869' : 0 |
    ||=== Build finished: 1 errors, 0 warnings ===|

    My findings:
    if (R1 & R2) OK!
    if (R1 & R2 & R3) Not OK!
    if (R1 & R2 & R3 &R4)  Not OK!
    if (R1 && R2 && R3 && R4) OK!

    I remember Maarten Brock fixed a similar bug in Version 2.8 in a snapshot.
    Version 2.9 does not have this bug, too bad it resurfaces in Version 3.0.