Nonzero pointer address spaces are silently erased in generated bindings and static wrappers
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Reproduce the issue with input.h, the shown bindgen invocation, and the generated bindings.rs and wrapper outputs. Trace how nonzero address spaces are represented in generated Rust declarations and static-function C wrappers. Done means the output preserves the address space where supported, or diagnoses and omits an unrepresentable Rust declaration, with Clang accepting the wrapper.
Written by the indexing model from the issue text.
Description
Input C/C++ Header
static inline int __attribute__((address_space(1))) *
phase8_as1_identity(
int __attribute__((address_space(1))) *value
) {
return value;
}
Clang accepts this declaration on the target used below. The function takes
and returns an address space 1 pointer.
Bindgen Invocation
$ bindgen input.h \
--wrap-static-fns \
--wrap-static-fns-path wrapper \
--rust-target 1.75 \
--no-layout-tests \
--no-rustfmt-bindings \
--output bindings.rs
Actual Results
The generated Rust declaration silently uses ordinary pointers:
extern "C" {
#[link_name = "phase8_as1_identity__extern"]
pub fn phase8_as1_identity(
value: *mut ::std::os::raw::c_int,
) -> *mut ::std::os::raw::c_int;
}
The generated C wrapper drops the address space too:
int *phase8_as1_identity__extern(int *value) {
return phase8_as1_identity(value);
}
Clang rejects that wrapper:
error: passing 'int *' to parameter of type
'__attribute__((address_space(1))) int *' changes address space of pointer
The two declarations also lower to different LLVM function types. These are
the signatures from the tools listed below:
; clang-15, correct C wrapper
define dso_local i32 addrspace(1)* @phase8_as1_identity__extern(
i32 addrspace(1)* %value)
; rustc 1.75, caller using the generated binding
declare noundef ptr @phase8_as1_identity__extern(ptr noundef)
Expected Results
Bindgen should not emit an ordinary pointer for a nonzero address space.
The C wrapper can preserve the source declaration:
int __attribute__((address_space(1))) *
phase8_as1_identity__extern(
int __attribute__((address_space(1))) *value
) {
return phase8_as1_identity(value);
}
Stable Rust does not have a general source-level pointer type for arbitrary
LLVM address spaces. If the selected Rust output cannot represent this type,
I would expect bindgen to diagnose it and omit the misleading declaration
instead of changing it to *mut c_int.
Environment
bindgen current main: 9d26c6eddeff9192ddedb563192abe3128fc5aae
bindgen release: 0.72.1
clang: 15.0.7
rustc: 1.75.0
target: x86_64-unknown-linux-gnu
Current main and 0.72.1 both generate the same invalid wrapper at O0 and O2.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 846
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 11
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rust-lang/rust-bindgen
-
--enable-cxx-namespaces panics on namespace [[deprecated]] { ("[" is not a valid Ident)Possibly taken @lwz23 claimed this 47 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
rust-lang/rust-bindgen#3485 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rust-lang/rust-bindgen#3483 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
rust-lang/rust-bindgen#3370 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
rust-lang/rust-bindgen#3363 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
rust-lang/rust-bindgen#3540 ·
Maintainers usually reply within 1 day
All issues in rust-lang/rust-bindgen
Similar issues
-
bug priority: medium
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
storytold/photocraft#12706 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
IngvarConsulting/unica#2822 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100