mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
Auto merge of #114360 - Zalathar:ffi-types, r=oli-obk
coverage: Consolidate FFI types into one module Coverage FFI types were historically split across two modules, because some of them were needed by code in `rustc_codegen_ssa`. Now that all of the coverage codegen code has been moved into `rustc_codegen_llvm` (#113355), it's possible to move all of the FFI types into a single module, making it easier to see all of them at once. --- This PR only moves code and adjusts imports; there should be no functional changes.
This commit is contained in:
commit
5cbfee5455
@ -85,3 +85,197 @@ impl CounterExpression {
|
|||||||
Self { kind, lhs, rhs }
|
Self { kind, lhs, rhs }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Corresponds to enum `llvm::coverage::CounterMappingRegion::RegionKind`.
|
||||||
|
///
|
||||||
|
/// Must match the layout of `LLVMRustCounterMappingRegionKind`.
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub enum RegionKind {
|
||||||
|
/// A CodeRegion associates some code with a counter
|
||||||
|
CodeRegion = 0,
|
||||||
|
|
||||||
|
/// An ExpansionRegion represents a file expansion region that associates
|
||||||
|
/// a source range with the expansion of a virtual source file, such as
|
||||||
|
/// for a macro instantiation or #include file.
|
||||||
|
ExpansionRegion = 1,
|
||||||
|
|
||||||
|
/// A SkippedRegion represents a source range with code that was skipped
|
||||||
|
/// by a preprocessor or similar means.
|
||||||
|
SkippedRegion = 2,
|
||||||
|
|
||||||
|
/// A GapRegion is like a CodeRegion, but its count is only set as the
|
||||||
|
/// line execution count when its the only region in the line.
|
||||||
|
GapRegion = 3,
|
||||||
|
|
||||||
|
/// A BranchRegion represents leaf-level boolean expressions and is
|
||||||
|
/// associated with two counters, each representing the number of times the
|
||||||
|
/// expression evaluates to true or false.
|
||||||
|
BranchRegion = 4,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This struct provides LLVM's representation of a "CoverageMappingRegion", encoded into the
|
||||||
|
/// coverage map, in accordance with the
|
||||||
|
/// [LLVM Code Coverage Mapping Format](https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/docs/CoverageMappingFormat.rst#llvm-code-coverage-mapping-format).
|
||||||
|
/// The struct composes fields representing the `Counter` type and value(s) (injected counter
|
||||||
|
/// ID, or expression type and operands), the source file (an indirect index into a "filenames
|
||||||
|
/// array", encoded separately), and source location (start and end positions of the represented
|
||||||
|
/// code region).
|
||||||
|
///
|
||||||
|
/// Corresponds to struct `llvm::coverage::CounterMappingRegion`.
|
||||||
|
///
|
||||||
|
/// Must match the layout of `LLVMRustCounterMappingRegion`.
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct CounterMappingRegion {
|
||||||
|
/// The counter type and type-dependent counter data, if any.
|
||||||
|
counter: Counter,
|
||||||
|
|
||||||
|
/// If the `RegionKind` is a `BranchRegion`, this represents the counter
|
||||||
|
/// for the false branch of the region.
|
||||||
|
false_counter: Counter,
|
||||||
|
|
||||||
|
/// An indirect reference to the source filename. In the LLVM Coverage Mapping Format, the
|
||||||
|
/// file_id is an index into a function-specific `virtual_file_mapping` array of indexes
|
||||||
|
/// that, in turn, are used to look up the filename for this region.
|
||||||
|
file_id: u32,
|
||||||
|
|
||||||
|
/// If the `RegionKind` is an `ExpansionRegion`, the `expanded_file_id` can be used to find
|
||||||
|
/// the mapping regions created as a result of macro expansion, by checking if their file id
|
||||||
|
/// matches the expanded file id.
|
||||||
|
expanded_file_id: u32,
|
||||||
|
|
||||||
|
/// 1-based starting line of the mapping region.
|
||||||
|
start_line: u32,
|
||||||
|
|
||||||
|
/// 1-based starting column of the mapping region.
|
||||||
|
start_col: u32,
|
||||||
|
|
||||||
|
/// 1-based ending line of the mapping region.
|
||||||
|
end_line: u32,
|
||||||
|
|
||||||
|
/// 1-based ending column of the mapping region. If the high bit is set, the current
|
||||||
|
/// mapping region is a gap area.
|
||||||
|
end_col: u32,
|
||||||
|
|
||||||
|
kind: RegionKind,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CounterMappingRegion {
|
||||||
|
pub(crate) fn code_region(
|
||||||
|
counter: Counter,
|
||||||
|
file_id: u32,
|
||||||
|
start_line: u32,
|
||||||
|
start_col: u32,
|
||||||
|
end_line: u32,
|
||||||
|
end_col: u32,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
counter,
|
||||||
|
false_counter: Counter::zero(),
|
||||||
|
file_id,
|
||||||
|
expanded_file_id: 0,
|
||||||
|
start_line,
|
||||||
|
start_col,
|
||||||
|
end_line,
|
||||||
|
end_col,
|
||||||
|
kind: RegionKind::CodeRegion,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function might be used in the future; the LLVM API is still evolving, as is coverage
|
||||||
|
// support.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub(crate) fn branch_region(
|
||||||
|
counter: Counter,
|
||||||
|
false_counter: Counter,
|
||||||
|
file_id: u32,
|
||||||
|
start_line: u32,
|
||||||
|
start_col: u32,
|
||||||
|
end_line: u32,
|
||||||
|
end_col: u32,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
counter,
|
||||||
|
false_counter,
|
||||||
|
file_id,
|
||||||
|
expanded_file_id: 0,
|
||||||
|
start_line,
|
||||||
|
start_col,
|
||||||
|
end_line,
|
||||||
|
end_col,
|
||||||
|
kind: RegionKind::BranchRegion,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function might be used in the future; the LLVM API is still evolving, as is coverage
|
||||||
|
// support.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub(crate) fn expansion_region(
|
||||||
|
file_id: u32,
|
||||||
|
expanded_file_id: u32,
|
||||||
|
start_line: u32,
|
||||||
|
start_col: u32,
|
||||||
|
end_line: u32,
|
||||||
|
end_col: u32,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
counter: Counter::zero(),
|
||||||
|
false_counter: Counter::zero(),
|
||||||
|
file_id,
|
||||||
|
expanded_file_id,
|
||||||
|
start_line,
|
||||||
|
start_col,
|
||||||
|
end_line,
|
||||||
|
end_col,
|
||||||
|
kind: RegionKind::ExpansionRegion,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function might be used in the future; the LLVM API is still evolving, as is coverage
|
||||||
|
// support.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub(crate) fn skipped_region(
|
||||||
|
file_id: u32,
|
||||||
|
start_line: u32,
|
||||||
|
start_col: u32,
|
||||||
|
end_line: u32,
|
||||||
|
end_col: u32,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
counter: Counter::zero(),
|
||||||
|
false_counter: Counter::zero(),
|
||||||
|
file_id,
|
||||||
|
expanded_file_id: 0,
|
||||||
|
start_line,
|
||||||
|
start_col,
|
||||||
|
end_line,
|
||||||
|
end_col,
|
||||||
|
kind: RegionKind::SkippedRegion,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function might be used in the future; the LLVM API is still evolving, as is coverage
|
||||||
|
// support.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub(crate) fn gap_region(
|
||||||
|
counter: Counter,
|
||||||
|
file_id: u32,
|
||||||
|
start_line: u32,
|
||||||
|
start_col: u32,
|
||||||
|
end_line: u32,
|
||||||
|
end_col: u32,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
counter,
|
||||||
|
false_counter: Counter::zero(),
|
||||||
|
file_id,
|
||||||
|
expanded_file_id: 0,
|
||||||
|
start_line,
|
||||||
|
start_col,
|
||||||
|
end_line,
|
||||||
|
end_col: (1_u32 << 31) | end_col,
|
||||||
|
kind: RegionKind::GapRegion,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
pub use super::ffi::*;
|
use crate::coverageinfo::ffi::{Counter, CounterExpression, ExprKind};
|
||||||
|
|
||||||
use rustc_index::{IndexSlice, IndexVec};
|
use rustc_index::{IndexSlice, IndexVec};
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
use crate::common::CodegenCx;
|
use crate::common::CodegenCx;
|
||||||
use crate::coverageinfo;
|
use crate::coverageinfo;
|
||||||
use crate::coverageinfo::map_data::{Counter, CounterExpression};
|
use crate::coverageinfo::ffi::{Counter, CounterExpression, CounterMappingRegion};
|
||||||
use crate::llvm;
|
use crate::llvm;
|
||||||
|
|
||||||
use llvm::coverageinfo::CounterMappingRegion;
|
|
||||||
use rustc_codegen_ssa::traits::ConstMethods;
|
use rustc_codegen_ssa::traits::ConstMethods;
|
||||||
use rustc_data_structures::fx::FxIndexSet;
|
use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
|
@ -3,10 +3,10 @@ use crate::llvm;
|
|||||||
use crate::abi::Abi;
|
use crate::abi::Abi;
|
||||||
use crate::builder::Builder;
|
use crate::builder::Builder;
|
||||||
use crate::common::CodegenCx;
|
use crate::common::CodegenCx;
|
||||||
use crate::coverageinfo::map_data::{CounterExpression, FunctionCoverage};
|
use crate::coverageinfo::ffi::{CounterExpression, CounterMappingRegion};
|
||||||
|
use crate::coverageinfo::map_data::FunctionCoverage;
|
||||||
|
|
||||||
use libc::c_uint;
|
use libc::c_uint;
|
||||||
use llvm::coverageinfo::CounterMappingRegion;
|
|
||||||
use rustc_codegen_ssa::traits::{
|
use rustc_codegen_ssa::traits::{
|
||||||
BaseTypeMethods, BuilderMethods, ConstMethods, CoverageInfoBuilderMethods, MiscMethods,
|
BaseTypeMethods, BuilderMethods, ConstMethods, CoverageInfoBuilderMethods, MiscMethods,
|
||||||
StaticMethods,
|
StaticMethods,
|
||||||
@ -27,7 +27,7 @@ use rustc_middle::ty::Ty;
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
|
|
||||||
mod ffi;
|
pub(crate) mod ffi;
|
||||||
pub(crate) mod map_data;
|
pub(crate) mod map_data;
|
||||||
pub mod mapgen;
|
pub mod mapgen;
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
#![allow(non_upper_case_globals)]
|
#![allow(non_upper_case_globals)]
|
||||||
|
|
||||||
use crate::coverageinfo::map_data as coverage_map;
|
|
||||||
|
|
||||||
use super::debuginfo::{
|
use super::debuginfo::{
|
||||||
DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator,
|
DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator,
|
||||||
DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DILocation, DINameSpace,
|
DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DILocation, DINameSpace,
|
||||||
@ -688,204 +686,6 @@ extern "C" {
|
|||||||
pub type DiagnosticHandlerTy = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);
|
pub type DiagnosticHandlerTy = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);
|
||||||
pub type InlineAsmDiagHandlerTy = unsafe extern "C" fn(&SMDiagnostic, *const c_void, c_uint);
|
pub type InlineAsmDiagHandlerTy = unsafe extern "C" fn(&SMDiagnostic, *const c_void, c_uint);
|
||||||
|
|
||||||
pub mod coverageinfo {
|
|
||||||
use super::coverage_map;
|
|
||||||
|
|
||||||
/// Corresponds to enum `llvm::coverage::CounterMappingRegion::RegionKind`.
|
|
||||||
///
|
|
||||||
/// Must match the layout of `LLVMRustCounterMappingRegionKind`.
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub enum RegionKind {
|
|
||||||
/// A CodeRegion associates some code with a counter
|
|
||||||
CodeRegion = 0,
|
|
||||||
|
|
||||||
/// An ExpansionRegion represents a file expansion region that associates
|
|
||||||
/// a source range with the expansion of a virtual source file, such as
|
|
||||||
/// for a macro instantiation or #include file.
|
|
||||||
ExpansionRegion = 1,
|
|
||||||
|
|
||||||
/// A SkippedRegion represents a source range with code that was skipped
|
|
||||||
/// by a preprocessor or similar means.
|
|
||||||
SkippedRegion = 2,
|
|
||||||
|
|
||||||
/// A GapRegion is like a CodeRegion, but its count is only set as the
|
|
||||||
/// line execution count when its the only region in the line.
|
|
||||||
GapRegion = 3,
|
|
||||||
|
|
||||||
/// A BranchRegion represents leaf-level boolean expressions and is
|
|
||||||
/// associated with two counters, each representing the number of times the
|
|
||||||
/// expression evaluates to true or false.
|
|
||||||
BranchRegion = 4,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This struct provides LLVM's representation of a "CoverageMappingRegion", encoded into the
|
|
||||||
/// coverage map, in accordance with the
|
|
||||||
/// [LLVM Code Coverage Mapping Format](https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/docs/CoverageMappingFormat.rst#llvm-code-coverage-mapping-format).
|
|
||||||
/// The struct composes fields representing the `Counter` type and value(s) (injected counter
|
|
||||||
/// ID, or expression type and operands), the source file (an indirect index into a "filenames
|
|
||||||
/// array", encoded separately), and source location (start and end positions of the represented
|
|
||||||
/// code region).
|
|
||||||
///
|
|
||||||
/// Corresponds to struct `llvm::coverage::CounterMappingRegion`.
|
|
||||||
///
|
|
||||||
/// Must match the layout of `LLVMRustCounterMappingRegion`.
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct CounterMappingRegion {
|
|
||||||
/// The counter type and type-dependent counter data, if any.
|
|
||||||
counter: coverage_map::Counter,
|
|
||||||
|
|
||||||
/// If the `RegionKind` is a `BranchRegion`, this represents the counter
|
|
||||||
/// for the false branch of the region.
|
|
||||||
false_counter: coverage_map::Counter,
|
|
||||||
|
|
||||||
/// An indirect reference to the source filename. In the LLVM Coverage Mapping Format, the
|
|
||||||
/// file_id is an index into a function-specific `virtual_file_mapping` array of indexes
|
|
||||||
/// that, in turn, are used to look up the filename for this region.
|
|
||||||
file_id: u32,
|
|
||||||
|
|
||||||
/// If the `RegionKind` is an `ExpansionRegion`, the `expanded_file_id` can be used to find
|
|
||||||
/// the mapping regions created as a result of macro expansion, by checking if their file id
|
|
||||||
/// matches the expanded file id.
|
|
||||||
expanded_file_id: u32,
|
|
||||||
|
|
||||||
/// 1-based starting line of the mapping region.
|
|
||||||
start_line: u32,
|
|
||||||
|
|
||||||
/// 1-based starting column of the mapping region.
|
|
||||||
start_col: u32,
|
|
||||||
|
|
||||||
/// 1-based ending line of the mapping region.
|
|
||||||
end_line: u32,
|
|
||||||
|
|
||||||
/// 1-based ending column of the mapping region. If the high bit is set, the current
|
|
||||||
/// mapping region is a gap area.
|
|
||||||
end_col: u32,
|
|
||||||
|
|
||||||
kind: RegionKind,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CounterMappingRegion {
|
|
||||||
pub(crate) fn code_region(
|
|
||||||
counter: coverage_map::Counter,
|
|
||||||
file_id: u32,
|
|
||||||
start_line: u32,
|
|
||||||
start_col: u32,
|
|
||||||
end_line: u32,
|
|
||||||
end_col: u32,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
counter,
|
|
||||||
false_counter: coverage_map::Counter::zero(),
|
|
||||||
file_id,
|
|
||||||
expanded_file_id: 0,
|
|
||||||
start_line,
|
|
||||||
start_col,
|
|
||||||
end_line,
|
|
||||||
end_col,
|
|
||||||
kind: RegionKind::CodeRegion,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This function might be used in the future; the LLVM API is still evolving, as is coverage
|
|
||||||
// support.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn branch_region(
|
|
||||||
counter: coverage_map::Counter,
|
|
||||||
false_counter: coverage_map::Counter,
|
|
||||||
file_id: u32,
|
|
||||||
start_line: u32,
|
|
||||||
start_col: u32,
|
|
||||||
end_line: u32,
|
|
||||||
end_col: u32,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
counter,
|
|
||||||
false_counter,
|
|
||||||
file_id,
|
|
||||||
expanded_file_id: 0,
|
|
||||||
start_line,
|
|
||||||
start_col,
|
|
||||||
end_line,
|
|
||||||
end_col,
|
|
||||||
kind: RegionKind::BranchRegion,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This function might be used in the future; the LLVM API is still evolving, as is coverage
|
|
||||||
// support.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn expansion_region(
|
|
||||||
file_id: u32,
|
|
||||||
expanded_file_id: u32,
|
|
||||||
start_line: u32,
|
|
||||||
start_col: u32,
|
|
||||||
end_line: u32,
|
|
||||||
end_col: u32,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
counter: coverage_map::Counter::zero(),
|
|
||||||
false_counter: coverage_map::Counter::zero(),
|
|
||||||
file_id,
|
|
||||||
expanded_file_id,
|
|
||||||
start_line,
|
|
||||||
start_col,
|
|
||||||
end_line,
|
|
||||||
end_col,
|
|
||||||
kind: RegionKind::ExpansionRegion,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This function might be used in the future; the LLVM API is still evolving, as is coverage
|
|
||||||
// support.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn skipped_region(
|
|
||||||
file_id: u32,
|
|
||||||
start_line: u32,
|
|
||||||
start_col: u32,
|
|
||||||
end_line: u32,
|
|
||||||
end_col: u32,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
counter: coverage_map::Counter::zero(),
|
|
||||||
false_counter: coverage_map::Counter::zero(),
|
|
||||||
file_id,
|
|
||||||
expanded_file_id: 0,
|
|
||||||
start_line,
|
|
||||||
start_col,
|
|
||||||
end_line,
|
|
||||||
end_col,
|
|
||||||
kind: RegionKind::SkippedRegion,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This function might be used in the future; the LLVM API is still evolving, as is coverage
|
|
||||||
// support.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn gap_region(
|
|
||||||
counter: coverage_map::Counter,
|
|
||||||
file_id: u32,
|
|
||||||
start_line: u32,
|
|
||||||
start_col: u32,
|
|
||||||
end_line: u32,
|
|
||||||
end_col: u32,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
counter,
|
|
||||||
false_counter: coverage_map::Counter::zero(),
|
|
||||||
file_id,
|
|
||||||
expanded_file_id: 0,
|
|
||||||
start_line,
|
|
||||||
start_col,
|
|
||||||
end_line,
|
|
||||||
end_col: (1_u32 << 31) | end_col,
|
|
||||||
kind: RegionKind::GapRegion,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod debuginfo {
|
pub mod debuginfo {
|
||||||
use super::{InvariantOpaque, Metadata};
|
use super::{InvariantOpaque, Metadata};
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
@ -1911,9 +1711,9 @@ extern "C" {
|
|||||||
pub fn LLVMRustCoverageWriteMappingToBuffer(
|
pub fn LLVMRustCoverageWriteMappingToBuffer(
|
||||||
VirtualFileMappingIDs: *const c_uint,
|
VirtualFileMappingIDs: *const c_uint,
|
||||||
NumVirtualFileMappingIDs: c_uint,
|
NumVirtualFileMappingIDs: c_uint,
|
||||||
Expressions: *const coverage_map::CounterExpression,
|
Expressions: *const crate::coverageinfo::ffi::CounterExpression,
|
||||||
NumExpressions: c_uint,
|
NumExpressions: c_uint,
|
||||||
MappingRegions: *const coverageinfo::CounterMappingRegion,
|
MappingRegions: *const crate::coverageinfo::ffi::CounterMappingRegion,
|
||||||
NumMappingRegions: c_uint,
|
NumMappingRegions: c_uint,
|
||||||
BufferOut: &RustString,
|
BufferOut: &RustString,
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user