File 0922-erts-emu-Fix-bug-in-bsl-bsr-error-handling-when-trac.patch of Package erlang

From 748f5a48914bc8dd5988b2427917dada68e2b3c0 Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Mon, 12 Feb 2024 19:32:24 +0100
Subject: [PATCH] erts-emu: Fix bug in bsl & bsr error handling when traced

bsl or bsr opcode may be overwritten by i_generic_breakpoint.

Maybe want a better solution that does not affect hot path.
---
 erts/emulator/beam/emu/arith_instrs.tab | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/erts/emulator/beam/emu/arith_instrs.tab b/erts/emulator/beam/emu/arith_instrs.tab
index 42f71f68fe..84ce03459e 100644
--- a/erts/emulator/beam/emu/arith_instrs.tab
+++ b/erts/emulator/beam/emu/arith_instrs.tab
@@ -352,12 +352,14 @@ i_bsr := shift.setup_bsr.execute;
 shift.head() {
     Eterm Op1, Op2;
     Sint shift_left_count;
+    unsigned int bif_ix;
 }
 
 shift.setup_bsr(Src1, Src2) {
     Op1 = $Src1;
     Op2 = $Src2;
     shift_left_count = 0;
+    bif_ix = BIF_bsr_2;
     if (ERTS_LIKELY(is_small(Op2))) {
         shift_left_count = -signed_val(Op2);
     } else if (is_big(Op2)) {
@@ -374,6 +376,7 @@ shift.setup_bsl(Src1, Src2) {
     Op1 = $Src1;
     Op2 = $Src2;
     shift_left_count = 0;
+    bif_ix = BIF_bsl_2;
     if (ERTS_LIKELY(is_small(Op2))) {
         shift_left_count = signed_val(Op2);
     } else if (is_big(Op2)) {
@@ -497,12 +500,7 @@ shift.execute(Fail, Dst) {
         reg[0] = Op1;
         reg[1] = Op2;
         SWAPOUT;
-        if (IsOpCode(I[0], i_bsl_ssjd)) {
-            I = handle_error(c_p, I, reg, &BIF_TRAP_EXPORT(BIF_bsl_2)->info.mfa);
-        } else {
-            ASSERT(IsOpCode(I[0], i_bsr_ssjd));
-            I = handle_error(c_p, I, reg, &BIF_TRAP_EXPORT(BIF_bsr_2)->info.mfa);
-        }
+        I = handle_error(c_p, I, reg, &BIF_TRAP_EXPORT(bif_ix)->info.mfa);
         goto post_error_handling;
     }
 }
-- 
2.35.3

openSUSE Build Service is sponsored by