diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl index 04f13f3080d..978553e56b5 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 b607e8afd34..a8f57ea5d57 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 00000000000..c9f34e343c0 --- /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.