[llvm] [llvm-cov] Add FileID to MCDC records of the json code coverage export (PR #145236)
Roman Beliaev via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 22 07:28:11 PDT 2025
https://github.com/belyaevrd created https://github.com/llvm/llvm-project/pull/145236
At the moment MCDC Record contains ExpandedFileID. If FileID != ExpandedFileID, the record's lines LineStart and LineEnd relate to the `FileID` file, but the record doesn't contain this id. So we can't distinguish multiple MCDC records with the same lines and columns, but different FileIDs.
This adds FileID to MCDC records as it is done for regions and branches.
>From 04089970ead210cba94e0b2bd6a499085fbb29f1 Mon Sep 17 00:00:00 2001
From: Roman Beliaev <belyaevdr at mail.ru>
Date: Sun, 22 Jun 2025 16:51:07 +0300
Subject: [PATCH] [llvm-cov] Add FileID to MCDC records of the json code
coverage export
At the moment MCDC Record contains ExpandedFileID. If FileID != ExpandedFileID,
the record's lines LineStart and LineEnd relate to the `FileID` file, but the
record doesn't contain this id. So we can't distinguish multiple MCDC records
with the same lines and columns, but different FileIDs.
This adds FileID to MCDC records as it is done for regions and branches.
---
.../tools/llvm-cov/Inputs/binary-formats.canonical.json | 2 +-
llvm/test/tools/llvm-cov/mcdc-export-json.test | 8 ++++----
llvm/tools/llvm-cov/CoverageExporterJson.cpp | 6 +++---
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/llvm/test/tools/llvm-cov/Inputs/binary-formats.canonical.json b/llvm/test/tools/llvm-cov/Inputs/binary-formats.canonical.json
index 33c517da91b5e..ae9c1509010af 100644
--- a/llvm/test/tools/llvm-cov/Inputs/binary-formats.canonical.json
+++ b/llvm/test/tools/llvm-cov/Inputs/binary-formats.canonical.json
@@ -33,4 +33,4 @@ CHECK-SAME: "mcdc":{"count":0,"covered":0,"notcovered":0,"percent":0},
CHECK-SAME: "regions":{"count":1,"covered":1,"notcovered":0,"percent":100}}}
CHECK-SAME: ],
CHECK-SAME: "type":"llvm.coverage.json.export"
-CHECK-SAME: "version":"2.0.1"
+CHECK-SAME: "version":"2.0.2"
diff --git a/llvm/test/tools/llvm-cov/mcdc-export-json.test b/llvm/test/tools/llvm-cov/mcdc-export-json.test
index c2cebf52db8cc..30c1af06df3a6 100644
--- a/llvm/test/tools/llvm-cov/mcdc-export-json.test
+++ b/llvm/test/tools/llvm-cov/mcdc-export-json.test
@@ -1,10 +1,10 @@
// RUN: llvm-profdata merge %S/Inputs/mcdc-general.proftext -o %t.profdata
// RUN: llvm-cov export --format=text %S/Inputs/mcdc-general.o -instr-profile %t.profdata | FileCheck %s
-// CHECK: 12,7,12,27,0,5,[true,true,true,true]
-// CHECK: 15,7,15,13,0,5,[true,true]
-// CHECK: 15,19,15,25,0,5,[true,false]
-// CHECK: 18,7,19,15,0,5,[true,true,false,true]
+// CHECK: 12,7,12,27,0,0,5,[true,true,true,true]
+// CHECK: 15,7,15,13,0,0,5,[true,true]
+// CHECK: 15,19,15,25,0,0,5,[true,false]
+// CHECK: 18,7,19,15,0,0,5,[true,true,false,true]
// CHECK: "mcdc":{"count":12,"covered":10,"notcovered":2,"percent":83.333333333333343}
Instructions for regenerating the test:
diff --git a/llvm/tools/llvm-cov/CoverageExporterJson.cpp b/llvm/tools/llvm-cov/CoverageExporterJson.cpp
index 4088c1b053aa8..0fa151a0b7ab7 100644
--- a/llvm/tools/llvm-cov/CoverageExporterJson.cpp
+++ b/llvm/tools/llvm-cov/CoverageExporterJson.cpp
@@ -62,7 +62,7 @@
#include <utility>
/// The semantic version combined as a string.
-#define LLVM_COVERAGE_EXPORT_JSON_STR "2.0.1"
+#define LLVM_COVERAGE_EXPORT_JSON_STR "2.0.2"
/// Unique type identifier for JSON coverage export.
#define LLVM_COVERAGE_EXPORT_JSON_TYPE_STR "llvm.coverage.json.export"
@@ -110,8 +110,8 @@ json::Array gatherConditions(const coverage::MCDCRecord &Record) {
json::Array renderMCDCRecord(const coverage::MCDCRecord &Record) {
const llvm::coverage::CounterMappingRegion &CMR = Record.getDecisionRegion();
- return json::Array({CMR.LineStart, CMR.ColumnStart, CMR.LineEnd,
- CMR.ColumnEnd, CMR.ExpandedFileID, int64_t(CMR.Kind),
+ return json::Array({CMR.LineStart, CMR.ColumnStart, CMR.LineEnd, CMR.ColumnEnd,
+ CMR.FileID, CMR.ExpandedFileID, int64_t(CMR.Kind),
gatherConditions(Record)});
}
More information about the llvm-commits
mailing list