Skip to content

Populate llvm.reserved from release LLVM IR bounds-check retention analysis#4

Merged
Coursant merged 6 commits intoSymbexpr-Cfrom
copilot/check-llvm-bounds-elimination-again
Mar 22, 2026
Merged

Populate llvm.reserved from release LLVM IR bounds-check retention analysis#4
Coursant merged 6 commits intoSymbexpr-Cfrom
copilot/check-llvm-bounds-elimination-again

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 22, 2026

bounds_checks_<crate>.json previously emitted llvm.reserved as an empty placeholder. This change makes llvm.reserved reflect whether MIR-discovered bounds checks are still retained after release LLVM lowering by deriving retention from emitted LLVM IR metadata.

  • llvm.reserved now carries LLVM-derived retention data

    • Replaced placeholder {} with structured output:
      • analysis: "llvm-ir-release"
      • records: [{ file, line, function, retained }]
    • retained is computed by matching source lines of MIR bounds-check records against LLVM panic callsites.
  • Release IR generation integrated into DB construction

    • During bounds DB dump, RAP invokes:
      • cargo rustc --release -- -Cdebuginfo=1 --emit=llvm-ir
    • Wrapper-specific env (RUSTC_WRAPPER, RAP_ARGS) is removed for this subprocess so IR emission is direct and deterministic.
  • LLVM IR parsing and source mapping

    • Scans target/release/deps/*.ll (respects CARGO_TARGET_DIR when set).
    • Detects bounds-check panic symbols (panic_bounds_check, slice_index_len_fail).
    • Resolves !dbg !N!DILocation(line: X, ...) to map retained checks back to source line numbers.
    • Supports multiple !dbg refs per instruction line.
  • Failure mode made explicit

    • If IR generation/parsing fails, llvm.reserved is still populated with:
      • analysis
      • error
      • empty records
    • This avoids silent placeholder output and preserves diagnosability.
  • Parser-focused unit coverage

    • Added tests for:
      • panic call with debug metadata mapping to retained source line
      • panic call without debug metadata producing no retained line mapping

Example output shape:

{
  "llvm": {
    "reserved": {
      "analysis": "llvm-ir-release",
      "records": [
        {
          "file": "src/lib.rs",
          "line": 42,
          "function": "my_crate::foo",
          "retained": true
        }
      ]
    }
  }
}

⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

Copilot AI self-assigned this Mar 22, 2026
Copilot AI changed the title [WIP] Explain how to check if bounds check elimination is performed by LLVM Clarify release-mode LLVM BCE verification workflow in range_assert Mar 22, 2026
Copilot AI requested a review from Coursant March 22, 2026 06:02
Copilot AI changed the title Clarify release-mode LLVM BCE verification workflow in range_assert Populate llvm.reserved from release LLVM IR bounds-check retention analysis Mar 22, 2026
@Coursant Coursant marked this pull request as ready for review March 22, 2026 11:41
@Coursant Coursant merged commit 6e136dd into Symbexpr-C Mar 22, 2026
0 of 2 checks passed
@Coursant Coursant deleted the copilot/check-llvm-bounds-elimination-again branch March 23, 2026 07:48
Coursant added a commit that referenced this pull request Mar 23, 2026
…-elimination-again"

This reverts commit 6e136dd, reversing
changes made to 51a6dcd.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants