diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-03-04 15:18:05 -0500 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2023-03-05 02:59:02 -0500 |
| commit | 9e3a5ecd39227aff3b2821d0c0b489eb9713b146 (patch) | |
| tree | 547382c647e3b5a615d062711d86417d009f0988 /src/codegen/c.zig | |
| parent | e96a0fd0a1a05fe8c3b4d87df03d78ae99b7dbcb (diff) | |
| download | zig-9e3a5ecd39227aff3b2821d0c0b489eb9713b146.tar.gz zig-9e3a5ecd39227aff3b2821d0c0b489eb9713b146.zip | |
CBE: fix behavior test failures on msvc
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 4d3e71e78a..b8606b1a17 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -4461,10 +4461,12 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue { if (dest_ty.isAbiInt()) { const dest_cty = try f.typeToCType(dest_ty, .complete); const dest_info = dest_ty.intInfo(target); - var wrap_ty_pl = Type.Payload.Bits{ .base = .{ .tag = switch (dest_info.signedness) { + var info_ty_pl = Type.Payload.Bits{ .base = .{ .tag = switch (dest_info.signedness) { .unsigned => .int_unsigned, .signed => .int_signed, } }, .data = dest_info.bits }; + var wrap_cty: ?CType = null; + var need_bitcasts = false; try f.writeCValue(writer, local, .Other); if (dest_cty.castTag(.array)) |pl| { @@ -4472,14 +4474,31 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue { .Little => pl.data.len - 1, .Big => 0, }}); - wrap_ty_pl.data -= 1; - wrap_ty_pl.data %= @intCast(u16, f.byteSize(f.indexToCType(pl.data.elem_type)) * 8); - wrap_ty_pl.data += 1; + const elem_cty = f.indexToCType(pl.data.elem_type); + wrap_cty = elem_cty.toSignedness(dest_info.signedness); + need_bitcasts = wrap_cty.?.tag() == .zig_i128; + info_ty_pl.data -= 1; + info_ty_pl.data %= @intCast(u16, f.byteSize(elem_cty) * 8); + info_ty_pl.data += 1; } - const wrap_ty = Type.initPayload(&wrap_ty_pl.base); - try writer.writeAll(" = zig_wrap_"); - try f.object.dg.renderTypeForBuiltinFnName(writer, wrap_ty); + try writer.writeAll(" = "); + if (need_bitcasts) { + try writer.writeAll("zig_bitcast_"); + try f.object.dg.renderCTypeForBuiltinFnName(writer, wrap_cty.?.toUnsigned()); + try writer.writeByte('('); + } + try writer.writeAll("zig_wrap_"); + const info_ty = Type.initPayload(&info_ty_pl.base); + if (wrap_cty) |cty| + try f.object.dg.renderCTypeForBuiltinFnName(writer, cty) + else + try f.object.dg.renderTypeForBuiltinFnName(writer, info_ty); try writer.writeByte('('); + if (need_bitcasts) { + try writer.writeAll("zig_bitcast_"); + try f.object.dg.renderCTypeForBuiltinFnName(writer, wrap_cty.?); + try writer.writeByte('('); + } try f.writeCValue(writer, local, .Other); if (dest_cty.castTag(.array)) |pl| { try writer.print("[{d}]", .{switch (target.cpu.arch.endian()) { @@ -4487,7 +4506,9 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue { .Big => 0, }}); } - try f.object.dg.renderBuiltinInfo(writer, wrap_ty, .bits); + if (need_bitcasts) try writer.writeByte(')'); + try f.object.dg.renderBuiltinInfo(writer, info_ty, .bits); + if (need_bitcasts) try writer.writeByte(')'); try writer.writeAll(");\n"); } |
