The device has some memory mapped peripherals and we have our HAL written as header files with static inline functions that provide access to these peripherals. The unit tests run on the simulator and "COVERAGE GCOV * DETAILS" is used in the .ini file for the simulator to generate gcov style coverage files. The tests are compiled with -O0 and debug information. Keil version is 5.33 with a flex license, compiler is 6.15.
The problem is that the .gcov files provide coverage information only on functions that are used by the unit tests. The rest of the functions in are not even considered for coverage (marked as "-:" in the .gcov file).
This is a huge problem because you will see a misleading 100% coverage for a file in which only one function is actually tested (called).
Example (code is blurred since I am not sure if I can share it externally):
The function on line 642 is not tested, the function on line 648 is covered by a unit test. The resulting coverage report correctly shows the lines from the covered function as covered does not show that the lines for the uncovered function are not covered.
Resulting .gcov file contents:
Same info in Keil's debug view:
Can you help me find a solution for this ? Perhaps I am missing something obvious?
My conclusion would be a bit different. It's not a question of optimization, but rather of usage. There is nothing for the compiler to do with an uncalled static inline function. The whole function simply will not exist in the generated code, because you explicitly told the compiler you only want it to appear inlined, inside its callers. So if there's no caller, there can be no code to configure or emit coverage information for.