INC and DEC fails when used in RECORDS

Post Reply
bscholte
Posts: 19
Joined: Sat Jan 24, 2015 6:15 pm
Location: Austria
Contact:

INC and DEC fails when used in RECORDS

Post by bscholte » Tue Mar 30, 2021 6:39 pm

This worked very well in 7.0, but fails in 7.2.
(Using Astrobe 7.2 on an LPC1769-Cortex ARM3)

Under certain conditions, the INC and DEC have stopped working when applied to a BYTE inside a RECORD.

It is easiest explained with some sample programs;
1.) When a RECORD is used and passed on a VAR to a PROCEDURE, INC or DEC on BYTEs in that record lead to a Bus Fault:

Code: Select all

MODULE faulttest1;

IMPORT Main, Out;

TYPE
     BRec=RECORD
            B0, B1, B2, B3:BYTE;
          END;

VAR gB:BRec;

PROCEDURE DoTest2(VAR B:BRec); (*This FAILS!!!*)
BEGIN
  Out.Writeln("VAR INCing");
  B.B0:=100; B.B1:=100; B.B2:=100; B.B3:=100;
  Out.Int(B.B2,0); Out.Ln;
  INC(B.B2);
  Out.Int(B.B2,0); Out.Ln;
  INC(B.B2);
  Out.Int(B.B2,0); Out.Ln;
END DoTest2;

PROCEDURE DoTest1(VAR B:BRec); (*This works*)
BEGIN
  Out.Writeln("Adding");
  B.B0:=100; B.B1:=100; B.B2:=100; B.B3:=100;
  Out.Int(B.B2,0); Out.Ln;
  B.B2:=B.B2+1;
  Out.Int(B.B2,0); Out.Ln;
  B.B2:=B.B2+1;
  Out.Int(B.B2,0); Out.Ln;
END DoTest1;
  
BEGIN
  Out.Writeln("Start");
  DoTest1(gB);
  DoTest2(gB);
END faulttest1.
2.) Similar, but slightly different when using a POINTER TO RECORD, again a Bus Fault:

Code: Select all

MODULE faulttest2;

IMPORT Main, Out;

TYPE BPtr=POINTER TO BRec;
     BRec=RECORD
            B0, B1, B2, B3:BYTE;
          END;

VAR gB:BPtr;

PROCEDURE DoTest3(B:BPtr);(*This Fails!!!*)
BEGIN
  Out.Writeln("INCing");
  B^.B0:=100; B^.B1:=100; B^.B2:=100; B^.B3:=100;
  Out.Int(B^.B2,0); Out.Ln;
  INC(B^.B2);
  Out.Int(B^.B2,0); Out.Ln;
  INC(B^.B2);
  Out.Int(B^.B2,0); Out.Ln;
END DoTest3;

PROCEDURE DoTest2(VAR B:BPtr); (*This works, but the VAR should not be needed*)
BEGIN
  Out.Writeln("VAR INCing");
  B^.B0:=100; B^.B1:=100; B^.B2:=100; B^.B3:=100;
  Out.Int(B^.B2,0); Out.Ln;
  INC(B^.B2);
  Out.Int(B^.B2,0); Out.Ln;
  INC(B^.B2);
  Out.Int(B^.B2,0); Out.Ln;
END DoTest2;

PROCEDURE DoTest1(B:BPtr); (*This works*)
BEGIN
  Out.Writeln("Adding");
  B^.B0:=100; B^.B1:=100; B^.B2:=100; B^.B3:=100;
  Out.Int(B^.B2,0); Out.Ln;
  B^.B2:=B^.B2+1;
  Out.Int(B^.B2,0); Out.Ln;
  B^.B2:=B^.B2+1;
  Out.Int(B^.B2,0); Out.Ln;
END DoTest1;
 
BEGIN
  Out.Writeln("Start");
  NEW(gB);
  DoTest1(gB);
  DoTest2(gB);
  DoTest3(gB);
  DISPOSE(gB);
END faulttest2.
Making a workaround such as

Code: Select all

PROCEDURE ByteINC(VAR B:BYTE)
      BEGIN
         B:=B+1
      END ByteINC;
does not work either, so it seems to fails for other procedure calls with this BYTE as well. As Workaround, only replacing INC for B:=B+1 and DEC for B:=B-1 seems to work.

unfortunately, we have many INC's and DEC's of BYTE's in the code.....

I hope this feedback is useful.

cfbsoftware
Site Admin
Posts: 545
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: INC and DEC fails when used in RECORDS

Post by cfbsoftware » Wed Apr 07, 2021 11:23 am

The fix for this problem is now available in v7.2.3 Astrobe for Cortex-M3, M4 and M7.

Post Reply