File 3367-beam_disasm-Translate-raise-2-as-a-bif.patch of Package erlang

From 07311441ef8633f196359bf1de886ea8d4dc1357 Mon Sep 17 00:00:00 2001
From: Michael Davis <mcarsondavis@gmail.com>
Date: Thu, 10 Nov 2022 16:08:50 -0600
Subject: [PATCH 7/8] beam_disasm: Translate raise/2 as a bif

The removed lines contain a warning to not translate as a BIF but this
only applied to the usage of beam_disasm in HiPE. `beam_validator`
expects the `bif/5` shape and `beam_asm:make_op/2` translates from
`bif/5` to `raise/2`.

For an example listing:

    call_that_will_raise(A) ->
        try
           1 + A
        catch
           error:_:Stacktrace ->
               erlang:raise(error, "Oh no!", Stacktrace)
        end.

we get the following asm:

    {function, call_that_will_raise, 1, 2}.
      {label,1}.
        {line,[{location,"raisin.erl",3}]}.
        {func_info,{atom,raisin},{atom,call_that_will_raise},1}.
      {label,2}.
        {allocate,1,1}.
        {'try',{y,0},{f,3}}.
        {line,[{location,"raisin.erl",5}]}.
        {gc_bif,'+',{f,0},1,[{x,0},{integer,1}],{x,0}}.
        {try_end,{y,0}}.
        {deallocate,1}.
        return.
      {label,3}.
        {try_case,{y,0}}.
        {test,is_eq_exact,
              {f,4},
              [{tr,{x,0},{t_atom,[error,exit,throw]}},{atom,error}]}.
        {move,{literal,"Oh no!"},{x,1}}.
        raw_raise.
        {deallocate,1}.
        return.
      {label,4}.
        {bif,raise,{f,0},[{x,2},{x,1}],{x,0}}.
---
 lib/compiler/src/beam_disasm.erl | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/compiler/src/beam_disasm.erl b/lib/compiler/src/beam_disasm.erl
index 6a5ec15d31..5e14715c65 100644
--- a/lib/compiler/src/beam_disasm.erl
+++ b/lib/compiler/src/beam_disasm.erl
@@ -1014,8 +1014,7 @@ resolve_inst({try_case,[Reg]},_,_,_) ->  % analogous to 'catch_end'
 resolve_inst({try_case_end,[Arg]},_,_,_) ->
     {try_case_end,resolve_arg(Arg)};
 resolve_inst({raise,[_Reg1,_Reg2]=Regs},_,_,_) ->
-    {raise,{f,0},Regs,{x,0}};		 % do NOT wrap this as a 'bif'
-					 % as there is no raise/2 bif!
+    {bif,raise,{f,0},Regs,{x,0}};
 
 %%
 %% New bit syntax instructions added in February 2004 (R10B).
-- 
2.35.3

openSUSE Build Service is sponsored by