JPA. Guest
|
Bitfield compares with int ... Compiler bug ? |
Posted: Tue Feb 20, 2007 1:41 pm |
|
|
Hello,
I have a program running on PIC18F2585 which I always compiled with V 3.236. It works well.
When I wanted to change PIC to 18F2682, I tried to compile the code with v4.023 and it did not work any more. So I switch back to the last 'stable' version of the compiler V3.249, but it still did ot work.
Digging in the assembly code and with the help of my ICD debugger, I found some strange behaviour of the compiler when comparing bitfield with int. Here is a snipset of the listing code, obtained with V3.236 (working) and V4.023 (not working).
(m is a pointer to a struct with a member named eid, also a struct, containing bitfield filhit)
1) Working code (V3.236)
Code: | .................... if (m->eid.filhit == 2 || m->eid.filhit == 3) checkMsgCanConfig(m);
44FE: MOVLW 01
4500: MOVLB 7
4502: ADDWF x68,W
4504: MOVWF FE9
4506: MOVLW 00
4508: ADDWFC x69,W
450A: MOVWF FEA
450C: MOVFF FEF,00
4510: RRCF 00,F
4512: RRCF 00,W
4514: ANDLW 07
4516: SUBLW 02 <-- OK compare with 2
4518: BZ 4534
451A: MOVLW 01
451C: ADDWF x68,W
451E: MOVWF FE9
4520: MOVLW 00
4522: ADDWFC x69,W
4524: MOVWF FEA
4526: MOVFF FEF,00
452A: RRCF 00,F
452C: RRCF 00,W
452E: ANDLW 07
4530: SUBLW 03 <-- OK compare with 3
4532: BNZ 4542
4534: MOVFF 769,802
4538: MOVFF 768,801
453C: MOVLB 0
453E: GOTO 37B6 |
2) Not working code (v4.023 / v3.249)
Code: | .................... if (m->eid.filhit == 2 || m->eid.filhit == 3) checkMsgCanConfig(m);
48A2: MOVLW 01
48A4: MOVLB 7
48A6: ADDWF x68,W
48A8: MOVWF FE9
48AA: MOVLW 00
48AC: ADDWFC x69,W
48AE: MOVWF FEA
48B0: MOVFF FEF,00
48B4: RRCF 00,F
48B6: RRCF 00,W
48B8: ANDLW 07
---------------------------------> Code Missing
48BA: BZ 48D4
48BC: MOVLW 01
48BE: ADDWF x68,W
48C0: MOVWF FE9
48C2: MOVLW 00
48C4: ADDWFC x69,W
48C6: MOVWF FEA
48C8: MOVFF FEF,00
48CC: RRCF 00,F
48CE: RRCF 00,W
48D0: ANDLW 07
---------------------------------> Code Missing
48D2: BNZ 48E2
48D4: MOVFF 769,803
48D8: MOVFF 768,802
48DC: MOVLB 0
48DE: GOTO 3B5C |
I finally found a workaround, the following code works:
Code: | .................... if ((int8)m->eid.filhit == 2 || (int8)m->eid.filhit == 3) |
Is this a compiler bug or am I missing something with my knowledge of C ? |
|