t_ptrchain.mod 876 B

12345678910111213141516171819202122232425262728293031323334353637
  1. MODULE TPtrChain;
  2. (* Regression: self-referential record fields must lay out the pointer
  3. and the following scalar at distinct offsets, and chained designators
  4. (p^.next^.value) plus VAR field actuals must load/store the right
  5. address. This is the lazyunique pointer-chain root cause. *)
  6. TYPE
  7. List = POINTER TO RECORD
  8. next : List;
  9. value: INTEGER;
  10. END;
  11. VAR ExitCode : INTEGER;
  12. VAR head, p : List;
  13. PROCEDURE Add (VAR q : List; val : INTEGER);
  14. BEGIN
  15. NEW(q);
  16. q^.value := val;
  17. q^.next := NIL
  18. END Add;
  19. BEGIN
  20. NEW(head);
  21. head^.value := -1;
  22. head^.next := NIL;
  23. p := head;
  24. Add(p^.next, 2);
  25. IF (p^.next # NIL) AND (p^.next^.value = 2) THEN
  26. p^.next^.value := 7;
  27. IF p^.next^.value = 7 THEN
  28. ExitCode := 42
  29. ELSE
  30. ExitCode := 1
  31. END
  32. ELSE
  33. ExitCode := 2
  34. END
  35. END TPtrChain.