[clang] [Coverage][MC/DC] Emit MC/DC instrumentation for block bodies (PR #216313)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 14 06:13:33 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
Author: Ryan Mansfield (rjmansfield)
<details>
<summary>Changes</summary>
GenerateBlockFunction() emits the block body without going through EmitFunctionBody(), so call maybeCreateMCDCCondBitmap() to allocate a condition bitmap.
---
Full diff: https://github.com/llvm/llvm-project/pull/216313.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CGBlocks.cpp (+1)
- (added) clang/test/Profile/c-mcdc-block.c (+18)
``````````diff
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 0683a4937cf37..aeb2e3321c4d7 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1576,6 +1576,7 @@ llvm::Function *CodeGenFunction::GenerateBlockFunction(
else {
PGO->assignRegionCounters(GlobalDecl(blockDecl), fn);
incrementProfileCounter(blockDecl->getBody());
+ maybeCreateMCDCCondBitmap();
EmitStmt(blockDecl->getBody());
}
diff --git a/clang/test/Profile/c-mcdc-block.c b/clang/test/Profile/c-mcdc-block.c
new file mode 100644
index 0000000000000..8927d26e9034f
--- /dev/null
+++ b/clang/test/Profile/c-mcdc-block.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fblocks %s -o - -emit-llvm -fprofile-instrument=clang -fcoverage-mapping -fcoverage-mcdc -disable-llvm-passes | FileCheck %s -check-prefix=MCDC
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fblocks %s -o - -emit-llvm -fprofile-instrument=clang -fcoverage-mapping | FileCheck %s -check-prefix=NOMCDC
+
+// Verify MC/DC coverage for block functions.
+
+typedef int (^blk)(int, int);
+
+blk make(void) {
+ return ^(int a, int b) {
+ return (a && b);
+ };
+}
+
+// MCDC-LABEL: @__make_block_invoke(
+// MCDC: call void @llvm.instrprof.mcdc.parameters(
+// MCDC: call void @llvm.instrprof.mcdc.tvbitmap.update(
+
+// NOMCDC-NOT: instrprof.mcdc
``````````
</details>
https://github.com/llvm/llvm-project/pull/216313
More information about the cfe-commits
mailing list