Skip to content

sizeof operator compiles to 0 for generic vectors #10381

@0cc4m

Description

@0cc4m

Issue Description

In a generic function, when using sizeof for a generic type vector, it compiles to 0 instead of the actual size.

Reproducer Code

[vk::binding(0)] RWStructuredBuffer<half> out;

uint get_vec_size<T>() {
    return sizeof(vector<T, 4>);
}

[shader("compute")]
[numthreads(1, 1, 1)]
void main() {
    out[0] = half(get_vec_size<float>());
}
slangc shader.slang -stage compute -target spirv-asm -entry main -o shader.spvasm -O0

When using sizeof(T) it works as expected.

Expected Behavior

It should compile to 16.

Actual Behavior

It compiles to 0:

     %uint_0 = OpConstant %uint 0
[...]
%get_vec_size = OpFunction %uint None %17
         %18 = OpLabel
               OpReturnValue %uint_0
               OpFunctionEnd

Environment

  • Slang compiled from commit d6a3e4d
  • Fedora 43

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions