From d3b1ccb2d5c5999da084145c34cca85b6f8beff1 Mon Sep 17 00:00:00 2001 From: johanknol Date: Sun, 13 Jan 2002 12:19:07 +0000 Subject: [PATCH 1/1] fixed bug #402254 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1793 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCC.y | 20 ++++++++++---------- src/SDCCast.c | 29 ++++++++++++++++++++++++++++- src/SDCCast.h | 1 + src/SDCCglue.c | 3 +++ 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/SDCC.y b/src/SDCC.y index d3767658..83409a13 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -406,34 +406,34 @@ assignment_expr $$ = newNode($2,$1,$3); break; case MUL_ASSIGN: - $$ = newNode('=',$1,newNode('*',copyAst($1),$3)); + $$ = newNode('=',$1,newNode('*',removeIncDecOps(copyAst($1)),$3)); break; case DIV_ASSIGN: - $$ = newNode('=',$1,newNode('/',copyAst($1),$3)); + $$ = newNode('=',$1,newNode('/',removeIncDecOps(copyAst($1)),$3)); break; case MOD_ASSIGN: - $$ = newNode('=',$1,newNode('%',copyAst($1),$3)); + $$ = newNode('=',$1,newNode('%',removeIncDecOps(copyAst($1)),$3)); break; case ADD_ASSIGN: - $$ = newNode('=',$1,newNode('+',copyAst($1),$3)); + $$ = newNode('=',$1,newNode('+',removeIncDecOps(copyAst($1)),$3)); break; case SUB_ASSIGN: - $$ = newNode('=',$1,newNode('-',copyAst($1),$3)); + $$ = newNode('=',$1,newNode('-',removeIncDecOps(copyAst($1)),$3)); break; case LEFT_ASSIGN: - $$ = newNode('=',$1,newNode(LEFT_OP,copyAst($1),$3)); + $$ = newNode('=',$1,newNode(LEFT_OP,removeIncDecOps(copyAst($1)),$3)); break; case RIGHT_ASSIGN: - $$ = newNode('=',$1,newNode(RIGHT_OP,copyAst($1),$3)); + $$ = newNode('=',$1,newNode(RIGHT_OP,removeIncDecOps(copyAst($1)),$3)); break; case AND_ASSIGN: - $$ = newNode('=',$1,newNode('&',copyAst($1),$3)); + $$ = newNode('=',$1,newNode('&',removeIncDecOps(copyAst($1)),$3)); break; case XOR_ASSIGN: - $$ = newNode('=',$1,newNode('^',copyAst($1),$3)); + $$ = newNode('=',$1,newNode('^',removeIncDecOps(copyAst($1)),$3)); break; case OR_ASSIGN: - $$ = newNode('=',$1,newNode('|',copyAst($1),$3)); + $$ = newNode('=',$1,newNode('|',removeIncDecOps(copyAst($1)),$3)); break; default : $$ = NULL; diff --git a/src/SDCCast.c b/src/SDCCast.c index 85ea2852..dfb3ad05 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -210,7 +210,7 @@ copyAstValues (ast * dest, ast * src) /* copyAst - makes a copy of a given astession */ /*-----------------------------------------------------------------*/ ast * -copyAst (ast * src) +copyAst (ast * src) { ast *dest; @@ -256,6 +256,31 @@ exit: } +/*-----------------------------------------------------------------*/ +/* removeIncDecOps: remove for side effects in *_ASSIGN's */ +/* "*s++ += 3" -> "*s++ = *s++ + 3" */ +/*-----------------------------------------------------------------*/ +ast *removeIncDecOps (ast * tree) { + + // traverse the tree and remove inc/dec ops + + if (!tree) + return NULL; + + if (tree->type == EX_OP && + (tree->opval.op == INC_OP || tree->opval.op == DEC_OP)) { + if (tree->left) + tree=tree->left; + else + tree=tree->right; + } + + tree->left=removeIncDecOps(tree->left); + tree->right=removeIncDecOps(tree->right); + + return tree; +} + /*-----------------------------------------------------------------*/ /* hasSEFcalls - returns TRUE if tree has a function call */ /*-----------------------------------------------------------------*/ @@ -2946,6 +2971,7 @@ decorateType (ast * tree) return tree; +#if 0 // assignment operators are converted by the parser /*------------------------------------------------------------------*/ /*----------------------------*/ /* assignment operators */ @@ -3078,6 +3104,7 @@ decorateType (ast * tree) tree->opval.op = '='; return tree; +#endif /*------------------------------------------------------------------*/ /*----------------------------*/ diff --git a/src/SDCCast.h b/src/SDCCast.h index 31a12ace..d42b7c6c 100644 --- a/src/SDCCast.h +++ b/src/SDCCast.h @@ -180,6 +180,7 @@ ast *newAst_STMNT (unsigned val); void initAst (); ast *newNode (long, ast *, ast *); ast *copyAst (ast *); +ast *removeIncDecOps (ast *); value *sizeofOp (sym_link *); value *evalStmnt (ast *); ast *createFunction (symbol *, ast *); diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 9a4c15fa..4033ed53 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -158,6 +158,9 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag) ast *ival = NULL; memmap *segment; + if (!map) + return; + if (addPublics) { /* PENDING: special case here - should remove */ -- 2.30.2