summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/coverageinfo
AgeCommit message (Collapse)AuthorLines
2024-11-10Rollup merge of #132675 - Zalathar:empty-spans, r=jieyouxuMatthias Krüger-67/+81
coverage: Restrict empty-span expansion to only cover `{` and `}` Coverage instrumentation has some tricky code for converting a coverage-relevant `Span` into a set of start/end line/byte-column coordinates that will be embedded in the CGU's coverage metadata. A big part of this complexity is special code for handling empty spans, which are expanded into non-empty spans (if possible) because LLVM's coverage reporter does not handle empty spans well. This PR simplifies that code by restricting it to only apply in two specific situations: when the character after the empty span is `{`, or the character before the empty span is `}`. (As an added benefit, this means that the expanded spans no longer extend awkwardly beyond the end of a physical line, which was common under the previous implementation.) Along the way, this PR also removes some unhelpful code for dealing with function source code spread across multiple files. Functions currently can't have coverage spans in multiple files, and if that ever changes (e.g. to properly support expansion regions) then this code will need to be completely overhauled anyway.
2024-11-10coverage: Pass a `LocalFileId` to `CoverageSpan::from_source_region`Zalathar-3/+9
2024-11-08coverage: Remove unhelpful code for handling multiple files per functionZalathar-59/+57
Functions currently can't have mappings in multiple files, and if that ever changes (e.g. to properly support expansion regions), this code will need to be completely overhauled anyway.
2024-11-08coverage: Add `GlobalFileId` for stricter type-checking of file IDsZalathar-7/+17
We already had a dedicated `LocalFileId` index type, but previously we used a raw `u32` for global file IDs, because index types were harder to pass through FFI.
2024-11-05coverage: Tidy up coverage-specific FFI functionsZalathar-14/+12
2024-11-05coverage: Extract safe FFI wrapper functions to `llvm_cov`Zalathar-126/+132
2024-11-03compiler: Directly use rustc_abi in codegenJubilee Young-1/+1
2024-10-31coverage: Avoid ICE when `coverage_cx` is unexpectedly unavailableZalathar-2/+11
2024-10-28Use a type-safe helper to cast `&str` and `&[u8]` to `*const c_char`Zalathar-4/+4
2024-10-26Rollup merge of #132124 - Zalathar:consolidate-covstar, r=jieyouxu许杰友 Jieyou Xu (Joe)-140/+98
coverage: Consolidate creation of covmap/covfun records This code for creating covmap/covfun records during codegen was split across multiple functions and files for dubious historical reasons. Having it all in one place makes it easier to follow. This PR also includes two semi-related cleanups: - Getting the codegen context's `coverage_cx` state is made infallible, since it should always exist when running the code paths that need it. - The value of `covfun_section_name` is saved in the codegen context, since it never changes at runtime, and the code that needs it has access to the context anyway. --- Background: Coverage instrumentation generates two kinds of metadata that are embedded in the final binary. There is per-CGU information that goes in the `__llvm_covmap` linker section, and per-function information that goes in the `__llvm_covfun` section (except on Windows, where slightly different section names are used).
2024-10-26coverage: Add links to LLVM docs for the coverage mapping formatZalathar-0/+2
2024-10-25coverage: Emit MC/DC intrinsics using the normal helper methodZalathar-0/+1
2024-10-25coverage: Store `covfun_section_name` in the codegen contextZalathar-27/+24
Adding an extra `OnceCell` to `CrateCoverageContext` is much nicer than trying to thread this string through multiple layers of function calls that already have access to the context.
2024-10-25coverage: Make obtaining the codegen coverage context infallibleZalathar-29/+12
In all the situations where this context is needed, it should always be available.
2024-10-25coverage: Consolidate creation of covmap/covfun recordsZalathar-88/+64
There is no need for this code to be split across multiple functions in multiple files.
2024-10-24Rollup merge of #131956 - Zalathar:llvm-counters, r=compiler-errors,SwatinemStuart Cook-343/+113
coverage: Pass coverage mappings to LLVM as separate structs Instead of trying to cram *N* different kinds of coverage mapping data into a single list for FFI, pass *N* different lists of simpler structs. This avoids the need to fill unused fields with dummy values, and avoids the need to tag structs with their underlying kind. It also lets us call the dedicated LLVM constructors for each different mapping type, instead of having to go through the complex general-purpose constructor. Even though this adds multiple new structs to the FFI surface area, the resulting C++ code is simpler and shorter. --- I've structured this mostly as a single atomic patch, rather than a series of incremental changes, because that avoids the need to make fiddly fixes to code that is about to be deleted anyway.
2024-10-20Make `llvm::set_section` take a `&CStr`Zalathar-10/+12
2024-10-20Pass coverage mappings to LLVM as separate structsZalathar-334/+104
2024-10-20Reduce visibility of coverage FFI functions/typesZalathar-10/+10
2024-10-19cg_llvm: Reuse LLVM-C Comdat supportJubilee Young-1/+4
Migrate `llvm::set_comdat` and `llvm::SetUniqueComdat` to LLVM-C FFI. Note, now we can call `llvm::set_comdat` only when the target actually supports adding comdat. As this has no convenient LLVM-C API, we implement this as `TargetOptions::supports_comdat`. Co-authored-by: Stuart Cook <Zalathar@users.noreply.github.com>
2024-10-18cg_llvm: Switch `llvm::add_global` to `&CStr`Jubilee Young-6/+8
2024-10-11coverage: Remove code related to LLVM 17Zalathar-15/+6
2024-10-08coverage. Adapt to mcdc mapping formats introduced by llvm 19zhuyunxing-18/+11
2024-10-08coverage. MCDC ConditionId start from 0 to keep with llvm 19zhuyunxing-6/+7
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-3/+3
2024-09-19Reformat some comments.Nicholas Nethercote-8/+8
So they are less than 100 chars.
2024-09-17Rename supertraits of `CodegenMethods`.Nicholas Nethercote-3/+3
Supertraits of `BuilderMethods` are all called `XyzBuilderMethods`. Supertraits of `CodegenMethods` are all called `XyzMethods`. This commit changes the latter to `XyzCodegenMethods`, for consistency.
2024-09-02chore: Fix typos in 'compiler' (batch 1)Alexander Cyon-1/+1
2024-08-28coverage: Rename `CodeRegion` to `SourceRegion`Zalathar-9/+10
LLVM uses the word "code" to refer to a particular kind of coverage mapping. This unrelated usage of the word is confusing, and makes it harder to introduce types whose names correspond to the LLVM classification of coverage kinds.
2024-08-16Add `warn(unreachable_pub)` to `rustc_codegen_llvm`.Nicholas Nethercote-18/+18
2024-07-29Reformat `use` declarations.Nicholas Nethercote-17/+14
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-15coverage: Restrict `ExpressionUsed` simplification to `Code` mappingsZalathar-2/+9
In the future, branch and MC/DC mappings might have expressions that don't correspond to any single point in the control-flow graph. That makes it trickier to keep track of which expressions should expect an `ExpressionUsed` node. We therefore sidestep that complexity by only performing `ExpressionUsed` simplification for expressions associated directly with ordinary `Code` mappings.
2024-05-30coverage: Rename MC/DC `conditions_num` to `num_conditions`Zalathar-3/+4
This value represents a quantity of conditions, not an ID, so the new spelling is more appropriate.
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_codegen_llvm`.Nicholas Nethercote-0/+3
2024-05-14coverage: `CoverageIdsInfo::mcdc_bitmap_bytes` is never neededZalathar-6/+1
This code for recalculating `mcdc_bitmap_bytes` doesn't provide any benefit, because its result won't have changed from the value in `FunctionCoverageInfo` that was computed during the MIR instrumentation pass.
2024-05-01coverage: Replace `max_decision_depth` with `num_condition_bitmaps`Zalathar-1/+1
This clearly distinguishes individual decision-depth indices from the total number of condition bitmaps to allocate.
2024-05-01coverage: Set up MC/DC bitmaps without additional unsafe codeZalathar-5/+15
Because this now always takes place at the start of the function, we can just use the normal `alloca` method and then initialize each bitmap immediately. This patch also moves bitmap setup out of the `mcdc_parameters` method, because there is no longer any particular reason for it to be there.
2024-05-01coverage: Eagerly do start-of-function codegen for coverageZalathar-27/+27
2024-04-29mcdc-coverage: Get decision_depth from THIR loweringDorian Péron-1/+2
Use decision context stack to handle nested decisions: - Introduce MCDCDecisionCtx - Use a stack of MCDCDecisionCtx to handle nested decisions
2024-04-29mcdc-coverage: Add decision_depth field in structsDorian Péron-4/+4
Add decision_depth field to TVBitmapUpdate/CondBitmapUpdate statements Add decision_depth field to BcbMappingKinds MCDCBranch and MCDCDecision Add decision_depth field to MCDCBranchSpan and MCDCDecisionSpan
2024-04-29mcdc-coverage: Add possibility for codegen llvm to handle several condition ↵Dorian Péron-7/+18
bitmaps
2024-04-20coverage. Lowering MC/DC statements to llvm-irzhuyunxing-1/+69
2024-04-19coverage. Generate Mappings of decisions and conditions for MC/DCzhuyunxing-1/+157
2024-04-04Auto merge of #123455 - matthiaskrgr:rollup-b6nu296, r=matthiaskrgrbors-4/+4
Rollup of 9 pull requests Successful merges: - #121546 (Error out of layout calculation if a non-last struct field is unsized) - #122448 (Port hir-tree run-make test to ui test) - #123212 (CFI: Change type transformation to use TypeFolder) - #123218 (Add test for getting parent HIR for synthetic HIR node) - #123324 (match lowering: make false edges more precise) - #123389 (Avoid panicking unnecessarily on startup) - #123397 (Fix diagnostic for qualifier in extern block) - #123431 (Stabilize `proc_macro_byte_character` and `proc_macro_c_str_literals`) - #123439 (coverage: Remove useless constants) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-04coverage: Remove useless constantsZalathar-4/+4
2024-04-03coverage: Correctly report and check LLVM's coverage mapping versionZalathar-9/+20
2024-04-01Auto merge of #122972 - beetrees:use-align-type, r=fee1-deadbors-3/+4
Use the `Align` type when parsing alignment attributes Use the `Align` type in `rustc_attr::parse_alignment`, removing the need to call `Align::from_bytes(...).unwrap()` later in the compilation process.
2024-04-01Use the `Align` type when parsing alignment attributesbeetrees-3/+4
2024-03-28Replace `RemapFileNameExt::for_codegen` with explicit callsUrgau-1/+7
2024-03-26coverage: Detect functions that have lost all their coverage statementsZalathar-4/+18
If a function was instrumented for coverage, but all of its coverage statements have been removed by later MIR transforms, it should be treated as "unused" even if the compiler generates an unreachable stub for it.