authorgravatar for february.cozzocrea@gmail.comfebruary cozzocrea <february.cozzocrea@gmail.com> 2024-01-16 08:12:05-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-01-16 18:12:05+02:00
logda506aaf6ea731c72daaac649dba788407db0d6c
treebf453b98b793cf85e13132056a691289c17dd612
parent50457482b16dc402ad0eff9f7990258257e2dd62
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

translate-c: Explicit cast bool from float fix


2 files changed, 18 insertions(+), 0 deletions(-)

src/translate_c.zig+8
......@@ -2380,6 +2380,14 @@ fn transCCast(
23802380 });
23812381 }
23822382 if (cIsFloating(src_type) and !cIsFloating(dst_type)) {
2383 // bool expression: floating val != 0
2384 if (qualTypeIsBoolean(dst_type)) {
2385 return Tag.not_equal.create(c.arena, .{
2386 .lhs = expr,
2387 .rhs = Tag.zero_literal.init(),
2388 });
2389 }
2390
23832391 // @as(dest_type, @intFromFloat(val))
23842392 return Tag.as.create(c.arena, .{
23852393 .lhs = dst_node,
test/cases/run_translated_c/explicit_cast_bool_from_float.c created+10
......@@ -0,0 +1,10 @@
1#include <stdbool.h>
2
3int main() {
4 float f = 2.0f;
5 bool b = (bool) f;
6 return 0;
7}
8
9// run-translated-c
10// c_frontends=aro,clang