diff options
| author | Veikka Tuominen <git@vexu.eu> | 2023-01-16 15:40:22 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-01-17 20:28:43 +0200 |
| commit | e04547642ac2d0c1cba010b6101bb30c210735cb (patch) | |
| tree | 6d540eefa7ad5eba40ae7a3b30c8c44f9c433d0d /src/Sema.zig | |
| parent | 14f03fbd1602dae8fcaa5da42f5769422d1c4a7a (diff) | |
| download | zig-e04547642ac2d0c1cba010b6101bb30c210735cb.tar.gz zig-e04547642ac2d0c1cba010b6101bb30c210735cb.zip | |
Sema: promote smaller float types passed to variadic functions
Closes #6854
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 21e6fd14be..fedf045daa 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -26067,7 +26067,8 @@ fn coerceVarArgParam( ) !Air.Inst.Ref { if (block.is_typeof) return inst; - const coerced = switch (sema.typeOf(inst).zigTypeTag()) { + const uncasted_ty = sema.typeOf(inst); + const coerced = switch (uncasted_ty.zigTypeTag()) { // TODO consider casting to c_int/f64 if they fit .ComptimeInt, .ComptimeFloat => return sema.fail( block, @@ -26081,6 +26082,17 @@ fn coerceVarArgParam( break :blk try sema.analyzeDeclRef(fn_decl); }, .Array => return sema.fail(block, inst_src, "arrays must be passed by reference to variadic function", .{}), + .Float => float: { + const target = sema.mod.getTarget(); + const double_bits = @import("type.zig").CType.sizeInBits(.double, target); + const inst_bits = uncasted_ty.floatBits(sema.mod.getTarget()); + if (inst_bits >= double_bits) break :float inst; + switch (double_bits) { + 32 => break :float try sema.coerce(block, Type.f32, inst, inst_src), + 64 => break :float try sema.coerce(block, Type.f64, inst, inst_src), + else => unreachable, + } + }, else => inst, }; |
