| ... | ... | @@ -927,9 +927,9 @@ pub const DeclGen = struct { |
| 927 | 927 | }; |
| 928 | 928 | const int_val = Value.initPayload(&int_val_pl.base); |
| 929 | 929 | |
| 930 | | try writer.writeByte('('); |
| 931 | | try dg.renderTypecast(writer, ty); |
| 932 | | try writer.writeByte(')'); |
| 930 | try writer.writeAll("zig_cast_"); |
| 931 | try dg.renderTypeForBuiltinFnName(writer, ty); |
| 932 | try writer.writeByte(' '); |
| 933 | 933 | if (std.math.isFinite(f128_val)) { |
| 934 | 934 | try writer.writeAll("zig_as_"); |
| 935 | 935 | try dg.renderTypeForBuiltinFnName(writer, ty); |
| ... | ... | @@ -3344,16 +3344,27 @@ fn airIntCast(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3344 | 3344 | return CValue.none; |
| 3345 | 3345 | } |
| 3346 | 3346 | |
| 3347 | const target = f.object.dg.module.getTarget(); |
| 3347 | 3348 | const operand = try f.resolveInst(ty_op.operand); |
| 3348 | 3349 | try reap(f, inst, &.{ty_op.operand}); |
| 3349 | 3350 | const writer = f.object.writer(); |
| 3350 | 3351 | const inst_ty = f.air.typeOfIndex(inst); |
| 3351 | 3352 | const local = try f.allocLocal(inst, inst_ty); |
| 3352 | 3353 | try f.writeCValue(writer, local, .Other); |
| 3353 | | try writer.writeAll(" = ("); |
| 3354 | | try f.renderTypecast(writer, inst_ty); |
| 3355 | | try writer.writeByte(')'); |
| 3354 | try writer.writeAll(" = "); |
| 3355 | const cant_cast = inst_ty.isInt() and inst_ty.bitSize(target) > 64; |
| 3356 | if (cant_cast) { |
| 3357 | if (f.air.typeOf(ty_op.operand).bitSize(target) > 64) return f.fail("TODO: C backend: implement casting between types > 64 bits", .{}); |
| 3358 | try writer.writeAll("zig_as_"); |
| 3359 | try f.object.dg.renderTypeForBuiltinFnName(writer, inst_ty); |
| 3360 | try writer.writeAll("(0, "); |
| 3361 | } else { |
| 3362 | try writer.writeByte('('); |
| 3363 | try f.renderTypecast(writer, inst_ty); |
| 3364 | try writer.writeByte(')'); |
| 3365 | } |
| 3356 | 3366 | try f.writeCValue(writer, operand, .Other); |
| 3367 | if (cant_cast) try writer.writeByte(')'); |
| 3357 | 3368 | try writer.writeAll(";\n"); |
| 3358 | 3369 | return local; |
| 3359 | 3370 | } |