Skip to content

Commit

Permalink
correctly handle casts to void in nucode output
Browse files Browse the repository at this point in the history
  • Loading branch information
totalspectrum committed Jul 26, 2023
1 parent 92e6081 commit bbc6888
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Version 6.2.4
- Added freopen(), tmpfile(), mktemp(), and some other stdio functions
- Added some missing math functions
- Correctly handled casts to void in nucode output
- Fixed some problems with sizeof() used to declare local variables
- Fixed incorrect multiple casting of union initialization
- Several improvements to C locale() related functions
Expand Down
16 changes: 15 additions & 1 deletion backends/nucode/outnu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,11 @@ NuCompileExpression(NuIrList *irl, AST *node) {
}
if (IsConstExpr(node)) {
int64_t val = EvalConstExpr(node);
AST *typ = ExprType(node);
if (IsVoidType(typ)) {
// do not push anything at all
return 0;
}
int siz = TypeSize(ExprType(node));
if (siz <= 4) {
NuEmitConst(irl, (int32_t)val);
Expand Down Expand Up @@ -1654,7 +1659,15 @@ NuCompileExpression(NuIrList *irl, AST *node) {
}
break;
case AST_CAST:
return NuCompileExpression(irl, node->right);
{
int n = NuCompileExpression(irl, node->right);
if (IsVoidType(node->left) && n) {
// ignoring the results, so pop them
NuCompileDrop(irl, n);
n = 0;
}
return n;
}
case AST_DECLARE_VAR:
return NuCompileExpression(irl, node->right);
case AST_SEQUENCE: {
Expand Down Expand Up @@ -2109,6 +2122,7 @@ static void NuCompileStatement(NuIrList *irl, AST *ast) {
case AST_SETJMP:
case AST_CATCH:
case AST_MEMREF:
case AST_CONDRESULT:
n = NuCompileExpression(irl, ast);
NuCompileDrop(irl, n);
break;
Expand Down

0 comments on commit bbc6888

Please sign in to comment.