diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-10-13 08:16:55 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-13 08:16:55 -0700 |
| commit | 7aa85691b08262b4fd63f9307e4d9cd41230e08c (patch) | |
| tree | 0a94e180e3a7b908e23445524118a0e8c3754b49 /src/Sema.zig | |
| parent | 244233da2a355cbb5b7ec2e3888c3607b91609a3 (diff) | |
| parent | b6762c2473fc02e0fa71212a5556f4aed3f1942c (diff) | |
| download | zig-7aa85691b08262b4fd63f9307e4d9cd41230e08c.tar.gz zig-7aa85691b08262b4fd63f9307e4d9cd41230e08c.zip | |
Merge pull request #17504 from ziglang/fix-var-args-coercion
Sema: fix crash when coercion dest is var args
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index c9dacd1185..0f3ae46c1b 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -4371,13 +4371,19 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr const mod = sema.mod; const un_tok = sema.code.instructions.items(.data)[inst].un_tok; const src = un_tok.src(); - const ty_operand = sema.resolveType(block, src, un_tok.operand) catch |err| switch (err) { - error.GenericPoison => { - // We don't actually have a type, so this will be treated as an untyped address-of operator. - return; - }, + // In case of GenericPoison, we don't actually have a type, so this will be + // treated as an untyped address-of operator. + if (un_tok.operand == .var_args_param_type) return; + const operand_air_inst = sema.resolveInst(un_tok.operand) catch |err| switch (err) { + error.GenericPoison => return, + else => |e| return e, + }; + if (operand_air_inst == .var_args_param_type) return; + const ty_operand = sema.analyzeAsType(block, src, operand_air_inst) catch |err| switch (err) { + error.GenericPoison => return, else => |e| return e, }; + if (ty_operand.isGenericPoison()) return; if (ty_operand.optEuBaseType(mod).zigTypeTag(mod) != .Pointer) { return sema.failWithOwnedErrorMsg(block, msg: { const msg = try sema.errMsg(block, src, "expected type '{}', found pointer", .{ty_operand.fmt(mod)}); @@ -9846,11 +9852,19 @@ fn analyzeAs( const mod = sema.mod; const operand = try sema.resolveInst(zir_operand); if (zir_dest_type == .var_args_param_type) return operand; - const dest_ty = sema.resolveType(block, src, zir_dest_type) catch |err| switch (err) { + const operand_air_inst = sema.resolveInst(zir_dest_type) catch |err| switch (err) { + error.GenericPoison => return operand, + else => |e| return e, + }; + if (operand_air_inst == .var_args_param_type) return operand; + const dest_ty = sema.analyzeAsType(block, src, operand_air_inst) catch |err| switch (err) { error.GenericPoison => return operand, else => |e| return e, }; - if (dest_ty.zigTypeTag(mod) == .NoReturn) { + const dest_ty_tag = dest_ty.zigTypeTagOrPoison(mod) catch |err| switch (err) { + error.GenericPoison => return operand, + }; + if (dest_ty_tag == .NoReturn) { return sema.fail(block, src, "cannot cast to noreturn", .{}); } const is_ret = if (Zir.refToIndex(zir_dest_type)) |ptr_index| |
