Skip to content

[Migrated] Array init with 0i32 uses 0u32 instead. #85

Closed
@rust-gpu-bot

Description

@rust-gpu-bot

Issue automatically imported from old repo: EmbarkStudios/rust-gpu#1061
Old labels: t: bug
Originally creatd by charles-r-earp on 2023-05-21T05:56:49Z


Initializing arrays seems to replace 0i32 with 0u32 when using [0i32; N].

Example (see https://github.com/charles-r-earp/rust-gpu/tree/array-init for compiletests).

; SPIR-V
; Version: 1.3
; Generator: Google rspirv; 0
; Bound: 11
; Schema: 0
               OpCapability Shader
               OpCapability Float64
               OpCapability Int64
               OpCapability Int16
               OpCapability Int8
               OpCapability ShaderClockKHR
               OpExtension "SPV_KHR_shader_clock"
               OpMemoryModel Logical Simple
               OpEntryPoint Fragment %1 "main" %o
               OpExecutionMode %1 OriginUpperLeft
          %3 = OpString "/home/charles/Documents/rust/rust-gpu/tests/ui/lang/core/array/init_array_i32.rs"
               OpSource Unknown 0 %3 "// Test creating an array.
// build-pass

use spirv_std::macros::spirv;

#[spirv(fragment)]
pub fn main(o: &mut i32) {
    let array = [0i32; 4];
    *o = array[0];
}
"
               OpName %o "o"
               OpDecorate %o Location 0
        %int = OpTypeInt 32 1
%_ptr_Output_int = OpTypePointer Output %int
       %void = OpTypeVoid
          %7 = OpTypeFunction %void
          %o = OpVariable %_ptr_Output_int Output
       %uint = OpTypeInt 32 0
     %uint_0 = OpConstant %uint 0
          %1 = OpFunction %void None %7
         %10 = OpLabel
               OpLine %3 9 4
               OpStore %o %uint_0
               OpNoLine
               OpReturn
               OpFunctionEnd

A 0u32 is stored to o instead of the expected 0i32, which fails to compile.

What works:

  • f32, this seems to be an issue with signed integers
  • <[T; N]>::default()
  • An explicit list, [0i32, 0i32, ..]
  • Using 1 instead of 0, [1i32; 1]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions