llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.01k stars 11.57k forks source link

llvm-cov: Uncovered region when evaluated at compile-time #35434

Open def- opened 6 years ago

def- commented 6 years ago
Bugzilla Link 36086
Version trunk
OS Linux
CC @ts826848,@chfast,@Ivan171,@kcc,@morehouse,@Dor1s,@vedantk,@yurybura

Extended Description

Code regions that can be evaluated at compile-time are shown as uncovered by llvm-cov, for example:

if (true && true) { // second true is uncovered return 0; }

if (argc > 1 && strcmp("&&", "&&) == 0) { // strcmp is uncovered return 0; }

if (argc > 1 && (strcmp)("&&", "&&) == 0) { // strcmp is covered here because it is done at runtime return 0; }

if (argc > 1 && strcmp(argv[1], "&&) == 0) { // strcmp is covered here because it is done at runtime return 0; }

Instead I would expect all of the if line to be covered.

Dor1s commented 6 years ago

Thanks for the pointers, Vedant! I'll take a look.

vedantk commented 6 years ago

I'd start by looking at clang's CodeGenFunction::EmitIfStmt. Specifically, when it's successfully able to use ConstantFoldsToSimpleInteger(), you'll want to insert a call to instrprof_increment_step (where the step is determined by the constant folder's result).

Dor1s commented 6 years ago

Vedant, I guess you're not working on this anymore, but could you please take a look and give some pointers if you see any potential solution?

This is an issue in Chromium as well, so we'll try to fix it eventually: https://bugs.chromium.org/p/chromium/issues/detail?id=845575

def- commented 6 years ago

This is also an issue with constexprs:

include

struct Foo { constexpr Foo(int value) : m_value(value) { }

int m_value;

};

constexpr Foo initFoo(int value) { return Foo(value); }

Foo x = initFoo(10);

int main() { std::cout << x.m_value << std::endl; }

I think code that has been covered at compile-time should not be shown as uncovered. Otherwise introducing more constexpr can reduce coverage.