File 0722-Eliminate-crash-in-compilation-of-native-code.patch of Package erlang
From 3fbea8d5dd7d59e62d6df4bbd3fc635ce9e0b696 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Mon, 17 Feb 2020 14:46:12 +0100
Subject: [PATCH] Eliminate crash in compilation of native code
The native code compiler would crash when attempting to compile
code such as the following:
ignore_value_of_try_catch(X) ->
try
X + 1
catch
C:E:Stk ->
erlang:raise(C, E, Stk)
end,
ok.
https://bugs.erlang.org/browse/ERL-1175
---
lib/hipe/icode/hipe_icode_primops.erl | 1 +
lib/hipe/test/basic_SUITE_data/basic_exceptions.erl | 15 +++++++++++++++
2 files changed, 16 insertions(+)
diff --git a/lib/hipe/icode/hipe_icode_primops.erl b/lib/hipe/icode/hipe_icode_primops.erl
index a1f1128124..63b34f23a4 100644
--- a/lib/hipe/icode/hipe_icode_primops.erl
+++ b/lib/hipe/icode/hipe_icode_primops.erl
@@ -133,6 +133,7 @@ is_safe({hipe_bs_primop, {bs_append, _, _, _, _}}) -> false;
is_safe({hipe_bs_primop, {bs_private_append, _, _}}) -> false;
is_safe({hipe_bs_primop, bs_init_writable}) -> true;
is_safe(build_stacktrace) -> true;
+is_safe(raw_raise) -> false;
is_safe(#mkfun{}) -> true;
is_safe(#unsafe_element{}) -> true;
is_safe(#unsafe_update_element{}) -> true;
diff --git a/lib/hipe/test/basic_SUITE_data/basic_exceptions.erl b/lib/hipe/test/basic_SUITE_data/basic_exceptions.erl
index ba9c03d4ba..9f79231e5a 100644
--- a/lib/hipe/test/basic_SUITE_data/basic_exceptions.erl
+++ b/lib/hipe/test/basic_SUITE_data/basic_exceptions.erl
@@ -25,6 +25,7 @@ test() ->
ok = test_guard_bif(),
ok = test_eclectic(),
ok = test_raise(),
+ ok = test_effect(),
ok.
%%--------------------------------------------------------------------
@@ -675,4 +676,18 @@ do_test_raise_3(Expr) ->
erlang:raise(exit, {exception,C,E}, Stk)
end.
+test_effect() ->
+ ok = effect_try(2),
+ {'EXIT',{badarith,_}} = (catch effect_try(bad)),
+ ok.
+
+effect_try(X) ->
+ try
+ X + 1
+ catch
+ C:E:Stk ->
+ erlang:raise(C, E, Stk)
+ end,
+ ok.
+
id(I) -> I.
--
2.16.4