diff options
| -rw-r--r-- | justfile | 3 | ||||
| -rw-r--r-- | src/codegen.c | 4 | ||||
| -rw-r--r-- | tests/cast_expressions.sh | 17 |
3 files changed, 24 insertions, 0 deletions
@@ -36,3 +36,6 @@ test-all: clean: rm -rf build rm -rf tests/tmp + +fmt: + nix fmt diff --git a/src/codegen.c b/src/codegen.c index be8acd7..e0e0b19 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -148,6 +148,10 @@ static void codegen_deref_expr(CodeGen* g, AstNode* ast, GenMode gen_mode) { static void codegen_cast_expr(CodeGen* g, AstNode* ast) { codegen_expr(g, ast->node_operand, GenMode_rval); + // (void) cast does nothing. + if (ast->ty->kind == TypeKind_void) + return; + int src_size = type_sizeof(ast->node_operand->ty); int dst_size = type_sizeof(ast->ty); diff --git a/tests/cast_expressions.sh b/tests/cast_expressions.sh index f6824ad..b493e04 100644 --- a/tests/cast_expressions.sh +++ b/tests/cast_expressions.sh @@ -152,3 +152,20 @@ int main() { return 0; } EOF + +cat <<'EOF' > expected +42 +EOF +test_diff <<'EOF' +int printf(const char*, ...); + +int f() { + return printf("42\n"); +} + +int main() { + (void)123; + (void)(5 + 6 + 7); + (void)f(); +} +EOF |
