zig icon indicating copy to clipboard operation
zig copied to clipboard

src/codegen/spirv/Assembler.zig: fix OpConstant /w floats

Open xor-shift opened this issue 3 months ago • 7 comments

apologies if this wasn't an oversight and if there was some reason behind the lack of a return but i couldn't find any indications towards that

previously, the following code would fail to compile:

export fn main() callconv(.spirv_kernel) void {
    asm volatile (
        \\ %f32 = OpTypeFloat 32
        \\ %foo = OpConstant %f32 0
    );
}

with the following output:

test2.zig:1:8: error: failed to assemble SPIR-V inline assembly
export fn main() callconv(.spirv_kernel) void {
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test2.zig:1:8: note: cannot parse literal constant

xor-shift avatar Nov 22 '25 10:11 xor-shift

cc @alichraghi

alexrp avatar Nov 22 '25 10:11 alexrp

Does this even compile? You are returning a return statement when it reaches the else branch.

DialecticalMaterialist avatar Nov 22 '25 10:11 DialecticalMaterialist

And from a quick glance parseContextDependentFloat does not even return a value. Since it appends the operand inside of the function.

DialecticalMaterialist avatar Nov 22 '25 11:11 DialecticalMaterialist

it does compile, noreturn (the type of a return statement) can be coerced into any type afaik.

the issue with the function is not that it doesn't return some value, it's the fact that it falls down to ass.fail

xor-shift avatar Nov 22 '25 11:11 xor-shift

I see, my bad then.

DialecticalMaterialist avatar Nov 22 '25 11:11 DialecticalMaterialist

oops, i didn't think new commits would get reflected here

xor-shift avatar Nov 22 '25 13:11 xor-shift

sorry about that..

xor-shift avatar Nov 22 '25 13:11 xor-shift