-
-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Coverage Analysis (à la DMD) #878
Conversation
Looks nice. I try to do a review this evening. |
Nice work! Did you try how your implementation fares against the test cases from the DMD test-suite? (There is a couple of them which are currently commented out. Just search for |
Just post that druntime PR – I suppose the easiest solution would be to turn the slice into a pointer and a separate value for the length in bits? |
@klickverbot I was thinking about another solution for the druntime bug, preserving the function's signature. But I think yours is simpler and better. |
In general, the coding looks good. Could you please check the Travis build? There are compile errors with the different LLVM versions we support. |
|
||
void emitCoverageLinecountInc(Loc &loc); | ||
|
||
#endif LDC_GEN_COVERAGE_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the LDC_GEN_COVERAGE
. The file fits on a screen so this does not add information.
Looks good known. Could you please rebase your commits into one? Then I merge this PR. |
BTW: Could you please check |
@redstar ldmd2 should now correctly handle -cov. I've squashed all commits into a single one. |
@klickverbot See https://issues.dlang.org/show_bug.cgi?id=14417 . |
@redstar "all" Travis builds are green now. |
@JohanEngelen Great work! Thank you! |
Add Coverage Analysis (à la DMD)
This PR adds coverage analysis to LDC2 (cmdline option -cov[=n%]), equal to DMD's coverage analysis (http://dlang.org/code_coverage.html).
Two data structures are added to the module object file for coverage analysis: _d_cover_data and _d_cover_valid. _d_cover_data is an array of the execution count for each line of code (the execution count is atomically incremented at the start of each statement). _d_cover_valid is a bit-array that for each line says whether there is a statement on that line for which the execution count must be printed.
Each module compiled with -cov is registered for coverage output by calling _d_cover_register2() in druntime/rt/cover.d, passing _d_cover_data and _d_cover_valid. Then, druntime will take care of outputting the coverage listing. _d_cover_register2() is called by a shared static constructor.
There is a bug in druntime's interface of _d_cover_register2(). The _d_cover_valid bit array must be passed as a "size_t[] valid", however, the length field of the slice must be the number of bits in the array (number of lines). I will submit a PR to druntime to fix this, but do not know if it will be accepted. The code in this PR is very conservative and creates an oversized array for _d_cover_valid, such that the slice length field is equal to (at least) number of lines.
Tested using MSVC, x64.