Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wgsl-in] Incorrect handling of negative integers with hex values #4492

Closed
Wumpf opened this issue Apr 24, 2023 · 2 comments · Fixed by #4870
Closed

[wgsl-in] Incorrect handling of negative integers with hex values #4492

Wumpf opened this issue Apr 24, 2023 · 2 comments · Fixed by #4870
Labels
area: naga front-end lang: WGSL WebGPU Shading Language naga Shader Translator type: bug Something isn't working

Comments

@Wumpf
Copy link
Member

Wumpf commented Apr 24, 2023

The following isn't accepted right now (note that this is how the spec defines the minimum integer https://www.w3.org/TR/WGSL/#integer-types)

const i32min = i32(-0x80000000);

Instead this is accepted and probably shouldn't:

const i32min = -0x80000000i

In fact, Tint will fail this with:

Tint WGSL reader failure: :24:17 error: value cannot be represented as 'i32'
const i32min = -0x80000000i; // Tint can't handle this being represented as `-0x80000000i`

I thought originally that this is the actual error, but I think the reasoning over at the chrome bug I opened is correct and above should be rejected, see https://bugs.chromium.org/p/chromium/issues/detail?id=1439274

For anyone else running into this, note that const i32min = -2147483648; is accepted by both compilers.

@teoxoy
Copy link
Member

teoxoy commented Sep 29, 2023

gfx-rs/naga#1863 fixed us not accepting:

const i32min = i32(-0x80000000);

const i32min = -0x80000000i;

Still works and shouldn't but will be fixed with #4400 since we currently treat the minus as part of the number when tokenizing.

@cwfitzgerald cwfitzgerald transferred this issue from gfx-rs/naga Oct 25, 2023
@cwfitzgerald cwfitzgerald added naga Shader Translator type: bug Something isn't working and removed kind: bug labels Oct 25, 2023
@teoxoy teoxoy added this to the WebGPU Specification V1 milestone Nov 3, 2023
@jimblandy
Copy link
Member

With #4870, this works:

const i32min = i32(-0x80000000);

and this gets an error:

const i32min = -0x80000000i;

Now Naga says:

error: numeric literal not representable by target type: `0x80000000i`
  ┌─ min.wgsl:2:17
  │
2 │ const i32min = -0x80000000i;
  │                 ^^^^^^^^^^^ numeric literal not representable by target type

So I think this one should be fixed by that PR.

jimblandy added a commit to jimblandy/wgpu that referenced this issue Dec 13, 2023
jimblandy added a commit to jimblandy/wgpu that referenced this issue Dec 13, 2023
@teoxoy teoxoy closed this as completed in d9d051b Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga front-end lang: WGSL WebGPU Shading Language naga Shader Translator type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants