translate-c: Explicit cast bool from float fix

This commit is contained in:
february cozzocrea 2024-01-16 08:12:05 -08:00 committed by GitHub
parent 50457482b1
commit da506aaf6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -2380,6 +2380,14 @@ fn transCCast(
});
}
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))
return Tag.as.create(c.arena, .{
.lhs = dst_node,

View 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