This is an archive of the discontinued LLVM Phabricator instance.

[GCOV] Handle correctly multiple CUs when profiling

Authored by calixte on Sep 12 2018, 4:15 AM.



Currently, clang crashes when there are several CUs with the same module.
It has been probably broken in:
So the goal of the patch is to fix it.

Diff Detail

Event Timeline

calixte created this revision.Sep 12 2018, 4:15 AM
calixte edited the summary of this revision. (Show Details)Sep 12 2018, 4:16 AM
vsk added a comment.Sep 12 2018, 11:57 AM

It would help to have a regression test for this (somewhere in test/Transforms/GCOVProfiling). Something that exercises emitProfileArcs with 2 CU's would work.

Here's a starting point:

Note that this actually crashes somewhere in emitProfileNotes. ASan reports a heap buffer overflow.

Thanks for the test case. The code for multiple CUs looks pretty buggy.
I'll have look on it to try to fix it.

calixte updated this revision to Diff 170648.Oct 23 2018, 8:13 AM

Fix multiple CUs stuff and add a test (thanks to vsk).

calixte retitled this revision from [GCOV] Remove useless loop when emiting edge counters to [GCOV] Handle correctly multiple CUs when profiling.Oct 23 2018, 8:16 AM
calixte edited the summary of this revision. (Show Details)
vsk resigned from this revision.Oct 25 2018, 10:06 AM
vsk added a subscriber: uweigand.

Thank you for working on this. I don't have any experience or familiarity with gcov to give this a proper review. @uweigand or @sylvestre.ledru may be able to give a better review.

marco-c accepted this revision.Dec 11 2018, 2:43 AM

Very nice simplification, I hope this won't introduce regressions.
I think we should test the patch on Mozilla CI before landing, so we can be reasonably confident that it doesn't break things.


It's a little confusing to have two variable names which are so similar. Maybe call the first CUToGCOVFunctions and the second CUToFunctions?


Nit: Maybe keep the same convention of using this-> for member variables?


There are some formatting changes here and there, did you make them with clang format?
Next time, can you do the formatting changes after review, so I don't have to see them


Do we have another test for the case where CUToCounters is not empty? I assume we don't.
It would be nice to have it, even a basic one, so I can also see how the generated code looks like now.

This revision is now accepted and ready to land.Dec 11 2018, 2:43 AM