4208 Commits

Author SHA1 Message Date
Pierre-Marie de Rodat
2286b389c7 instrument-projects.adb: fix handling of No_Body units as closure roots
Units that contain only `pragma No_Body;` should be ignored when
computing an Ada source closure: LibGPR2 assigns them no name (so
gnatcov could crash with an assertion failure), and they cannot have
dependencies anyway.
2026-02-12 09:07:26 +00:00
Pierre-Marie de Rodat
b37901aedd sc_obligations.adb: make fingerprints insensitive to line number changes
This allows passing to `gnatcov coverage` traces produced before the
addition of exemption annotations (or gnatcov-unrelated annotation) to
source code.

This commit also adapts `320-varying-scos` tests so that SCOS that are
supposed to be distinct get different column numbers, in order to
correctly exercise the "SCO fingerprint mismatch" behavior.
2026-02-11 12:57:43 +00:00
Pierre-Marie de Rodat
7804f3fad4 Make it possible to pass --relocate-build-tree without an explicit dir 2026-02-06 13:33:55 +00:00
Pierre-Marie de Rodat
a610fd3de4 command_line.ads: harmonize option value patterns 2026-02-06 12:59:30 +00:00
Dorian Peron
bcf284c0c2 instr-c(funcall): Avoid instrumenting unsupported CallInit VarDecls with auto 2026-02-06 12:38:08 +01:00
Dorian Peron
15cfd65e2f instr-c(funcall): Instrument constructors 2026-02-05 11:51:01 +01:00
Pierre-Marie de Rodat
1ef4cc57e5 Ada 2022: add support for contracts in access-to-subp types
(cherry picked from commit 05fd8b3b1e)
2026-02-02 21:20:17 +00:00
Pierre-Marie de Rodat
fd733c0d06 Ada 2022: add support for contracts in generic formal subprograms
(cherry picked from commit e70d901e62)
2026-02-02 21:07:16 +00:00
Pierre-Marie de Rodat
2856081fab instrument-ada_unit.adb: update after a breaking LAL API change
(cherry picked from commit bac3ad4b79)
2026-02-02 21:07:16 +00:00
Pierre-Marie de Rodat
b21b6565f5 Instrument: fix output dir. for instr sources of multi-project units 2026-01-28 09:25:08 +00:00
Pierre-Marie de Rodat
5fdad26e12 instrument-projects.adb: minor refactoring
Do not go through `LU_Info` in order to access the unit name, as there
is a local variable that provides the same information (and with the
needed type).
2026-01-28 09:25:08 +00:00
Dorian Peron
6fc9bd0352 instr-c(funcall): Instrument user defined literals 2026-01-27 17:54:56 +01:00
Pierre-Marie de Rodat
5e65869bfd Instrument the same set of Ada sources that GPRbuild will compile
Make `gnatcov instrument` refrain from instrumenting Ada source files
that GPRbuild would not compile when given the same project options. For
instance, do not instrument source files that belong to the root project
but which are not in the closure of GPR mains.

Adapt relevant existing testcases to accomodate this new behavior: this
makes source instrumentation behave mor like coverage with binary
traces.
2026-01-21 20:43:35 +00:00
Pierre-Marie de Rodat
398b32497c Instrument: harmonize the sloc of SCO stmt in expression functions
Fix the statement instrumentation of expression functions in Ada 2022
mode so that the sloc of the resulting SCO statement is identical to
what we get for pre-2022 code: the parens around the expression must not
be included.

This fixes 213-sarif-report test failures with `--cargs:Ada=-gnat22`.
2026-01-21 14:00:04 +00:00
Pierre-Marie de Rodat
71b5a7962e instrument-ada_unit.adb: minor style fixes 2026-01-21 11:12:31 +00:00
Pierre-Marie de Rodat
157c5f53d9 Instrument: make Ada dump helpers compatible with Ada 95
This fixes multiple tests when the testsuite is run with
`--cargs:Ada=-gnat95`, so no need for new testcases.
2026-01-21 10:00:07 +00:00
Pierre-Marie de Rodat
25ed848962 Fix function call instrumentation for pre-2012 Ada codebases 2026-01-20 15:43:37 +00:00
Pierre-Marie de Rodat
dff2ad468e instrument-ada_unit.adb: remove unused code
Current, we never instrument calls when a qualified expr is needed to
wrap the inserted if expression: remove preliminary code that was
introduced to handle this case (it's never used and we always emit a
warning saying we could not instrument instead).
2026-01-20 15:43:37 +00:00
Pierre-Marie de Rodat
e1fdee3a8a instrument-ada_unit.adb: style fixes 2026-01-20 15:43:37 +00:00
Pierre-Marie de Rodat
0158b4ab53 instrument-ada_unit.adb: minor warning message reformatting 2026-01-20 14:26:42 +00:00
Pierre-Marie de Rodat
082bcfb7b5 Remove useless null statements 2026-01-20 14:34:09 +01:00
Matthieu Eyraud
facdb93cbe Add a switch enabling the instrumentation of ghost code
Also duplicate the test with code, and run them once with the
--instrument-ghost instrumentation switch, and once without, and check
that the coverage results are as expected.

Migrate ghost code tests from the gnatcoverage-extra repository
2026-01-15 19:06:05 +01:00
Matthieu Eyraud
72422b908b Do not use the volatile aspect for witness results
Using this aspect is not supported in Ghost code when the SPARK mode is
explicitly enforced. As this was introduced to avoid the compiler
optimizing away witness declarations, devise an alternate mechanism to
that avail: adding an additional limited record parameter to the witness
call.
2026-01-15 19:06:05 +01:00
Matthieu Eyraud
5f04a6ad83 Remove code for instrumentation of EF with a controlling return type
These constructs are no longer supported in non Ada 2022 because of
freezing issues.
2026-01-15 19:06:05 +01:00
Pierre-Marie de Rodat
7c5d83be3c Instrument: fix the handling of non-Latin-1 Ada sources
Use Libadalang's heuristics to detect source encodings from GPR files to
decode Ada source files with the right encoding. Also make sure
instrumented sources are written with the same encoding.
2026-01-15 14:53:01 +00:00