AVR: if with bitpacked record creates uncomplete code
Original Reporter info from Mantis: Timm Thaler
-
Reporter name: Timm Thaler
Original Reporter info from Mantis: Timm Thaler
- Reporter name: Timm Thaler
Description:
After fixing this issue https://bugs.freepascal.org/view.php?id=33417 an "if .. then" compare with bitpacked record creates uncomplete code under some circumstances:
- if..then cause is in procedure
- call procedure by value (by reference it works)
- check with "not" on false, check on true works
Steps to reproduce:
Have a varable as bitpacked record:
type
tflags = bitpacked record // Flags
bit0, bit1, bit2, bit3, bit4, bit5, bit6, bit7 : boolean;
end;
var
flags : tflags;
Have a procedure checking this record for single bits:
procedure flagtest(test : tflags);
begin
if not flags.bit3 then begin // ok
inc(cyclcnt);
end;
if not test.bit3 then begin // code in "if..then" cause is missing
inc(cyclcnt);
end;
if flags.bit3 then begin // ok
inc(cyclcnt);
end;
if test.bit3 then begin // ok
inc(cyclcnt);
end;
end;
Call this procedure:
flagtest(flags);
The procedure compiles to:
PsMATHTEST_ss_FLAGTESTsTFLAGS:
# [14] begin mov r18,r24 # Var test located in register r18 # [15] if not flags.bit3 then begin // ok lds r19,(U_sMT_INIT_ss_FLAGS) sbrc r19,3 rjmp .Lj6 .Lj7: # [16] inc(cyclcnt); lds r19,(U_sMT_INIT_ss_CYCLCNT) inc r19 sts (U_sMT_INIT_ss_CYCLCNT),r19 .Lj6: # [18] if not test.bit3 then begin // code in then cause is missing sbrc r18,3 # [21] if flags.bit3 then begin // ok lds r19,(U_sMT_INIT_ss_FLAGS) sbrs r19,3 rjmp .Lj12 .Lj11: # [22] inc(cyclcnt); lds r19,(U_sMT_INIT_ss_CYCLCNT) inc r19 sts (U_sMT_INIT_ss_CYCLCNT),r19 .Lj12: # [24] if test.bit3 then begin // ok sbrs r18,3 rjmp .Lj14 .Lj13: # [25] inc(cyclcnt); lds r18,(U_sMT_INIT_ss_CYCLCNT) inc r18 sts (U_sMT_INIT_ss_CYCLCNT),r18 .Lj14: # [27] end;
ret
Mantis conversion info:
- Mantis ID: 33423
- OS: AVR
- OS Build: AVR5
- Build: FPC 3.1.1-r38511 [2018/03/13]
- Platform: Embedded
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 38520 (#b9417cc5)