authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-10-26 01:13:53-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-10-26 01:13:53-04:00
logf2a174b294f3322c45510d199bc14ab2c0aadbfc
tree15a9c47f38b5671e29d568c6f8de895b06a9e7f3
parentdf198ea60e05664b5b72a43aae815fa06d94c19c
parentf95ec229f8478eedbb59700cbd223367ebd89a86
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #10035 from Snektron/stage2-orelse

stage2: improve orelse for c-pointers

1 files changed, 12 insertions(+), 2 deletions(-)

src/Sema.zig+12-2
...@@ -3035,10 +3035,11 @@ fn analyzeBlockBody(...@@ -3035,10 +3035,11 @@ fn analyzeBlockBody(
3035 // to emit a jump instruction to after the block when it encounters the break.3035 // to emit a jump instruction to after the block when it encounters the break.
3036 try parent_block.instructions.append(gpa, merges.block_inst);3036 try parent_block.instructions.append(gpa, merges.block_inst);
3037 const resolved_ty = try sema.resolvePeerTypes(parent_block, src, merges.results.items, .none);3037 const resolved_ty = try sema.resolvePeerTypes(parent_block, src, merges.results.items, .none);
3038 const ty_inst = try sema.addType(resolved_ty);
3038 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +3039 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +
3039 child_block.instructions.items.len);3040 child_block.instructions.items.len);
3040 sema.air_instructions.items(.data)[merges.block_inst] = .{ .ty_pl = .{3041 sema.air_instructions.items(.data)[merges.block_inst] = .{ .ty_pl = .{
3041 .ty = try sema.addType(resolved_ty),3042 .ty = ty_inst,
3042 .payload = sema.addExtraAssumeCapacity(Air.Block{3043 .payload = sema.addExtraAssumeCapacity(Air.Block{
3043 .body_len = @intCast(u32, child_block.instructions.items.len),3044 .body_len = @intCast(u32, child_block.instructions.items.len),
3044 }),3045 }),
...@@ -4666,7 +4667,16 @@ fn zirOptionalPayload(...@@ -4666,7 +4667,16 @@ fn zirOptionalPayload(
4666 if (operand_ty.ptrSize() != .C) {4667 if (operand_ty.ptrSize() != .C) {
4667 return sema.failWithExpectedOptionalType(block, src, operand_ty);4668 return sema.failWithExpectedOptionalType(block, src, operand_ty);
4668 }4669 }
4669 break :t operand_ty;4670 const ptr_info = operand_ty.ptrInfo().data;
4671 break :t try Type.ptr(sema.arena, .{
4672 .pointee_type = try ptr_info.pointee_type.copy(sema.arena),
4673 .@"align" = ptr_info.@"align",
4674 .@"addrspace" = ptr_info.@"addrspace",
4675 .mutable = ptr_info.mutable,
4676 .@"allowzero" = ptr_info.@"allowzero",
4677 .@"volatile" = ptr_info.@"volatile",
4678 .size = .One,
4679 });
4670 },4680 },
4671 else => return sema.failWithExpectedOptionalType(block, src, operand_ty),4681 else => return sema.failWithExpectedOptionalType(block, src, operand_ty),
4672 };4682 };