@@ -363,7 +363,10 @@ NeedIncDecTransform(AST *expr, AST *typ)
363363 if (IsFloatType (typ ) || IsInt64Type (typ ) || IsBoolType (typ ))
364364 return true;
365365 }
366-
366+
367+ /* transform for explicit casts */
368+ if (expr && expr -> kind == AST_CAST )
369+ return true;
367370 /* keep inc/dec for traditional output, or at least be more
368371 conservative about transforms
369372 */
@@ -643,11 +646,12 @@ doSimplifyAssignments(AST **astptr, int insertCasts, int atTopLevel)
643646 */
644647 AST * typ = ExprType (ast -> left );
645648 bool needTransform = NeedIncDecTransform (ast -> left , typ );
649+ int size = typ ? TypeSize (BaseType (typ )) : 1 ;
646650 if (needTransform ) {
647651 AstReportAs (ast , & saveinfo );
648652 AST * temp = AstTempLocalVariable ("_temp_" , typ );
649653 AST * save = AstAssign (temp , ast -> left );
650- AST * update = AstAssign (ast -> left , AstOperator (newop , ast -> left , AstInteger (1 )));
654+ AST * update = AstAssign (ast -> left , AstOperator (newop , ast -> left , AstInteger (size )));
651655
652656 ast = * astptr = NewAST (AST_SEQUENCE ,
653657 NewAST (AST_SEQUENCE , save , update ),
@@ -657,13 +661,14 @@ doSimplifyAssignments(AST **astptr, int insertCasts, int atTopLevel)
657661 } else if (ast -> right ) {
658662 AST * ident = ast -> right ;
659663 AST * typ = ExprType (ident );
664+ int size = typ ? TypeSize (BaseType (typ )) : 1 ;
660665 bool needTransform = NeedIncDecTransform (ast -> right , typ );
661666 if (needTransform ) {
662667 AstReportAs (ast , & saveinfo );
663668 ast -> kind = AST_ASSIGN ;
664669 ast -> d .ival = K_ASSIGN ;
665670 ast -> left = ident ;
666- ast -> right = AstOperator (newop , ident , AstInteger (1 ));
671+ ast -> right = AstOperator (newop , ident , AstInteger (size ));
667672 AstReportDone (& saveinfo );
668673 }
669674 }
0 commit comments