Well, this is a bizarre one.
(program entry point)
(temp 1)
(temp 1)
(show [ {A} {B} {C} ])
(show $X) $X
Should output:
[[0] [1] [2]]
But actually outputs:
[[0] [[[2]]] [2]]
Some temporary variable seems to be getting misplaced. Every element of this program seems to be necessary: the bug does not happen if the calls to (temp $) or (show $) are inlined, or if (temp $) does not have a parameter.
Here’s the IR that’s being produced:
Intermediate code for (temp $): 0 -1
R0: (group leader) (1 incoming) clause 65535
JUMP R1 - -
R1: (part of group R0) (1 incoming) clause 65535
ALLOCATE 0 1 -
UNIFY A0 1 -
TRACEPOINT 0 closurebug.dg:4
MAKE_PAIR_VV X0 2 []
MAKE_PAIR_VV A0 X0 []
MAKE_PAIR_VV X1 A0 []
MAKE_PAIR_VV A0 X1 A0
MAKE_PAIR_VV X2 0 []
MAKE_PAIR_VV A0 X2 A0
TRACEPOINT 1 closurebug.dg:5
SET_CONT R2 - -
INVOKE_ONCE (show $)
R2: (group leader) (1 incoming) clause 65535
TRACEPOINT 3 closurebug.dg:5
DEALLOCATE 1 - - -
PROCEED 0 - - -
It happens on all backends, so the problem must be in the frontend.