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

Source-Based Coverage does not report uninstantiated templates as "untested" #68889

Open
carlosgalvezp opened this issue Oct 12, 2023 · 1 comment

Comments

@carlosgalvezp
Copy link
Contributor

Hi!

I find that Clang's Source-Based Coverage does not report templates as "untested", leading to fake high coverage numbers.
I understand that templates are templates, and that they don't generate code until they are instantiated. That would make sense on coverage tools that depend on code being generated, like GCOV. But Clang is different, it operates on the AST - and the templates (even though not instantiated) definitely exist in the AST.

So I wonder why can't Clang report that template as untested? Is there anything I can do to achieve the desired behavior?

Example output:

    1|       |int foo()
    2|      0|{
    3|      0|  return 0;
    4|      0|}
    5|       |
    6|       |template <typename T>
    7|       |T bar()
    8|       |{
    9|       |  return T{};
   10|       |}
   11|       |
   12|       |int main()
   13|      1|{}
   14|       |
   15|       |

The regular function clearly shows as untested (0 times executed), whereas the template function is not counted towards coverage.

Thanks!

@chapuni
Copy link
Contributor

chapuni commented Dec 28, 2024

Clang's covmap is based on function instrumentation in codegen. We have to enhance covmap (in object files) for uninstantiated templates.

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

No branches or pull requests

2 participants