mirror of
https://github.com/ziglang/zig.git
synced 2025-12-11 16:53:06 +00:00
translate-c: Explicit cast bool from float fix
This commit is contained in:
parent
50457482b1
commit
da506aaf6e
@ -2380,6 +2380,14 @@ fn transCCast(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (cIsFloating(src_type) and !cIsFloating(dst_type)) {
|
if (cIsFloating(src_type) and !cIsFloating(dst_type)) {
|
||||||
|
// bool expression: floating val != 0
|
||||||
|
if (qualTypeIsBoolean(dst_type)) {
|
||||||
|
return Tag.not_equal.create(c.arena, .{
|
||||||
|
.lhs = expr,
|
||||||
|
.rhs = Tag.zero_literal.init(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// @as(dest_type, @intFromFloat(val))
|
// @as(dest_type, @intFromFloat(val))
|
||||||
return Tag.as.create(c.arena, .{
|
return Tag.as.create(c.arena, .{
|
||||||
.lhs = dst_node,
|
.lhs = dst_node,
|
||||||
|
|||||||
10
test/cases/run_translated_c/explicit_cast_bool_from_float.c
Normal file
10
test/cases/run_translated_c/explicit_cast_bool_from_float.c
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
float f = 2.0f;
|
||||||
|
bool b = (bool) f;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// run-translated-c
|
||||||
|
// c_frontends=aro,clang
|
||||||
Loading…
x
Reference in New Issue
Block a user