about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-11-29 14:52:41 +1100
committerZalathar <Zalathar@users.noreply.github.com>2024-11-29 14:57:01 +1100
commit9461f4296ffcbd75440ec211ead7bff6fb86012c (patch)
tree4855cb6a7cc7ddb6c3de368750840ac255f387be /compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs
parentd53f0b1d8e261f2f3535f1cd165c714fc0b0b298 (diff)
downloadrust-9461f4296ffcbd75440ec211ead7bff6fb86012c.tar.gz
rust-9461f4296ffcbd75440ec211ead7bff6fb86012c.zip
Revert "Rollup merge of #133418 - Zalathar:spans, r=jieyouxu"
This reverts commit adf9b5fcd1de43eaf0a779e10612caee8b47bede, reversing
changes made to af1ca153d4aed5ffe22445273aa388a8d3f8f4ae.

Reverting due to <https://github.com/rust-lang/rust/issues/133606>.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs')
-rw-r--r--compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs36
1 files changed, 26 insertions, 10 deletions
diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs
index 19d6726002c..a6e07ea2a60 100644
--- a/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs
+++ b/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs
@@ -1,4 +1,6 @@
-use rustc_middle::mir::coverage::{CounterId, CovTerm, ExpressionId};
+use rustc_middle::mir::coverage::{CounterId, CovTerm, ExpressionId, SourceRegion};
+
+use crate::coverageinfo::mapgen::LocalFileId;
 
 /// Must match the layout of `LLVMRustCounterKind`.
 #[derive(Copy, Clone, Debug)]
@@ -124,23 +126,37 @@ pub(crate) struct CoverageSpan {
     /// Local index into the function's local-to-global file ID table.
     /// The value at that index is itself an index into the coverage filename
     /// table in the CGU's `__llvm_covmap` section.
-    pub(crate) file_id: u32,
+    file_id: u32,
 
     /// 1-based starting line of the source code span.
-    pub(crate) start_line: u32,
+    start_line: u32,
     /// 1-based starting column of the source code span.
-    pub(crate) start_col: u32,
+    start_col: u32,
     /// 1-based ending line of the source code span.
-    pub(crate) end_line: u32,
+    end_line: u32,
     /// 1-based ending column of the source code span. High bit must be unset.
-    pub(crate) end_col: u32,
+    end_col: u32,
+}
+
+impl CoverageSpan {
+    pub(crate) fn from_source_region(
+        local_file_id: LocalFileId,
+        code_region: &SourceRegion,
+    ) -> Self {
+        let file_id = local_file_id.as_u32();
+        let &SourceRegion { start_line, start_col, end_line, end_col } = code_region;
+        // Internally, LLVM uses the high bit of `end_col` to distinguish between
+        // code regions and gap regions, so it can't be used by the column number.
+        assert!(end_col & (1u32 << 31) == 0, "high bit of `end_col` must be unset: {end_col:#X}");
+        Self { file_id, start_line, start_col, end_line, end_col }
+    }
 }
 
 /// Must match the layout of `LLVMRustCoverageCodeRegion`.
 #[derive(Clone, Debug)]
 #[repr(C)]
 pub(crate) struct CodeRegion {
-    pub(crate) cov_span: CoverageSpan,
+    pub(crate) span: CoverageSpan,
     pub(crate) counter: Counter,
 }
 
@@ -148,7 +164,7 @@ pub(crate) struct CodeRegion {
 #[derive(Clone, Debug)]
 #[repr(C)]
 pub(crate) struct BranchRegion {
-    pub(crate) cov_span: CoverageSpan,
+    pub(crate) span: CoverageSpan,
     pub(crate) true_counter: Counter,
     pub(crate) false_counter: Counter,
 }
@@ -157,7 +173,7 @@ pub(crate) struct BranchRegion {
 #[derive(Clone, Debug)]
 #[repr(C)]
 pub(crate) struct MCDCBranchRegion {
-    pub(crate) cov_span: CoverageSpan,
+    pub(crate) span: CoverageSpan,
     pub(crate) true_counter: Counter,
     pub(crate) false_counter: Counter,
     pub(crate) mcdc_branch_params: mcdc::BranchParameters,
@@ -167,6 +183,6 @@ pub(crate) struct MCDCBranchRegion {
 #[derive(Clone, Debug)]
 #[repr(C)]
 pub(crate) struct MCDCDecisionRegion {
-    pub(crate) cov_span: CoverageSpan,
+    pub(crate) span: CoverageSpan,
     pub(crate) mcdc_decision_params: mcdc::DecisionParameters,
 }