Rust-GPU / Rust-GPU/rust-gpu

[Migrated] ZST's in structs cause invalid pointer casts

Open
#89 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
3.4k
Forks
125
PR merge metrics
No merged PRs in 30d

Description

Issue automatically imported from old repo: https://github.com/EmbarkStudios/rust-gpu/issues/1037
Old labels: t: bug,s: qptr may fix
Originally creatd by TrueDoctor on 2023-04-18T16:53:55Z


Expected Behaviour

The code should compile

Example & Steps To Reproduce

code:

 #[spirv(fragment)] 
 pub fn main(x: (usize, ())) {
    drop(&x.1); 
 }

result:

error: Cannot cast between pointer types
  --> examples/shaders/simplest-shader/src/lib.rs:44:55
   |
44 | #[spirv(fragment)] pub fn main(x: (usize, ())) { drop(&x.1); }
   |                                                       ^^^^
   |
   = note: from: *u32
   = note: to: *u8

error: Cannot offset a pointer to an arbitrary element
  --> examples/shaders/simplest-shader/src/lib.rs:44:55
   |
44 | #[spirv(fragment)] pub fn main(x: (usize, ())) { drop(&x.1); }
   |                                                       ^^^^

error: Cannot cast between pointer types
  --> examples/shaders/simplest-shader/src/lib.rs:44:50
   |
44 | #[spirv(fragment)] pub fn main(x: (usize, ())) { drop(&x.1); }
   |                                                  ^^^^^^^^^^
   |
   = note: from: *u8
   = note: to: *struct () {  }

System Info

  • Rust: [e.g. 1.49.0-nightly (1eaadebb3 2020-10-21)]
  • OS: linux 6.2.9-arch1-1
  • GPU: Intel Iris Plus Graphics G7

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 with the reproducer in examples/shaders/simplest-shader/src/lib.rs, especially the #[spirv(fragment)] function and the reference to x.1. Run the example and inspect the pointer-cast and arbitrary-offset errors. Done means this valid-looking struct containing a zero-sized tuple field compiles without those errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.