Skip to content

Conversation

Zalathar
Copy link
Contributor

As explained by a note in ffi.rs, passing strings and byte slices through FFI is more convenient if we take advantage of the fact that *const c_uchar and *const c_char have the same ABI.

Doing so avoids having to rely on a special helper function, since we can just call as_ptr instead.

(The same logic applies to every other binding that currently uses the as_c_char_ptr helper; I just haven't adjusted all of them yet.)


As a drive-by change, this PR also marks some coverage-related FFI bindings as safe.

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 16, 2025

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@BoxyUwU
Copy link
Member

BoxyUwU commented Sep 16, 2025

r? compiler

@rustbot rustbot assigned SparrowLii and unassigned BoxyUwU Sep 16, 2025
@SparrowLii
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 30, 2025

📌 Commit 06a7460 has been approved by SparrowLii

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 30, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 30, 2025
cg_llvm: Stop using `as_c_char_ptr` for coverage-related bindings

[As explained by a note in `ffi.rs`](https://github.com/rust-lang/rust/blob/8a1b39995e5b630c5872f5de5079f1f569bd5ac2/compiler/rustc_codegen_llvm/src/llvm/ffi.rs#L4-L11), passing strings and byte slices through FFI is more convenient if we take advantage of the fact that `*const c_uchar` and `*const c_char` have the same ABI.

Doing so avoids having to rely on a special helper function, since we can just call `as_ptr` instead.

(The same logic applies to every other binding that currently uses the `as_c_char_ptr` helper; I just haven't adjusted all of them yet.)

---

As a drive-by change, this PR also marks some coverage-related FFI bindings as `safe`.
bors added a commit that referenced this pull request Sep 30, 2025
Rollup of 4 pull requests

Successful merges:

 - #146518 (Improve the documentation around `ZERO_AR_DATE`)
 - #146596 (Add a dummy codegen backend)
 - #146617 (Don’t suggest foreign `doc(hidden)` types in "the following other types implement trait" diagnostics)
 - #146635 (cg_llvm: Stop using `as_c_char_ptr` for coverage-related bindings)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Sep 30, 2025
Rollup of 6 pull requests

Successful merges:

 - #143069 (Add fast-path for accessing the current thread id)
 - #146518 (Improve the documentation around `ZERO_AR_DATE`)
 - #146596 (Add a dummy codegen backend)
 - #146617 (Don’t suggest foreign `doc(hidden)` types in "the following other types implement trait" diagnostics)
 - #146635 (cg_llvm: Stop using `as_c_char_ptr` for coverage-related bindings)
 - #147184 (Fix the bevy implied bounds hack for the next solver)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Oct 1, 2025
Rollup of 6 pull requests

Successful merges:

 - #143069 (Add fast-path for accessing the current thread id)
 - #146518 (Improve the documentation around `ZERO_AR_DATE`)
 - #146596 (Add a dummy codegen backend)
 - #146617 (Don’t suggest foreign `doc(hidden)` types in "the following other types implement trait" diagnostics)
 - #146635 (cg_llvm: Stop using `as_c_char_ptr` for coverage-related bindings)
 - #147184 (Fix the bevy implied bounds hack for the next solver)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b21c438 into rust-lang:master Oct 1, 2025
10 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 1, 2025
rust-timer added a commit that referenced this pull request Oct 1, 2025
Rollup merge of #146635 - Zalathar:llvm-cov, r=SparrowLii

cg_llvm: Stop using `as_c_char_ptr` for coverage-related bindings

[As explained by a note in `ffi.rs`](https://github.com/rust-lang/rust/blob/8a1b39995e5b630c5872f5de5079f1f569bd5ac2/compiler/rustc_codegen_llvm/src/llvm/ffi.rs#L4-L11), passing strings and byte slices through FFI is more convenient if we take advantage of the fact that `*const c_uchar` and `*const c_char` have the same ABI.

Doing so avoids having to rely on a special helper function, since we can just call `as_ptr` instead.

(The same logic applies to every other binding that currently uses the `as_c_char_ptr` helper; I just haven't adjusted all of them yet.)

---

As a drive-by change, this PR also marks some coverage-related FFI bindings as `safe`.
@Zalathar Zalathar deleted the llvm-cov branch October 1, 2025 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants