translate-c: Fix types on assign expression bool
This commit is contained in:
committed by
Veikka Tuominen
parent
3c8d968194
commit
86ec26b1f0
@@ -4519,7 +4519,10 @@ fn transCreateNodeAssign(
|
||||
defer block_scope.deinit();
|
||||
|
||||
const tmp = try block_scope.makeMangledName(c, "tmp");
|
||||
const rhs_node = try transExpr(c, &block_scope.base, rhs, .used);
|
||||
var rhs_node = try transExpr(c, &block_scope.base, rhs, .used);
|
||||
if (!exprIsBooleanType(lhs) and isBoolRes(rhs_node)) {
|
||||
rhs_node = try Tag.bool_to_int.create(c.arena, rhs_node);
|
||||
}
|
||||
const tmp_decl = try Tag.var_simple.create(c.arena, .{ .name = tmp, .init = rhs_node });
|
||||
try block_scope.statements.append(tmp_decl);
|
||||
|
||||
|
||||
@@ -3900,4 +3900,20 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
\\pub const ZERO = @as(c_int, 0);
|
||||
\\pub const WORLD = @as(c_int, 0o0000123);
|
||||
});
|
||||
|
||||
cases.add("Assign expression from bool to int",
|
||||
\\void foo(void) {
|
||||
\\ int a;
|
||||
\\ if (a = 1 > 0) {}
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
\\pub export fn foo() void {
|
||||
\\ var a: c_int = undefined;
|
||||
\\ if ((blk: {
|
||||
\\ const tmp = @boolToInt(@as(c_int, 1) > @as(c_int, 0));
|
||||
\\ a = tmp;
|
||||
\\ break :blk tmp;
|
||||
\\ }) != 0) {}
|
||||
\\}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user