From c2035ebb8b7bbdeee1ff03a348ba39edef1050b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 9 Mar 2016 16:14:36 +0100 Subject: beam_block: Eliminate unsafe optimization Consider this code: %% Start of block get_tuple_element Tuple 0 Element get_map_elements Fail Map [Key => Dest] . . . move Element UltimateDest %% End of block Fail: %% Code that uses Element. beam_block (more precisely, otp_tuple_element/1) would incorrectly transform the code to this: %% Start of block get_map_elements Fail Map [Key => Dest] . . . get_tuple_element Tuple 0 UltimateDest %% End of block Fail: %% Code that uses Element. That is, the code at label Fail would use register Element, which is either uninitalized or contains the wrong value. We could fix this problem by always keeping label information at hand when optimizing blocks so that we could check the code at the failure label for get_map_elements. That would require changes to beam_block and beam_utils. We might consider doing that in the future if it turns out be worth it. For now, I have decided that I want to keep the simplicity of blocks (allowing them to be optimized without keeping label information). That could be achieved by not including get_map_elements in blocks. Another way, which I have chosen, is to only allow get_map_elements as the first instruction in the block. For background on the bug: c288ab8 introduced the beam_reorder pass and 5f431276 introduced opt_tuple_element() in beam_block. --- lib/compiler/test/Makefile | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/compiler/test/Makefile') diff --git a/lib/compiler/test/Makefile b/lib/compiler/test/Makefile index c2d757da4d..85118502e3 100644 --- a/lib/compiler/test/Makefile +++ b/lib/compiler/test/Makefile @@ -8,6 +8,7 @@ include $(ERL_TOP)/make/$(TARGET)/otp.mk MODULES= \ andor_SUITE \ apply_SUITE \ + beam_block_SUITE \ beam_validator_SUITE \ beam_disasm_SUITE \ beam_except_SUITE \ @@ -44,6 +45,7 @@ MODULES= \ NO_OPT= \ andor \ apply \ + beam_block \ beam_except \ beam_reorder \ beam_type \ @@ -67,6 +69,7 @@ NO_OPT= \ INLINE= \ andor \ apply \ + beam_block \ beam_utils \ bs_bincomp \ bs_bit_binaries \ -- cgit v1.2.3