File 3441-Option-line_coverage-don-t-alter-line-numbers-in-exc.patch of Package erlang
From 31221a13cba1f32b1c75bc47d0ed690b3591f766 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Mon, 7 Oct 2024 08:38:40 +0200
Subject: [PATCH] Option `line_coverage`: don't alter line numbers in
exceptions
---
lib/compiler/src/beam_z.erl | 2 ++
lib/compiler/test/compile_SUITE.erl | 21 +++++++++++++++++--
.../test/compile_SUITE_data/exceptions.erl | 18 ++++++++++++++++
3 files changed, 39 insertions(+), 2 deletions(-)
create mode 100644 lib/compiler/test/compile_SUITE_data/exceptions.erl
diff --git a/lib/compiler/src/beam_z.erl b/lib/compiler/src/beam_z.erl
index 486d497f1c..88f874f69a 100644
--- a/lib/compiler/src/beam_z.erl
+++ b/lib/compiler/src/beam_z.erl
@@ -141,6 +141,8 @@ undo_rename(I) -> I.
remove_redundant_lines(Is) ->
remove_redundant_lines_1(Is, none).
+remove_redundant_lines_1([{executable_line,_,_}=I|Is], _PrevLoc) ->
+ [I|remove_redundant_lines_1(Is, none)];
remove_redundant_lines_1([{line,Loc}=I|Is], PrevLoc) ->
if
Loc =:= PrevLoc ->
diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl
index e0791172c4..b607e8afd3 100644
--- a/lib/compiler/test/compile_SUITE.erl
+++ b/lib/compiler/test/compile_SUITE.erl
@@ -41,7 +41,8 @@
deterministic_docs/1,
compile_attribute/1, message_printing/1, other_options/1,
transforms/1, erl_compile_api/1, types_pp/1, bs_init_writable/1,
- annotations_pp/1, option_order/1
+ annotations_pp/1, option_order/1,
+ sys_coverage/1
]).
suite() -> [{ct_hooks,[ts_install_cth]}].
@@ -64,7 +65,7 @@ all() ->
deterministic_docs,
compile_attribute, message_printing, other_options, transforms,
erl_compile_api, types_pp, bs_init_writable, annotations_pp,
- option_order].
+ option_order, sys_coverage].
groups() ->
[].
@@ -2317,6 +2318,22 @@ option_order(Config) ->
run(Config, Ts),
ok.
+%% Make sure that the `line_coverage` option will not change
+%% line numbers in exceptions.
+sys_coverage(Config) ->
+ Mod = exceptions,
+ DataDir = proplists:get_value(data_dir, Config),
+ Source = filename:join(DataDir, "exceptions"),
+ {ok,Mod,Code} = compile:file(Source, [line_coverage,binary,report]),
+ {module,Mod} = code:load_binary(Mod, "", Code),
+
+ Mod:Mod(Config),
+
+ true = code:delete(Mod),
+ false = code:purge(Mod),
+
+ ok.
+
%%%
%%% Utilities.
%%%
diff --git a/lib/compiler/test/compile_SUITE_data/exceptions.erl b/lib/compiler/test/compile_SUITE_data/exceptions.erl
new file mode 100644
index 0000000000..8cbffdcc59
--- /dev/null
+++ b/lib/compiler/test/compile_SUITE_data/exceptions.erl
@@ -0,0 +1,18 @@
+-module(exceptions).
+-export([?MODULE/1]).
+
+wrong_line() -> %Line 4
+ {ok,_} = id(error), %Line 5
+ ok. %Line 6
+
+?MODULE(Unknown) ->
+ id(Unknown),
+
+ {'EXIT',{{badmatch,error},
+ [{?MODULE,wrong_line,0,Loc}|_]}} = catch wrong_line(),
+ {line,5} = lists:keyfind(line, 1, Loc),
+
+ ok.
+
+id(I) ->
+ I.
--
2.43.0