re-enable code coverage + enzyme
@chapman39 is already working on this.
Since Oct 10, 2025.
- Dominant language
- C++
- Stars
- 245
- Forks
- 36
- Avg merge
- 8d 23h
- Merged PRs (30d)
- 4
Description
Enzyme does not work well with code coverage.
```cpp
#include
extern "C" double __enzyme_autodiff(void*, double);
double square(double x) {
return x * x;
}
double dsquare(double x) {
// This returns the derivative of square, i.e., 2 * x
return __enzyme_autodiff((void*)square, x);
}
int main() {
for (double i = 1; i < 5; ++i) {
std::cout << "square(" << i << ") = " << square(i)
<< ", dsquare(" << i << ") = " << dsquare(i) << std::endl;
}
return 0;
}
```
Link with Enzyme and `--coverage` CXX flags, and you will get the following error:
```
root@50e20fa2bc58:/home/serac/serac_repo/enzyme_cov# clang++ -fplugin=../Enzyme/enzyme/build1/Enzyme/ClangEnzyme-19.so -fprofile-instr-generate -fcoverage-mapping ./enzyme_smoketest.cpp
error: Enzyme: ; Function Attrs: mustprogress noinline nounwind optnone willreturn uwtable
define dso_local noundef double @preprocess__Z6squared(double noundef %0) #5 {
%2 = load i64, ptr @__profc__Z6squared, align 8
%3 = add i64 %2, 1
store i64 %3, ptr @__profc__Z6squared, align 8
%4 = fmul double %0, %0
ret double %4
}
constantarg[double %0] = 0 type: {[-1]:Float@double} - vals: {}
constantinst[ %2 = load i64, ptr @__profc__Z6squared, align 8] = 0 val:0 type: {}
constantinst[ %3 = add i64 %2, 1] = 0 val:0 type: {}
constantinst[ store i64 %3, ptr @__profc__Z6squared, align 8] = 0 val:1 type: {}
constantinst[ %4 = fmul double %0, %0] = 0 val:0 type: {[-1]:Float@double}
constantinst[ ret double %4] = 1 val:1 type: {}
cannot handle unknown binary operator: %3 = add i64 %2, 1
1 error generated.
```
According to an issue in Enzyme, if you re-build Enzyme with coverage CXX flags, it'll work. However, after doing so and creating a small CMake reproducer, I was not able to get it working.
Related issue: https://github.com/EnzymeAD/Enzyme/issues/2411
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.