[llvm] [llvm-cov] Support LCOV exclusion markers (PR #220767)

Yaxun Liu via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 14:59:23 PDT 2026


================
@@ -0,0 +1,51 @@
+//===- CoverageExclusions.h - Source coverage exclusions -------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_COV_COVERAGEEXCLUSIONS_H
+#define LLVM_COV_COVERAGEEXCLUSIONS_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ProfileData/Coverage/CoverageMapping.h"
+#include "llvm/Support/Error.h"
+#include <utility>
+#include <vector>
+
+namespace llvm {
+
+class CoverageExclusions {
+public:
+  using LineRange = std::pair<unsigned, unsigned>;
+
+  Error parse(StringRef Filename, StringRef Source);
+
+  bool isLineExcluded(StringRef Filename, unsigned Line) const;
+
+  bool isRegionExcluded(const coverage::FunctionRecord &Function,
+                        const coverage::CounterMappingRegion &Region) const;
+
+  bool isFunctionExcluded(const coverage::FunctionRecord &Function,
----------------
yxsamliu wrote:

Yes. The existing exclusion test checks branch regions, and I added a focused MC/DC test in aad9a681: excluding a decision line removes its MC/DC record (12 to 8 conditions), while the other decisions remain. Both tests pass locally: https://github.com/llvm/llvm-project/blob/aad9a68181dfe80b31881a654f600926dc3c274e/llvm/test/tools/llvm-cov/lcov-exclusion-mcdc.test

https://github.com/llvm/llvm-project/pull/220767


More information about the llvm-commits mailing list