Skip to content
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

Strange 'function coverage' result in C++ code? #98

Closed
henry2cox opened this issue Oct 7, 2020 · 5 comments
Closed

Strange 'function coverage' result in C++ code? #98

henry2cox opened this issue Oct 7, 2020 · 5 comments

Comments

@henry2cox
Copy link
Collaborator

I see some strange results that I do not understand.
For example, I have a singleton class "ErrorManager" whose constructor and destructor are defined in file 'errorManger.cpp'
The "function" coverage page for the file contains the following (extracted - many other lines elided):
image
(note the ErrorManager::~ErrorManager() is hit zero times).

Slightly later on the page, I find:
image
Note that now we see that "ErrorManager::ErrorManager().2" is hit 2415 times.
(It would be a good guess, to suspect that this regression suite contains 2415 testcases.)

The hrefs for both links point to the same line (.../errorManager.cpp:147) - so it seems clear that these two are aliases for the same function.

Question: why is geninfo (or gcov??) creating these alias entries? Is there a way to stop it?
This is a problem because we tend to care about uncovered code - but quite a few of the "uncovered" functions that we see in the function coverage report are bogus.

I am considering to add a simple filter, to merge the data for all "unique" functions which are declared on the same file/line.
I suspect that the resulting report will be more useful in our current methodology.

@henry2cox
Copy link
Collaborator Author

henry2cox commented Oct 7, 2020

FWIW: a trivial filter was so easy that I just did it.
The effect was to cut the number of unique functions reported by more than 90% in the project that I used for testing.
(Most of the merged aliases are different template instantiations.)
Update: using the simple hack on a larger, real project cut the number of functions from 260K to about 43K.

@xaizek
Copy link

xaizek commented Oct 7, 2020

why is geninfo (or gcov??) creating these alias entries?

It's the compiler. There can be different versions of destructors (or functions in general). Some with a call to delete this, some without. I think this happens when the class has a virtual table.

Haven't tried it, but you can try compiling with -ffunction-sections and linking with -Wl,--gc-sections. If those functions are unused, the linker should drop them. In general your filter will produce better results though, because some versions of the same function might be used only partially.

@henry2cox
Copy link
Collaborator Author

henry2cox commented Oct 7, 2020 via email

@henry2cox
Copy link
Collaborator Author

Replying to my own issue....
FWIW: I implemented the 'function/alias' table described above (keeping all the aliases). The function coverage detail page now shows each alias groups (in sorted order, always keeping the groups together).

@henry2cox
Copy link
Collaborator Author

#169 is merged - so I'm closing my issue :-)
The workaround is not perfect - but it it good enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants