File 0525-Robustify-an-unsafe-loader-optimization.patch of Package erlang

From 238116b7ee5bd84642edc8ac540ee80913315bb5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Sat, 12 Sep 2020 17:53:59 +0200
Subject: [PATCH] Robustify an unsafe loader optimization

The loader would rewrite a code sequence such as the following:

    {move,{atom,something},{x,0}}.
    {move,{x,0},{x,0}}.

To:

    {move,{x,0},{x,0}}.

(If `{x,0}` was uninitialized, that could crash the runtime system.)

Change the loader transformation to keep both `move` instructions.

Note that such code sequences are never emitted by the Erlang compiler,
but it could be emitted by an alternative code generator or found in
handwritten or patched BEAM code.

https://bugs.erlang.org/browse/ERL-1344
---
 erts/emulator/beam/ops.tab | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/erts/emulator/beam/ops.tab b/erts/emulator/beam/ops.tab
index f3ab8bf48d..ed0b240d8a 100644
--- a/erts/emulator/beam/ops.tab
+++ b/erts/emulator/beam/ops.tab
@@ -936,8 +936,16 @@ call_ext_last Arity u$func:erlang:dt_append_vm_tag_data/1 D => \
 call_ext_only Arity u$func:erlang:dt_append_vm_tag_data/1 => \
     return
 
-# Can happen after one of the transformations above.
-move Discarded x==0 | move Something x==0 => move Something x=0
+# After one of the transformations above there can be a redundant move
+# instruction that can be discarded.
+#
+# The distinct() guard protects against the second move instruction being
+# `{move,{x,0},{x,0}}`, which is never generated by the compiler but could
+# be generated by an alternative code generator or found in handwritten
+# BEAM code.
+
+move Discarded x==0 | move Something Dst=x==0 | distinct(Something, Dst) => \
+   move Something x=0
 
 %endif
 
-- 
2.26.2

openSUSE Build Service is sponsored by