Skip to content

Commit 09ef065

Browse files
committed
fix -- operator for floats and booleans
1 parent 0c336db commit 09ef065

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

frontends/hltransform.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,18 +439,19 @@ doSimplifyAssignments(AST **astptr, int insertCasts, int atTopLevel)
439439
break;
440440
case K_INCREMENT:
441441
case K_DECREMENT:
442+
int newop = (op == K_DECREMENT) ? '-' : '+';
442443
/* for ++ and --, handle floats and 64 bit integers by turning into i = i+1 */
443444
/* specifically: i++ -> (tmp = i, i = i+1, tmp)
444445
++i -> (i = i+1, i) */
445446
if (ast->left) {
446447
/* i++ case */
447448
AST *typ = ExprType(ast->left);
448449
if (typ) {
449-
if (IsFloatType(typ) || IsInt64Type(typ)) {
450+
if (IsFloatType(typ) || IsInt64Type(typ) || IsBoolType(typ)) {
450451
AstReportAs(ast, &saveinfo);
451452
AST *temp = AstTempLocalVariable("_temp_", typ);
452453
AST *save = AstAssign(temp, ast->left);
453-
AST *update = AstAssign(ast->left, AstOperator('+', ast->left, AstInteger(1)));
454+
AST *update = AstAssign(ast->left, AstOperator(newop, ast->left, AstInteger(1)));
454455

455456
ast = *astptr = NewAST(AST_SEQUENCE,
456457
NewAST(AST_SEQUENCE, save, update),
@@ -462,11 +463,11 @@ doSimplifyAssignments(AST **astptr, int insertCasts, int atTopLevel)
462463
AST *ident = ast->right;
463464
AST *typ = ExprType(ident);
464465
if (typ) {
465-
if (IsFloatType(typ) || IsInt64Type(typ)) {
466+
if (IsFloatType(typ) || IsInt64Type(typ) || IsBoolType(typ)) {
466467
ast->kind = AST_ASSIGN;
467468
ast->d.ival = K_ASSIGN;
468469
ast->left = ident;
469-
ast->right = AstOperator('+', ident, AstInteger(1));
470+
ast->right = AstOperator(newop, ident, AstInteger(1));
470471
}
471472
}
472473
}

0 commit comments

Comments
 (0)