authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2019-03-18 14:55:57+01:00
committergravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2019-03-18 14:55:57+01:00
log9171e7a7c11d2f5623a30683e1a0f510fe30b4de
treeb1ef8b24e72c8ce9a5f36655cc6e77f70b67d4f0
parent5ae400fb393b4a7fb4af15b89a4101de9255b26d

More work on ignoring values correctly


2 files changed, 138 insertions(+), 73 deletions(-)

src/translate_c.cpp+115-70
......@@ -1226,8 +1226,8 @@ static AstNode *trans_compound_stmt(Context *c, TransScope *scope, const clang::
12261226 return child_scope_block->node;
12271227}
12281228
1229static AstNode *trans_stmt_expr(Context *c, TransScope *scope, const clang::StmtExpr *stmt,
1230 TransScope **out_node_scope)
1229static AstNode *trans_stmt_expr(Context *c, ResultUsed result_used, TransScope *scope,
1230 const clang::StmtExpr *stmt, TransScope **out_node_scope)
12311231{
12321232 AstNode *block = trans_compound_stmt(c, scope, stmt->getSubStmt(), out_node_scope);
12331233 if (block == nullptr)
......@@ -1248,7 +1248,7 @@ static AstNode *trans_stmt_expr(Context *c, TransScope *scope, const clang::Stmt
12481248 return_expr = return_expr->data.bin_op_expr.op2;
12491249 }
12501250 block->data.block.statements.append(trans_create_node_break(c, label, return_expr));
1251 return block;
1251 return maybe_suppress_result(c, result_used, block);
12521252}
12531253
12541254static AstNode *trans_return_stmt(Context *c, TransScope *scope, const clang::ReturnStmt *stmt) {
......@@ -1264,13 +1264,15 @@ static AstNode *trans_return_stmt(Context *c, TransScope *scope, const clang::Re
12641264 }
12651265}
12661266
1267static AstNode *trans_integer_literal(Context *c, const clang::IntegerLiteral *stmt) {
1267static AstNode *trans_integer_literal(Context *c, ResultUsed result_used, const clang::IntegerLiteral *stmt) {
12681268 llvm::APSInt result;
12691269 if (!stmt->EvaluateAsInt(result, *reinterpret_cast<clang::ASTContext *>(c->ctx))) {
12701270 emit_warning(c, stmt->getLocStart(), "invalid integer literal");
12711271 return nullptr;
12721272 }
1273 return trans_create_node_apint(c, result);
1273
1274 AstNode *node = trans_create_node_apint(c, result);
1275 return maybe_suppress_result(c, result_used, node);
12741276}
12751277
12761278static AstNode *trans_conditional_operator(Context *c, ResultUsed result_used, TransScope *scope,
......@@ -1407,14 +1409,17 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS
14071409 case clang::BO_Cmp:
14081410 emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: clang::BO_Cmp");
14091411 return nullptr;
1410 case clang::BO_Mul:
1411 return trans_create_bin_op(c, scope, stmt->getLHS(),
1412 case clang::BO_Mul: {
1413 AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(),
14121414 qual_type_has_wrapping_overflow(c, stmt->getType()) ? BinOpTypeMultWrap : BinOpTypeMult,
14131415 stmt->getRHS());
1416 return maybe_suppress_result(c, result_used, node);
1417 }
14141418 case clang::BO_Div:
14151419 if (qual_type_has_wrapping_overflow(c, stmt->getType())) {
14161420 // unsigned/float division uses the operator
1417 return trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeDiv, stmt->getRHS());
1421 AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeDiv, stmt->getRHS());
1422 return maybe_suppress_result(c, result_used, node);
14181423 } else {
14191424 // signed integer division uses @divTrunc
14201425 AstNode *fn_call = trans_create_node_builtin_fn_call_str(c, "divTrunc");
......@@ -1424,12 +1429,13 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS
14241429 AstNode *rhs = trans_expr(c, ResultUsedYes, scope, stmt->getRHS(), TransLValue);
14251430 if (rhs == nullptr) return nullptr;
14261431 fn_call->data.fn_call_expr.params.append(rhs);
1427 return fn_call;
1432 return maybe_suppress_result(c, result_used, fn_call);
14281433 }
14291434 case clang::BO_Rem:
14301435 if (qual_type_has_wrapping_overflow(c, stmt->getType())) {
14311436 // unsigned/float division uses the operator
1432 return trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeMod, stmt->getRHS());
1437 AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeMod, stmt->getRHS());
1438 return maybe_suppress_result(c, result_used, node);
14331439 } else {
14341440 // signed integer division uses @rem
14351441 AstNode *fn_call = trans_create_node_builtin_fn_call_str(c, "rem");
......@@ -1439,42 +1445,72 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS
14391445 AstNode *rhs = trans_expr(c, ResultUsedYes, scope, stmt->getRHS(), TransLValue);
14401446 if (rhs == nullptr) return nullptr;
14411447 fn_call->data.fn_call_expr.params.append(rhs);
1442 return fn_call;
1448 return maybe_suppress_result(c, result_used, fn_call);
14431449 }
1444 case clang::BO_Add:
1445 return trans_create_bin_op(c, scope, stmt->getLHS(),
1450 case clang::BO_Add: {
1451 AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(),
14461452 qual_type_has_wrapping_overflow(c, stmt->getType()) ? BinOpTypeAddWrap : BinOpTypeAdd,
14471453 stmt->getRHS());
1448 case clang::BO_Sub:
1449 return trans_create_bin_op(c, scope, stmt->getLHS(),
1454 return maybe_suppress_result(c, result_used, node);
1455 }
1456 case clang::BO_Sub: {
1457 AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(),
14501458 qual_type_has_wrapping_overflow(c, stmt->getType()) ? BinOpTypeSubWrap : BinOpTypeSub,
14511459 stmt->getRHS());
1452 case clang::BO_Shl:
1453 return trans_create_shift_op(c, scope, stmt->getType(), stmt->getLHS(), BinOpTypeBitShiftLeft, stmt->getRHS());
1454 case clang::BO_Shr:
1455 return trans_create_shift_op(c, scope, stmt->getType(), stmt->getLHS(), BinOpTypeBitShiftRight, stmt->getRHS());
1456 case clang::BO_LT:
1457 return trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpLessThan, stmt->getRHS());
1458 case clang::BO_GT:
1459 return trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpGreaterThan, stmt->getRHS());
1460 case clang::BO_LE:
1461 return trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpLessOrEq, stmt->getRHS());
1462 case clang::BO_GE:
1463 return trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpGreaterOrEq, stmt->getRHS());
1464 case clang::BO_EQ:
1465 return trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpEq, stmt->getRHS());
1466 case clang::BO_NE:
1467 return trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpNotEq, stmt->getRHS());
1468 case clang::BO_And:
1469 return trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeBinAnd, stmt->getRHS());
1470 case clang::BO_Xor:
1471 return trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeBinXor, stmt->getRHS());
1472 case clang::BO_Or:
1473 return trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeBinOr, stmt->getRHS());
1474 case clang::BO_LAnd:
1475 return trans_create_bool_bin_op(c, scope, stmt->getLHS(), BinOpTypeBoolAnd, stmt->getRHS());
1476 case clang::BO_LOr:
1477 return trans_create_bool_bin_op(c, scope, stmt->getLHS(), BinOpTypeBoolOr, stmt->getRHS());
1460 return maybe_suppress_result(c, result_used, node);
1461 }
1462 case clang::BO_Shl: {
1463 AstNode *node = trans_create_shift_op(c, scope, stmt->getType(), stmt->getLHS(), BinOpTypeBitShiftLeft, stmt->getRHS());
1464 return maybe_suppress_result(c, result_used, node);
1465 }
1466 case clang::BO_Shr: {
1467 AstNode *node = trans_create_shift_op(c, scope, stmt->getType(), stmt->getLHS(), BinOpTypeBitShiftRight, stmt->getRHS());
1468 return maybe_suppress_result(c, result_used, node);
1469 }
1470 case clang::BO_LT: {
1471 AstNode *node =trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpLessThan, stmt->getRHS());
1472 return maybe_suppress_result(c, result_used, node);
1473 }
1474 case clang::BO_GT: {
1475 AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpGreaterThan, stmt->getRHS());
1476 return maybe_suppress_result(c, result_used, node);
1477 }
1478 case clang::BO_LE: {
1479 AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpLessOrEq, stmt->getRHS());
1480 return maybe_suppress_result(c, result_used, node);
1481 }
1482 case clang::BO_GE: {
1483 AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpGreaterOrEq, stmt->getRHS());
1484 return maybe_suppress_result(c, result_used, node);
1485 }
1486 case clang::BO_EQ: {
1487 AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpEq, stmt->getRHS());
1488 return maybe_suppress_result(c, result_used, node);
1489 }
1490 case clang::BO_NE: {
1491 AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeCmpNotEq, stmt->getRHS());
1492 return maybe_suppress_result(c, result_used, node);
1493 }
1494 case clang::BO_And: {
1495 AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeBinAnd, stmt->getRHS());
1496 return maybe_suppress_result(c, result_used, node);
1497 }
1498 case clang::BO_Xor: {
1499 AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeBinXor, stmt->getRHS());
1500 return maybe_suppress_result(c, result_used, node);
1501 }
1502 case clang::BO_Or: {
1503 AstNode *node = trans_create_bin_op(c, scope, stmt->getLHS(), BinOpTypeBinOr, stmt->getRHS());
1504 return maybe_suppress_result(c, result_used, node);
1505 }
1506 case clang::BO_LAnd: {
1507 AstNode *node = trans_create_bool_bin_op(c, scope, stmt->getLHS(), BinOpTypeBoolAnd, stmt->getRHS());
1508 return maybe_suppress_result(c, result_used, node);
1509 }
1510 case clang::BO_LOr: {
1511 AstNode *node = trans_create_bool_bin_op(c, scope, stmt->getLHS(), BinOpTypeBoolOr, stmt->getRHS());
1512 return maybe_suppress_result(c, result_used, node);
1513 }
14781514 case clang::BO_Assign:
14791515 return trans_create_assign(c, result_used, scope, stmt->getLHS(), stmt->getRHS());
14801516 case clang::BO_Comma:
......@@ -1486,13 +1522,15 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS
14861522 AstNode *lhs = trans_expr(c, ResultUsedNo, &scope_block->base, stmt->getLHS(), TransRValue);
14871523 if (lhs == nullptr)
14881524 return nullptr;
1489 scope_block->node->data.block.statements.append(maybe_suppress_result(c, ResultUsedNo, lhs));
1525 scope_block->node->data.block.statements.append(lhs);
14901526
1491 AstNode *rhs = trans_expr(c, result_used, &scope_block->base, stmt->getRHS(), TransRValue);
1527 AstNode *rhs = trans_expr(c, ResultUsedYes, &scope_block->base, stmt->getRHS(), TransRValue);
14921528 if (rhs == nullptr)
14931529 return nullptr;
1494 scope_block->node->data.block.statements.append(trans_create_node_break(c, label_name, rhs));
1495 return scope_block->node;
1530
1531 rhs = trans_create_node_break(c, label_name, rhs);
1532 scope_block->node->data.block.statements.append(rhs);
1533 return maybe_suppress_result(c, result_used, scope_block->node);
14961534 }
14971535 case clang::BO_MulAssign:
14981536 case clang::BO_DivAssign:
......@@ -1718,7 +1756,7 @@ static AstNode *trans_compound_assign_operator(Context *c, ResultUsed result_use
17181756 zig_unreachable();
17191757}
17201758
1721static AstNode *trans_implicit_cast_expr(Context *c, TransScope *scope, const clang::ImplicitCastExpr *stmt) {
1759static AstNode *trans_implicit_cast_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::ImplicitCastExpr *stmt) {
17221760 switch (stmt->getCastKind()) {
17231761 case clang::CK_LValueToRValue:
17241762 return trans_expr(c, ResultUsedYes, scope, stmt->getSubExpr(), TransRValue);
......@@ -1727,8 +1765,9 @@ static AstNode *trans_implicit_cast_expr(Context *c, TransScope *scope, const cl
17271765 AstNode *target_node = trans_expr(c, ResultUsedYes, scope, stmt->getSubExpr(), TransRValue);
17281766 if (target_node == nullptr)
17291767 return nullptr;
1730 return trans_c_cast(c, stmt->getExprLoc(), stmt->getType(),
1768 AstNode *node = trans_c_cast(c, stmt->getExprLoc(), stmt->getType(),
17311769 stmt->getSubExpr()->getType(), target_node);
1770 return maybe_suppress_result(c, result_used, node);
17321771 }
17331772 case clang::CK_FunctionToPointerDecay:
17341773 case clang::CK_ArrayToPointerDecay:
......@@ -1736,7 +1775,7 @@ static AstNode *trans_implicit_cast_expr(Context *c, TransScope *scope, const cl
17361775 AstNode *target_node = trans_expr(c, ResultUsedYes, scope, stmt->getSubExpr(), TransRValue);
17371776 if (target_node == nullptr)
17381777 return nullptr;
1739 return target_node;
1778 return maybe_suppress_result(c, result_used, target_node);
17401779 }
17411780 case clang::CK_BitCast:
17421781 {
......@@ -1753,7 +1792,7 @@ static AstNode *trans_implicit_cast_expr(Context *c, TransScope *scope, const cl
17531792 AstNode *node = trans_create_node_builtin_fn_call_str(c, "ptrCast");
17541793 node->data.fn_call_expr.params.append(dest_type_node);
17551794 node->data.fn_call_expr.params.append(target_node);
1756 return node;
1795 return maybe_suppress_result(c, result_used, node);
17571796 }
17581797 case clang::CK_NullToPointer:
17591798 return trans_create_node_unsigned(c, 0);
......@@ -2746,7 +2785,9 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *
27462785 return node;
27472786}
27482787
2749static AstNode *trans_member_expr(Context *c, TransScope *scope, const clang::MemberExpr *stmt) {
2788static AstNode *trans_member_expr(Context *c, ResultUsed result_used, TransScope *scope,
2789 const clang::MemberExpr *stmt)
2790{
27502791 AstNode *container_node = trans_expr(c, ResultUsedYes, scope, stmt->getBase(), TransRValue);
27512792 if (container_node == nullptr)
27522793 return nullptr;
......@@ -2758,10 +2799,10 @@ static AstNode *trans_member_expr(Context *c, TransScope *scope, const clang::Me
27582799 const char *name = decl_name(stmt->getMemberDecl());
27592800
27602801 AstNode *node = trans_create_node_field_access_str(c, container_node, name);
2761 return node;
2802 return maybe_suppress_result(c, result_used, node);
27622803}
27632804
2764static AstNode *trans_array_subscript_expr(Context *c, TransScope *scope, const clang::ArraySubscriptExpr *stmt) {
2805static AstNode *trans_array_subscript_expr(Context *c, ResultUsed result_used, TransScope *scope, const clang::ArraySubscriptExpr *stmt) {
27652806 AstNode *container_node = trans_expr(c, ResultUsedYes, scope, stmt->getBase(), TransRValue);
27662807 if (container_node == nullptr)
27672808 return nullptr;
......@@ -2774,13 +2815,13 @@ static AstNode *trans_array_subscript_expr(Context *c, TransScope *scope, const
27742815 AstNode *node = trans_create_node(c, NodeTypeArrayAccessExpr);
27752816 node->data.array_access_expr.array_ref_expr = container_node;
27762817 node->data.array_access_expr.subscript = idx_node;
2777 return node;
2818 return maybe_suppress_result(c, result_used, node);
27782819}
27792820
27802821static AstNode *trans_c_style_cast_expr(Context *c, ResultUsed result_used, TransScope *scope,
27812822 const clang::CStyleCastExpr *stmt, TransLRValue lrvalue)
27822823{
2783 AstNode *sub_expr_node = trans_expr(c, result_used, scope, stmt->getSubExpr(), lrvalue);
2824 AstNode *sub_expr_node = trans_expr(c, ResultUsedYes, scope, stmt->getSubExpr(), lrvalue);
27842825 if (sub_expr_node == nullptr)
27852826 return nullptr;
27862827
......@@ -2791,8 +2832,8 @@ static AstNode *trans_c_style_cast_expr(Context *c, ResultUsed result_used, Tran
27912832 return maybe_suppress_result(c, result_used, cast);
27922833}
27932834
2794static AstNode *trans_unary_expr_or_type_trait_expr(Context *c, TransScope *scope,
2795 const clang::UnaryExprOrTypeTraitExpr *stmt)
2835static AstNode *trans_unary_expr_or_type_trait_expr(Context *c, ResultUsed result_used,
2836 TransScope *scope, const clang::UnaryExprOrTypeTraitExpr *stmt)
27962837{
27972838 AstNode *type_node = trans_qual_type(c, stmt->getTypeOfArgument(), stmt->getLocStart());
27982839 if (type_node == nullptr)
......@@ -2800,7 +2841,7 @@ static AstNode *trans_unary_expr_or_type_trait_expr(Context *c, TransScope *scop
28002841
28012842 AstNode *node = trans_create_node_builtin_fn_call_str(c, "sizeOf");
28022843 node->data.fn_call_expr.params.append(type_node);
2803 return node;
2844 return maybe_suppress_result(c, result_used, node);
28042845}
28052846
28062847static AstNode *trans_do_loop(Context *c, TransScope *parent_scope, const clang::DoStmt *stmt) {
......@@ -3078,11 +3119,13 @@ static int trans_switch_default(Context *c, TransScope *parent_scope, const clan
30783119 return ErrorNone;
30793120}
30803121
3081static AstNode *trans_string_literal(Context *c, TransScope *scope, const clang::StringLiteral *stmt) {
3122static AstNode *trans_string_literal(Context *c, ResultUsed result_used, TransScope *scope, const clang::StringLiteral *stmt) {
30823123 switch (stmt->getKind()) {
30833124 case clang::StringLiteral::Ascii:
3084 case clang::StringLiteral::UTF8:
3085 return trans_create_node_str_lit_c(c, string_ref_to_buf(stmt->getString()));
3125 case clang::StringLiteral::UTF8: {
3126 AstNode *node = trans_create_node_str_lit_c(c, string_ref_to_buf(stmt->getString()));
3127 return maybe_suppress_result(c, result_used, node);
3128 }
30863129 case clang::StringLiteral::UTF16:
30873130 emit_warning(c, stmt->getLocStart(), "TODO support UTF16 string literals");
30883131 return nullptr;
......@@ -3114,8 +3157,10 @@ static AstNode *trans_continue_stmt(Context *c, TransScope *scope, const clang::
31143157 return trans_create_node(c, NodeTypeContinue);
31153158}
31163159
3117static AstNode *trans_predefined_expr(Context *c, TransScope *scope, const clang::PredefinedExpr *expr) {
3118 return trans_string_literal(c, scope, expr->getFunctionName());
3160static AstNode *trans_predefined_expr(Context *c, ResultUsed result_used, TransScope *scope,
3161 const clang::PredefinedExpr *expr)
3162{
3163 return trans_string_literal(c, result_used, scope, expr->getFunctionName());
31193164}
31203165
31213166static int wrap_stmt(AstNode **out_node, TransScope **out_scope, TransScope *in_scope, AstNode *result_node) {
......@@ -3142,7 +3187,7 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const clang::Stmt *st
31423187 trans_compound_stmt(c, scope, (const clang::CompoundStmt *)stmt, out_node_scope));
31433188 case clang::Stmt::IntegerLiteralClass:
31443189 return wrap_stmt(out_node, out_child_scope, scope,
3145 trans_integer_literal(c, (const clang::IntegerLiteral *)stmt));
3190 trans_integer_literal(c, result_used, (const clang::IntegerLiteral *)stmt));
31463191 case clang::Stmt::ConditionalOperatorClass:
31473192 return wrap_stmt(out_node, out_child_scope, scope,
31483193 trans_conditional_operator(c, result_used, scope, (const clang::ConditionalOperator *)stmt));
......@@ -3154,7 +3199,7 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const clang::Stmt *st
31543199 trans_compound_assign_operator(c, result_used, scope, (const clang::CompoundAssignOperator *)stmt));
31553200 case clang::Stmt::ImplicitCastExprClass:
31563201 return wrap_stmt(out_node, out_child_scope, scope,
3157 trans_implicit_cast_expr(c, scope, (const clang::ImplicitCastExpr *)stmt));
3202 trans_implicit_cast_expr(c, result_used, scope, (const clang::ImplicitCastExpr *)stmt));
31583203 case clang::Stmt::DeclRefExprClass:
31593204 return wrap_stmt(out_node, out_child_scope, scope,
31603205 trans_decl_ref_expr(c, scope, (const clang::DeclRefExpr *)stmt, lrvalue));
......@@ -3190,23 +3235,23 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const clang::Stmt *st
31903235 return ErrorNone;
31913236 case clang::Stmt::MemberExprClass:
31923237 return wrap_stmt(out_node, out_child_scope, scope,
3193 trans_member_expr(c, scope, (const clang::MemberExpr *)stmt));
3238 trans_member_expr(c, result_used, scope, (const clang::MemberExpr *)stmt));
31943239 case clang::Stmt::ArraySubscriptExprClass:
31953240 return wrap_stmt(out_node, out_child_scope, scope,
3196 trans_array_subscript_expr(c, scope, (const clang::ArraySubscriptExpr *)stmt));
3241 trans_array_subscript_expr(c, result_used, scope, (const clang::ArraySubscriptExpr *)stmt));
31973242 case clang::Stmt::CStyleCastExprClass:
31983243 return wrap_stmt(out_node, out_child_scope, scope,
31993244 trans_c_style_cast_expr(c, result_used, scope, (const clang::CStyleCastExpr *)stmt, lrvalue));
32003245 case clang::Stmt::UnaryExprOrTypeTraitExprClass:
32013246 return wrap_stmt(out_node, out_child_scope, scope,
3202 trans_unary_expr_or_type_trait_expr(c, scope, (const clang::UnaryExprOrTypeTraitExpr *)stmt));
3247 trans_unary_expr_or_type_trait_expr(c, result_used, scope, (const clang::UnaryExprOrTypeTraitExpr *)stmt));
32033248 case clang::Stmt::ForStmtClass: {
32043249 AstNode *node = trans_for_loop(c, scope, (const clang::ForStmt *)stmt);
32053250 return wrap_stmt(out_node, out_child_scope, scope, node);
32063251 }
32073252 case clang::Stmt::StringLiteralClass:
32083253 return wrap_stmt(out_node, out_child_scope, scope,
3209 trans_string_literal(c, scope, (const clang::StringLiteral *)stmt));
3254 trans_string_literal(c, result_used, scope, (const clang::StringLiteral *)stmt));
32103255 case clang::Stmt::BreakStmtClass:
32113256 return wrap_stmt(out_node, out_child_scope, scope,
32123257 trans_break_stmt(c, scope, (const clang::BreakStmt *)stmt));
......@@ -3513,7 +3558,7 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const clang::Stmt *st
35133558 return ErrorUnexpected;
35143559 case clang::Stmt::PredefinedExprClass:
35153560 return wrap_stmt(out_node, out_child_scope, scope,
3516 trans_predefined_expr(c, scope, (const clang::PredefinedExpr *)stmt));
3561 trans_predefined_expr(c, result_used, scope, (const clang::PredefinedExpr *)stmt));
35173562 case clang::Stmt::PseudoObjectExprClass:
35183563 emit_warning(c, stmt->getLocStart(), "TODO handle C PseudoObjectExprClass");
35193564 return ErrorUnexpected;
......@@ -3525,7 +3570,7 @@ static int trans_stmt_extra(Context *c, TransScope *scope, const clang::Stmt *st
35253570 return ErrorUnexpected;
35263571 case clang::Stmt::StmtExprClass:
35273572 return wrap_stmt(out_node, out_child_scope, scope,
3528 trans_stmt_expr(c, scope, (const clang::StmtExpr *)stmt, out_node_scope));
3573 trans_stmt_expr(c, result_used, scope, (const clang::StmtExpr *)stmt, out_node_scope));
35293574 case clang::Stmt::SubstNonTypeTemplateParmExprClass:
35303575 emit_warning(c, stmt->getLocStart(), "TODO handle C SubstNonTypeTemplateParmExprClass");
35313576 return ErrorUnexpected;
test/translate_c.zig+23-3
......@@ -67,9 +67,29 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
6767 \\}
6868 ,
6969 \\pub fn foo() void {
70 \\ c"foo";
71 \\ c"foo";
72 \\ c"void foo(void)";
70 \\ _ = c"foo";
71 \\ _ = c"foo";
72 \\ _ = c"void foo(void)";
73 \\}
74 );
75
76 cases.add("ignore result",
77 \\void foo() {
78 \\ int a;
79 \\ 1;
80 \\ "hey";
81 \\ 1 + 1;
82 \\ 1 - 1;
83 \\ a = 1;
84 \\}
85 ,
86 \\pub fn foo() void {
87 \\ var a: c_int = undefined;
88 \\ _ = 1;
89 \\ _ = c"hey";
90 \\ _ = (1 + 1);
91 \\ _ = (1 - 1);
92 \\ a = 1;
7393 \\}
7494 );
7595