llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Paweł Bylica (chfast)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/190870.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/ModuleBuilder.cpp (+3-2) 
- (added) clang/test/CoverageMapping/consteval.cpp (+21) 


``````````diff
diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp 
b/clang/lib/CodeGen/ModuleBuilder.cpp
index dd6b3c904d03d..1888de4521abd 100644
--- a/clang/lib/CodeGen/ModuleBuilder.cpp
+++ b/clang/lib/CodeGen/ModuleBuilder.cpp
@@ -228,8 +228,9 @@ namespace {
 
       // Provide some coverage mapping even for methods that aren't emitted.
       // Don't do this for templated classes though, as they may not be
-      // instantiable.
-      if (!D->getLexicalDeclContext()->isDependentContext())
+      // instantiable. Also skip consteval methods as they are never emitted.
+      if (!D->getLexicalDeclContext()->isDependentContext() &&
+          !D->getAsFunction()->isImmediateFunction())
         Builder->AddDeferredUnusedCoverageMapping(D);
     }
 
diff --git a/clang/test/CoverageMapping/consteval.cpp 
b/clang/test/CoverageMapping/consteval.cpp
new file mode 100644
index 0000000000000..3540d52011955
--- /dev/null
+++ b/clang/test/CoverageMapping/consteval.cpp
@@ -0,0 +1,21 @@
+// 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;
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/190870
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to