v7.1: Type Tests (revisited)

Report any suspected bugs that you find
Post Reply
gray
Posts: 64
Joined: Tue Feb 12, 2019 2:59 am

v7.1: Type Tests (revisited)

Post by gray » Mon Feb 17, 2020 3:06 am

I usually use pointers for all my extended types, and type tests work as specified. For a configuration record similar to GPIO's PortConfiguration I used an extended record, and ran into a problem with type testing in leaf procedures. I have a procedure that returns the data for a specific device, eg. for I2C1, depending if I need the base version or the one with the ISR information, like so:

Code: Select all

  PROCEDURE GetConfig*(VAR cfg: I2Cbase.Config);
  BEGIN
    cfg.base := Base;
    cfg.configure := Configure;
    CASE cfg OF I2Cint.Config:
      cfg.eventIrqNo := EventIrqNo;
      cfg.errorIrqNo := ErrorIrqNo;
      cfg.eventVectorAdr := EventVectorAdr;
      cfg.errorVectorAdr := ErrorVectorAdr
    END
  END GetConfig;
This works -- until I make GetConfig a leaf procedure, in which case the type test always fails.

Here's a condensed test case:

Code: Select all

MODULE M50a;
  IMPORT Main, Out;
  
  TYPE
    R1 = POINTER TO T1;
    R2 = POINTER TO T2;
    T1 = RECORD i: INTEGER END;
    T2 = RECORD(T1) j: INTEGER END;
  VAR
    t2: T2;
    r2: R2;
    
  PROCEDURE* P1(VAR t: T1);
  BEGIN
    t.i := 13;
    CASE t OF T2:
      t.j := 4
    END
  END P1;
  
  PROCEDURE* P2(r: R1);
  BEGIN
    r.i := 13;
    CASE r OF R2:
      r.j := 4
    END
  END P2;
  
  PROCEDURE* P3(VAR t: T1);
  BEGIN
    t.i := 13;
    IF t IS T2 THEN
      t(T2).j := 4
    END
  END P3;
  
  PROCEDURE* P4(r: R1);
  BEGIN
    r.i := 13;
    IF r IS R2 THEN
      r(R2).j := 4
    END
  END P4;
  
BEGIN
  Out.String("=="); Out.Ln;
  NEW(r2);
  t2.i := 0; t2.j := 0;
  P1(t2);
  Out.Int(t2.i, 4); Out.Int(t2.j, 4); Out.Ln;
  r2.i := 0; r2.j := 0;
  P2(r2);
  Out.Int(r2.i, 4); Out.Int(r2.j, 4); Out.Ln;
  t2.i := 0; t2.j := 0;
  P3(t2);
  Out.Int(t2.i, 4); Out.Int(t2.j, 4); Out.Ln;
  r2.i := 0; r2.j := 0;
  P4(r2);
  Out.Int(r2.i, 4); Out.Int(r2.j, 4); Out.Ln
END M50a.
All four cases P1 to P4 work if the procedures are not leaf, but P1 and P3 fail if they are.

I think the problem with P1 and P3 is here:

Code: Select all

 PROCEDURE* P1(VAR t: T1);
  BEGIN
    t.i := 13;
    (* ... *)
    CASE t OF T2:
    52  F85C9C04H  ldr      r9,[fp,-4] (* type info is not on the stack, but in R10 *)
    56  F8D99004H  ldr      r9,[r9,4]
    60  467FH      mov      r7,pc
    (* ... *)
Caveat: my assembly skills are wonky at best. :!:

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

Re: v7.1: Type Tests (revisited)

Post by cfbsoftware » Thu Feb 20, 2020 12:29 am

Thank you for reporting the problem. The fix to the compiler has been included in maintenance release v7.1.1.
Last edited by cfbsoftware on Fri Feb 21, 2020 9:27 pm, edited 1 time in total.
Reason: Maintenance release v7.1.1 is now available.

Post Reply