Files
Paweł Bylica e3ebeeca95 [Coverage] Skip coverage mapping for consteval member functions (#190870)
Static consteval member functions were incorrectly getting a coverage
mapping with zero count, making them appear as uncovered lines. Free
consteval functions were already correctly excluded because
EmitTopLevelDecl returns early for immediate functions.

The fix adds an isImmediateFunction() check in
HandleInlineMemberFunction before adding deferred coverage mappings,
consistent with the top-level check.

Fixes #164448.
2026-04-23 12:16:25 +02:00

22 lines
745 B
C++

// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++20 -triple %itanium_abi_triple -main-file-name consteval.cpp %s | FileCheck %s
// Consteval functions should not have coverage mappings, as they are evaluated
// entirely at compile time and produce no runtime code.
// See https://github.com/llvm/llvm-project/issues/164448.
// CHECK-NOT: _Z1gv:
consteval int g() { return 0; }
struct S {
// CHECK-NOT: _ZN1S1sEv:
static consteval int s() { return 1; }
};
// CHECK-LABEL: main:
// CHECK-NEXT: File 0, [[@LINE+1]]:12 -> [[@LINE+5]]:2 = #0
int main() {
[[maybe_unused]] auto i = g();
[[maybe_unused]] auto j = S::s();
return 0;
}