https://github.com/rjmansfield created 
https://github.com/llvm/llvm-project/pull/216313

GenerateBlockFunction() emits the block body without going through 
EmitFunctionBody(), so call maybeCreateMCDCCondBitmap() to allocate a condition 
bitmap.

>From 012f3ba06b32e1f995f7143531d749ccd1134eae Mon Sep 17 00:00:00 2001
From: Ryan Mansfield <[email protected]>
Date: Fri, 14 Aug 2026 09:10:31 -0400
Subject: [PATCH] [Coverage][MC/DC] Emit MC/DC instrumentation for block bodies

GenerateBlockFunction() emits the block body without going through
EmitFunctionBody(), so call maybeCreateMCDCCondBitmap() to allocate a
condition bitmap.
---
 clang/lib/CodeGen/CGBlocks.cpp    |  1 +
 clang/test/Profile/c-mcdc-block.c | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 clang/test/Profile/c-mcdc-block.c

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

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

Reply via email to