From 8efb55fce2781c1bd6090dee7e0083ea0ae8b91f Mon Sep 17 00:00:00 2001 From: bernhardheld Date: Tue, 17 Jan 2006 23:48:35 +0000 Subject: [PATCH] * src/SDCCast.c (backPatchLabels): fixed bug #1408066: made it inifinitely recurseable, added static * support/regression/tests/bug-1408066.c: added git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4020 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 6 ++++++ src/SDCCast.c | 20 ++++++----------- support/regression/tests/bug-1408066.c | 30 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 support/regression/tests/bug-1408066.c diff --git a/ChangeLog b/ChangeLog index 8325d42c..b4c2f675 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-01-18 Bernhard Held + + * src/SDCCast.c (backPatchLabels): fixed bug #1408066: made it + inifinitely recurseable, added static + * support/regression/tests/bug-1408066.c: added + 2006-01-17 Bernhard Held * src/SDCCicode.h, diff --git a/src/SDCCast.c b/src/SDCCast.c index 3a91217c..285bf5e9 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -59,7 +59,7 @@ ast *optimizeGetHbit (ast *, RESULT_TYPE); ast *optimizeGetAbit (ast *, RESULT_TYPE); ast *optimizeGetByte (ast *, RESULT_TYPE); ast *optimizeGetWord (ast *, RESULT_TYPE); -ast *backPatchLabels (ast *, symbol *, symbol *); +static ast *backPatchLabels (ast *, symbol *, symbol *); void PA(ast *t); int inInitMode = 0; memmap *GcurMemmap=NULL; /* points to the memmap that's currently active */ @@ -4519,11 +4519,12 @@ sizeofOp (sym_link * type) #define IS_IFX(ex) (ex->type == EX_OP && ex->opval.op == IFX ) #define IS_LT(ex) (ex->type == EX_OP && ex->opval.op == '<' ) #define IS_GT(ex) (ex->type == EX_OP && ex->opval.op == '>') +#define IS_NULLOP(ex) (ex->type == EX_OP && ex->opval.op == NULLOP) /*-----------------------------------------------------------------*/ /* backPatchLabels - change and or not operators to flow control */ /*-----------------------------------------------------------------*/ -ast * +static ast * backPatchLabels (ast * tree, symbol * trueLabel, symbol * falseLabel) { @@ -4588,25 +4589,18 @@ backPatchLabels (ast * tree, symbol * trueLabel, symbol * falseLabel) /* change not */ if (IS_NOT (tree)) { - int wasnot = IS_NOT (tree->left); + /* call with exchanged labels */ tree->left = backPatchLabels (tree->left, falseLabel, trueLabel); - /* if the left is already a IFX */ + /* if left isn't already a IFX */ if (!IS_IFX (tree->left)) - tree->left = newNode (IFX, tree->left, NULL); - - if (wasnot) - { - tree->left->trueLabel = trueLabel; - tree->left->falseLabel = falseLabel; - } - else { + tree->left = newNode (IFX, tree->left, NULL); tree->left->trueLabel = falseLabel; tree->left->falseLabel = trueLabel; } return tree->left; - } + } if (IS_IFX (tree)) { diff --git a/support/regression/tests/bug-1408066.c b/support/regression/tests/bug-1408066.c new file mode 100644 index 00000000..00523243 --- /dev/null +++ b/support/regression/tests/bug-1408066.c @@ -0,0 +1,30 @@ +/* + bug-136564.c0 + + loop induction +*/ + +#include + + +void +testBackPatchLabel(void) +{ + volatile unsigned char c0 = 0, c1 = 1; + unsigned char r; + + if ( (c0 == 0)) r = 1; else r = 0; ASSERT(r == 1); + if ( !(c0 == 0)) r = 1; else r = 0; ASSERT(r == 0); + if ( !!(c0 == 0)) r = 1; else r = 0; ASSERT(r == 1); + if ( !!!(c0 == 0)) r = 1; else r = 0; ASSERT(r == 0); + if ( !!!!(c0 == 0)) r = 1; else r = 0; ASSERT(r == 1); + if (!!!!!(c0 == 0)) r = 1; else r = 0; ASSERT(r == 0); + + if ( ((c0 == 0) && (c1 == 1))) r = 1; else r = 0; ASSERT(r == 1); + if ( !((c0 == 0) && (c1 == 1))) r = 1; else r = 0; ASSERT(r == 0); + if ( !!((c0 == 0) && (c1 == 1))) r = 1; else r = 0; ASSERT(r == 1); + + if ( ( (c0 == 0) && (c1 == 1))) r = 1; else r = 0; ASSERT(r == 1); + if ( !( !(c0 == 1) && !(c1 == 0))) r = 1; else r = 0; ASSERT(r == 0); + if ( !!(!!(c0 == 0) && !!(c1 == 1))) r = 1; else r = 0; ASSERT(r == 1); +} -- 2.30.2