Commit da506aaf6e
Changed files (2)
test
cases
run_translated_c
src/translate_c.zig
@@ -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,
test/cases/run_translated_c/explicit_cast_bool_from_float.c
@@ -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