authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-10-07 19:43:27+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-10-15 14:00:00+02:00
log4a6a024a4bd103cf7bf7e50a5ccf4103f4ce83a2
tree36411f3b31fc18c7d561c4efd1f421838f208bcf
parent89b1dafa7808d22eab78ea486f158f794da46a2c
signature Signed by SSH key SHA256:CQ99aPxq+RueiL9u7z0FEki5Fm7V6T8q4PrEGmINrA4

spirv: properly skip comptime function parameters


2 files changed, 14 insertions(+), 13 deletions(-)

src/codegen/spirv.zig+14-7
......@@ -1242,14 +1242,19 @@ const DeclGen = struct {
12421242
12431243 const param_ty_refs = try self.gpa.alloc(CacheRef, fn_info.param_types.len);
12441244 defer self.gpa.free(param_ty_refs);
1245 for (param_ty_refs, fn_info.param_types.get(ip)) |*param_type, fn_param_type| {
1246 param_type.* = try self.resolveType(fn_param_type.toType(), .direct);
1245 var param_index: usize = 0;
1246 for (fn_info.param_types.get(ip)) |param_ty_index| {
1247 const param_ty = param_ty_index.toType();
1248 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
1249
1250 param_ty_refs[param_index] = try self.resolveType(param_ty, .direct);
1251 param_index += 1;
12471252 }
12481253 const return_ty_ref = try self.resolveType(fn_info.return_type.toType(), .direct);
12491254
12501255 const ty_ref = try self.spv.resolve(.{ .function_type = .{
12511256 .return_type = return_ty_ref,
1252 .parameters = param_ty_refs,
1257 .parameters = param_ty_refs[0..param_index],
12531258 } });
12541259
12551260 try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref });
......@@ -1675,9 +1680,11 @@ const DeclGen = struct {
16751680 const fn_info = mod.typeToFunc(decl.ty).?;
16761681
16771682 try self.args.ensureUnusedCapacity(self.gpa, fn_info.param_types.len);
1678 for (0..fn_info.param_types.len) |i| {
1679 const param_type = fn_info.param_types.get(ip)[i];
1680 const param_type_id = try self.resolveTypeId(param_type.toType());
1683 for (fn_info.param_types.get(ip)) |param_ty_index| {
1684 const param_ty = param_ty_index.toType();
1685 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
1686
1687 const param_type_id = try self.resolveTypeId(param_ty);
16811688 const arg_result_id = self.spv.allocId();
16821689 try self.func.prologue.emit(self.spv.gpa, .OpFunctionParameter, .{
16831690 .id_result_type = param_type_id,
......@@ -3986,9 +3993,9 @@ const DeclGen = struct {
39863993 // Note: resolve() might emit instructions, so we need to call it
39873994 // before starting to emit OpFunctionCall instructions. Hence the
39883995 // temporary params buffer.
3989 const arg_id = try self.resolve(arg);
39903996 const arg_ty = self.typeOf(arg);
39913997 if (!arg_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
3998 const arg_id = try self.resolve(arg);
39923999
39934000 params[n_params] = arg_id;
39944001 n_params += 1;
test/behavior/struct.zig-6
......@@ -887,8 +887,6 @@ test "anonymous struct literal syntax" {
887887}
888888
889889test "fully anonymous struct" {
890 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
891
892890 const S = struct {
893891 fn doTheTest() !void {
894892 try dump(.{
......@@ -911,8 +909,6 @@ test "fully anonymous struct" {
911909}
912910
913911test "fully anonymous list literal" {
914 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
915
916912 const S = struct {
917913 fn doTheTest() !void {
918914 try dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi" });
......@@ -1715,8 +1711,6 @@ test "extern struct field pointer has correct alignment" {
17151711}
17161712
17171713test "packed struct field in anonymous struct" {
1718 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1719
17201714 const T = packed struct {
17211715 f1: bool = false,
17221716 };