rust-lang / rust-lang/rust-bindgen

bindgen fails to correctly convert the `~0ul` constant on i368 architecture

Open
#2,965 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

We have header files with the following definition, which should use the largest unsigned long value:

#define CK_UNAVAILABLE_INFORMATION ~0UL

These are different on 32b and 64b architectures (not our choice of types)

When bindgen processes this inptut, it generates the following line of rust code:

pub const CK_UNAVAILABLE_INFORMATION: CK_ULONG = 18446744073709551615;

which is obviously wrong as the rust compiler will very soon figure out:

 --> src/conformance/../pkcs11/bindings.rs:7:50
  |
7 | pub const CK_UNAVAILABLE_INFORMATION: CK_ULONG = 18446744073709551615;
  |                                                  ^^^^^^^^^^^^^^^^^^^^
  |
  = note: the literal `18446744073709551615` does not fit into the type `u32` whose range is `0..=4294967295`
  = note: `#[deny(overflowing_literals)]` on by default

This happens both with 0.69 and 0.70 versions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with bindgen 0.69 or 0.70 using a header defining CK_UNAVAILABLE_INFORMATION as ~0UL on both 32-bit and 64-bit targets. Compare the generated Rust constant with CK_ULONG's target-specific range; done means the generated bindings compile correctly on both architectures.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.