mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
translate-c: handle for loop with empty body
This commit is contained in:
parent
aa232089f2
commit
c420b234cc
@ -3020,8 +3020,7 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const Stmt *stmt,
|
||||
if (while_node->data.while_expr.body == nullptr) {
|
||||
while_node->data.while_expr.body = trans_create_node(c, NodeTypeBlock);
|
||||
}
|
||||
return wrap_stmt(out_node, out_child_scope, scope,
|
||||
while_node);
|
||||
return wrap_stmt(out_node, out_child_scope, scope, while_node);
|
||||
}
|
||||
case Stmt::IfStmtClass:
|
||||
return wrap_stmt(out_node, out_child_scope, scope,
|
||||
@ -3048,9 +3047,13 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const Stmt *stmt,
|
||||
case Stmt::DoStmtClass:
|
||||
return wrap_stmt(out_node, out_child_scope, scope,
|
||||
trans_do_loop(c, scope, (const DoStmt *)stmt));
|
||||
case Stmt::ForStmtClass:
|
||||
return wrap_stmt(out_node, out_child_scope, scope,
|
||||
trans_for_loop(c, scope, (const ForStmt *)stmt));
|
||||
case Stmt::ForStmtClass: {
|
||||
AstNode *while_node = trans_for_loop(c, scope, (const ForStmt *)stmt);
|
||||
if (while_node->data.while_expr.body == nullptr) {
|
||||
while_node->data.while_expr.body = trans_create_node(c, NodeTypeBlock);
|
||||
}
|
||||
return wrap_stmt(out_node, out_child_scope, scope, while_node);
|
||||
}
|
||||
case Stmt::StringLiteralClass:
|
||||
return wrap_stmt(out_node, out_child_scope, scope,
|
||||
trans_string_literal(c, scope, (const StringLiteral *)stmt));
|
||||
|
||||
@ -1,6 +1,16 @@
|
||||
const tests = @import("tests.zig");
|
||||
|
||||
pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
cases.add("for with empty body",
|
||||
\\void foo(void) {
|
||||
\\ for (;;);
|
||||
\\}
|
||||
,
|
||||
\\pub fn foo() void {
|
||||
\\ while (true) {}
|
||||
\\}
|
||||
);
|
||||
|
||||
cases.add("while with empty body",
|
||||
\\void foo(void) {
|
||||
\\ while (1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user