aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-08-05 18:18:24 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-08-05 18:18:24 -0400
commitc420b234cc5698d44b11cf313f14a9608328f111 (patch)
tree10a0452bcd450020ab0fa5429b6ffd1b1e190b0c /src
parentaa232089f2beaa273458a9fa75b2ba5c70f71805 (diff)
downloadzig-c420b234cc5698d44b11cf313f14a9608328f111.tar.gz
zig-c420b234cc5698d44b11cf313f14a9608328f111.zip
translate-c: handle for loop with empty body
Diffstat (limited to 'src')
-rw-r--r--src/translate_c.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/translate_c.cpp b/src/translate_c.cpp
index ceb6f2a0bc..bf31dc7c3d 100644
--- a/src/translate_c.cpp
+++ b/src/translate_c.cpp
@@ -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));