File 3481-Make-option-line_coverage-work-when-given-in-the-com.patch of Package erlang
From 78c6bfc0952c2541eb1d4609ba1162ba1b508a64 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Tue, 22 Oct 2024 07:51:00 +0200
Subject: [PATCH] Make option line_coverage work when given in the compile()
attribute
Closes #8942
---
lib/compiler/src/compile.erl | 2 +-
lib/compiler/test/compile_SUITE.erl | 28 +++++++++++++++---
.../embedded_line_coverage.erl | 29 +++++++++++++++++++
3 files changed, 54 insertions(+), 5 deletions(-)
create mode 100644 lib/compiler/test/compile_SUITE_data/embedded_line_coverage.erl
diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl
index 04f13f3080..978553e56b 100644
--- a/lib/compiler/src/compile.erl
+++ b/lib/compiler/src/compile.erl
@@ -1640,7 +1640,7 @@ abstr_passes(AbstrStatus) ->
{delay,[{iff,debug_info,?pass(save_abstract_code)}]},
- {iff,line_coverage,{pass,sys_coverage}},
+ {delay,[{iff,line_coverage,{pass,sys_coverage}}]},
?pass(expand_records),
{iff,'dexp',{listing,"expand"}},
diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl
index b607e8afd3..a8f57ea5d5 100644
--- a/lib/compiler/test/compile_SUITE.erl
+++ b/lib/compiler/test/compile_SUITE.erl
@@ -2318,22 +2318,42 @@ 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),
+
+ sys_coverage_1(DataDir),
+ sys_coverage_2(DataDir),
+
+ ok.
+
+%% Make sure that the `line_coverage` option will not change line
+%% numbers in exceptions.
+sys_coverage_1(DataDir) ->
+ Mod = exceptions,
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),
+ Mod:Mod(DataDir),
true = code:delete(Mod),
false = code:purge(Mod),
ok.
+%% Make sure that the `line_coverage` option given in the `compile`
+%% attribute in a module works.
+sys_coverage_2(DataDir) ->
+ Mod = embedded_line_coverage,
+ Source = filename:join(DataDir, "embedded_line_coverage"),
+ {ok,Mod,Asm} = compile:file(Source, ['S',binary,report]),
+
+ {Mod,_,_,Fs,_} = Asm,
+ [{function,add,2,_,Is}|_] = Fs,
+ true = lists:keymember(executable_line, 1, Is),
+
+ ok.
+
%%%
%%% Utilities.
%%%
diff --git a/lib/compiler/test/compile_SUITE_data/embedded_line_coverage.erl b/lib/compiler/test/compile_SUITE_data/embedded_line_coverage.erl
new file mode 100644
index 0000000000..c9f34e343c
--- /dev/null
+++ b/lib/compiler/test/compile_SUITE_data/embedded_line_coverage.erl
@@ -0,0 +1,29 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2024. All Rights Reserved.
+%%
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-module(embedded_line_coverage).
+-export([add/2]).
+
+%% Test that using the `line_coverage` option works when given in a
+%% module.
+-compile([line_coverage]).
+
+add(A, B) ->
+ A + B.
--
2.43.0