Detecting if code coverage is enabled

I want to add a call to __llvm_profile_dump() to customize code coverage recording.

Is there a way to detect if code coverage is enabled at compile time? I wasn’t able to find any __has_feature/__has_extension/macro for this in the documentation.

Currently, I solved this by adding custom preprocessor defines for the configurations that are used for running code with code coverage, but IMO it would be more reliable and convenient if there would be something built-in into compiler itself.

I want to add a call to __llvm_profile_dump() to customize code coverage recording.

Is there a way to detect if code coverage is enabled at compile time? I wasn't able to find any __has_feature/__has_extension/macro for this in the documentation.

Currently, I solved this by adding custom preprocessor defines for the configurations that are used for running code with code coverage, but IMO it would be more reliable and convenient if there would be something built-in into compiler itself.

There isn't a preprocessor define or compiler feature you can check at compile-time to determine whether coverage is enabled. We've held off on doing this to avoid creating situations where users #ifdef out code to change coverage results. Is there something about passing a custom define that's problematic?

vedant