The attached test case produces an incorrect message when compiled with the optimizing compiler, e.g. by using the command line
The array index is reported as 0 but it should be 5. Enabling paranoid IR verification and looking at the IR shows that the problem occurs in EscapeTransformations: the int_aload is removed but the resulting temporary is still used later.
One way to fix this would be to optimize the trap_if into an unconditional trap and then run a global dead code elimination pass. AFAIK we don't have such a pass yet.