From 495ae550cde1a8b148c1c666efbfbfb57c1ceeb5 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 26 Feb 2024 14:19:39 -0500 Subject: [PATCH] Skip isolating cover instructions when native coverage is available If OTP is compiled with native coverage support (OTP 27+ plus JIT), `cover` does not attempt to inject counters into the code, so isolating the cover instructions fails. We can skip that step when we detect native coverage support. --- src/horus.erl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/horus.erl b/src/horus.erl index b074466..541bd02 100644 --- a/src/horus.erl +++ b/src/horus.erl @@ -1218,8 +1218,16 @@ pass1_process_instructions( Instructions, #state{mfa_in_progress = MFA, asm_in_progress_from = cover} = State) -> - Instructions1 = horus_cover:isolate_cover_instructions(MFA, Instructions), - pass1_process_instructions(Instructions1, State, []); + NativeCoverageSupport = erlang:function_exported( + code, coverage_support, 0) andalso + apply(code, coverage_support, []), + case NativeCoverageSupport of + true -> + pass1_process_instructions(Instructions, State, []); + false -> + Instructions1 = horus_cover:isolate_cover_instructions(MFA, Instructions), + pass1_process_instructions(Instructions1, State, []) + end; pass1_process_instructions(Instructions, State) -> pass1_process_instructions(Instructions, State, []).