authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-28 13:05:40+03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-03-28 13:05:40+03:00
log460e7a24451c9bf37a8c1e5e6a4554173416b149
tree1b96c2bced6da02c69d08d6fe2299e7c1c8809b8
parentb8cd56dc94f68cda6616b4d9411d0419d2bb909f
parentd5e89dd70b2b5e26e2457d276ce25125f111b29a
signature Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #11319 from Vexu/stage2-arg-count

stage2: check arg count before types

3 files changed, 22 insertions(+), 11 deletions(-)

build.zig+2-1
......@@ -613,7 +613,8 @@ fn addCxxKnownPath(
613613 ctx.cxx_compiler,
614614 b.fmt("-print-file-name={s}", .{objname}),
615615 });
616 const path_unpadded = mem.tokenize(u8, path_padded, "\r\n").next().?;
616 var tokenizer = mem.tokenize(u8, path_padded, "\r\n");
617 const path_unpadded = tokenizer.next().?;
617618 if (mem.eql(u8, path_unpadded, objname)) {
618619 if (errtxt) |msg| {
619620 std.debug.print("{s}", .{msg});
src/Sema.zig+11-8
......@@ -2317,8 +2317,8 @@ fn zirErrorSetDecl(
23172317 const extra_index_end = extra_index + (extra.data.fields_len * 2);
23182318 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string
23192319 const str_index = sema.code.extra[extra_index];
2320 const name = try new_decl_arena_allocator.dupe(u8, sema.code.nullTerminatedString(str_index));
2321 const result = names.getOrPutAssumeCapacity(name);
2320 const kv = try sema.mod.getErrorValue(sema.code.nullTerminatedString(str_index));
2321 const result = names.getOrPutAssumeCapacity(kv.key);
23222322 assert(!result.found_existing); // verified in AstGen
23232323 }
23242324
......@@ -3661,8 +3661,12 @@ fn zirParamType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
36613661 fn_ty.fnInfo();
36623662
36633663 if (param_index >= fn_info.param_types.len) {
3664 assert(fn_info.is_var_args);
3665 return sema.addType(Type.initTag(.var_args_param));
3664 if (fn_info.is_var_args) {
3665 return sema.addType(Type.initTag(.var_args_param));
3666 }
3667 // TODO implement begin_call/end_call Zir instructions and check
3668 // argument count before casting arguments to parameter types.
3669 return sema.fail(block, callee_src, "wrong number of arguments", .{});
36663670 }
36673671
36683672 if (fn_info.param_types[param_index].tag() == .generic_poison) {
......@@ -13159,11 +13163,10 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
1315913163 // TODO use reflection instead of magic numbers here
1316013164 // error_set: type,
1316113165 const name_val = struct_val[0];
13166 const name_str = try name_val.toAllocatedBytes(Type.initTag(.const_slice_u8), sema.arena, target);
1316213167
13163 names.putAssumeCapacityNoClobber(
13164 try name_val.toAllocatedBytes(Type.initTag(.const_slice_u8), sema.arena, target),
13165 {},
13166 );
13168 const kv = try sema.mod.getErrorValue(name_str);
13169 names.putAssumeCapacityNoClobber(kv.key, {});
1316713170 }
1316813171
1316913172 // names must be sorted
src/value.zig+9-2
......@@ -461,7 +461,7 @@ pub const Value = extern union {
461461 => unreachable,
462462
463463 .ty, .lazy_align => {
464 const payload = self.castTag(.ty).?;
464 const payload = self.cast(Payload.Ty).?;
465465 const new_payload = try arena.create(Payload.Ty);
466466 new_payload.* = .{
467467 .base = payload.base,
......@@ -718,7 +718,7 @@ pub const Value = extern union {
718718 .lazy_align => {
719719 try out_stream.writeAll("@alignOf(");
720720 try val.castTag(.lazy_align).?.data.dump("", options, out_stream);
721 try out_stream.writeAll(")");
721 return try out_stream.writeAll(")");
722722 },
723723 .int_type => {
724724 const int_type = val.castTag(.int_type).?.data;
......@@ -2478,6 +2478,13 @@ pub const Value = extern union {
24782478 .the_only_possible_value,
24792479 => return hashInt(ptr_val, hasher, target),
24802480
2481 .lazy_align => {
2482 // Bit weird to have this here but this function is also called
2483 // on integers.
2484 const ty = ptr_val.castTag(.lazy_align).?.data;
2485 ty.hashWithHasher(hasher, target);
2486 },
2487
24812488 else => unreachable,
24822489 }
24832490 }