The GC check runs before stack locations 0 and 1 have been initialized, so they need to be cleared as they can contain garbage data which could crash Factor if it tries to trace them. This is achieved by computing uninitialized locations with a dataflow analysis (see compiler.cfg.stacks.padding ) and then inserting clears so that the instruction sequence becomes:
Similar dangerous stack 'holes' needs to be padded in the same way to guard unsafe ##peek instructions. E.g:
##inc D: 2
##peek RCX D: 2
Here the ##peek can cause a stack underflow and then there will be two uninitialized locations on the captured data stack that can't be traced. As in the previous example, ##clears are inserted on locations D: 0 and D: 1.