diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-26 01:13:53 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-26 01:13:53 -0400 |
| commit | f2a174b294f3322c45510d199bc14ab2c0aadbfc (patch) | |
| tree | 15a9c47f38b5671e29d568c6f8de895b06a9e7f3 /src | |
| parent | df198ea60e05664b5b72a43aae815fa06d94c19c (diff) | |
| parent | f95ec229f8478eedbb59700cbd223367ebd89a86 (diff) | |
| download | zig-f2a174b294f3322c45510d199bc14ab2c0aadbfc.tar.gz zig-f2a174b294f3322c45510d199bc14ab2c0aadbfc.zip | |
Merge pull request #10035 from Snektron/stage2-orelse
stage2: improve orelse for c-pointers
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 2562948e8e..6d087fde7e 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -3035,10 +3035,11 @@ fn analyzeBlockBody( // to emit a jump instruction to after the block when it encounters the break. try parent_block.instructions.append(gpa, merges.block_inst); const resolved_ty = try sema.resolvePeerTypes(parent_block, src, merges.results.items, .none); + const ty_inst = try sema.addType(resolved_ty); try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + child_block.instructions.items.len); sema.air_instructions.items(.data)[merges.block_inst] = .{ .ty_pl = .{ - .ty = try sema.addType(resolved_ty), + .ty = ty_inst, .payload = sema.addExtraAssumeCapacity(Air.Block{ .body_len = @intCast(u32, child_block.instructions.items.len), }), @@ -4666,7 +4667,16 @@ fn zirOptionalPayload( if (operand_ty.ptrSize() != .C) { return sema.failWithExpectedOptionalType(block, src, operand_ty); } - break :t operand_ty; + const ptr_info = operand_ty.ptrInfo().data; + break :t try Type.ptr(sema.arena, .{ + .pointee_type = try ptr_info.pointee_type.copy(sema.arena), + .@"align" = ptr_info.@"align", + .@"addrspace" = ptr_info.@"addrspace", + .mutable = ptr_info.mutable, + .@"allowzero" = ptr_info.@"allowzero", + .@"volatile" = ptr_info.@"volatile", + .size = .One, + }); }, else => return sema.failWithExpectedOptionalType(block, src, operand_ty), }; |
