Add attribute and pragma for source code coverage suppression.
New attribute and pragma allow developers to exclude specific code sections from coverage reports.
GCC now supports [[gnu::suppress_coverage]] attribute and #pragma GCC suppress_coverage to exclude functions or code blocks from coverage reports. This is useful for code like unreachable asserts or library code that shouldn’t impact user-facing coverage metrics. It provides finer-grained control than existing file-level filtering.
In Details
This patch introduces compiler intrinsics (__attribute__((suppress_coverage)) and #pragma GCC suppress_coverage) that mark regions of code. The code generation and profiling instrumentation are modified to recognize these markers and skip the marked regions during coverage data collection, preventing them from negatively affecting coverage percentages.
- coverage report
- A report generated by tools like gcov that shows which lines and branches of source code were executed during a test run, used to measure test thoroughness.
- gcov
- A code coverage analysis tool that collects information about code execution by instrumenting compiled programs.
- branch coverage
- A metric in code coverage analysis that measures the percentage of executable branches (e.g., if-else statements, loops) that have been tested.
- attribute
- A C/C++ language extension that provides additional information to the compiler about program entities, like functions or variables.
- pragma
- A preprocessor directive that allows a program to issue compiler-specific commands, often used for optimization hints or controlling compiler behavior.