From 40b04e016f0390381414b38643fd5b6f4184974d Mon Sep 17 00:00:00 2001 From: MaartenBrock Date: Sat, 22 Mar 2008 11:58:36 +0000 Subject: [PATCH] * src/mcs51/gen.c (adjustArithmeticResult): fixed bug 1839299 * support/regression/tests/bug1839277.c: added related testBug1839299 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5113 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 5 ++ src/mcs51/gen.c | 74 ++++++++++++++++++--------- support/regression/tests/bug1839277.c | 28 +++++++++- 3 files changed, 80 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 86e619de..923e2a98 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-03-22 Maarten Brock + + * src/mcs51/gen.c (adjustArithmeticResult): fixed bug 1839299 + * support/regression/tests/bug1839277.c: added related testBug1839299 + 2008-03-21 Maarten Brock * src/ds390/gen.c (opIsGptr, adjustArithmeticResult, genAddrOf, genAssign), diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index a8086d65..a5da703f 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -4425,34 +4425,58 @@ adjustArithmeticResult (iCode * ic) static void adjustArithmeticResult (iCode * ic) { - if (opIsGptr (IC_RESULT (ic)) && - opIsGptr (IC_LEFT (ic)) && - !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic)))) + if (opIsGptr (IC_RESULT (ic))) { - aopPut (IC_RESULT (ic), - aopGet (IC_LEFT (ic), GPTRSIZE - 1, FALSE, FALSE), - GPTRSIZE - 1); - } + char buffer[10]; - if (opIsGptr (IC_RESULT (ic)) && - opIsGptr (IC_RIGHT (ic)) && - !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic)))) - { - aopPut (IC_RESULT (ic), - aopGet (IC_RIGHT (ic), GPTRSIZE - 1, FALSE, FALSE), - GPTRSIZE - 1); - } + if (opIsGptr (IC_LEFT (ic))) + { + if (!sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic)))) + { + aopPut (IC_RESULT (ic), + aopGet (IC_LEFT (ic), GPTRSIZE - 1, FALSE, FALSE), + GPTRSIZE - 1); + } + return; + } - if (opIsGptr (IC_RESULT (ic)) && - IC_LEFT (ic) && AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE && - IC_RIGHT (ic) && AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE && - !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) && - !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic)))) - { - char buffer[10]; - SNPRINTF (buffer, sizeof(buffer), - "#0x%02x", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL)); - aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1); + if (opIsGptr (IC_RIGHT (ic))) + { + if (!sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic)))) + { + aopPut (IC_RESULT (ic), + aopGet (IC_RIGHT (ic), GPTRSIZE - 1, FALSE, FALSE), + GPTRSIZE - 1); + } + return; + } + + if (IC_LEFT (ic) && AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE && + IC_RIGHT (ic) && AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE && + !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) && + !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic)))) + { + SNPRINTF (buffer, sizeof(buffer), + "#0x%02x", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL)); + aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1); + return; + } + if (IC_LEFT (ic) && AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE && + !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic)))) + { + SNPRINTF (buffer, sizeof(buffer), + "#0x%02x", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL)); + aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1); + return; + } + if (IC_RIGHT (ic) && AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE && + !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic)))) + { + SNPRINTF (buffer, sizeof(buffer), + "#0x%02x", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_RIGHT (ic)))), NULL, NULL)); + aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1); + return; + } } } #endif diff --git a/support/regression/tests/bug1839277.c b/support/regression/tests/bug1839277.c index 78dae846..4c473284 100644 --- a/support/regression/tests/bug1839277.c +++ b/support/regression/tests/bug1839277.c @@ -1,5 +1,5 @@ /* - bug 1839277 + bug 1839277 & 1839299 */ #include @@ -11,7 +11,7 @@ code struct Value { char i=1; void -testBug(void) +testBug1839277(void) { volatile char code* * p; unsigned long v = 0; @@ -48,3 +48,27 @@ testBug(void) ASSERT((unsigned char)(v>>16)==0x80); #endif } + +void +testBug1839299(void) +{ + volatile char code* * p; + unsigned long v = 0; +//'Values[0].Name' subexpression is evaluated as follows first: +//mov r2,#_Values +//mov r3,#(_Values >> 8) +//mov r4,#(_Values >> 16) ;this is wrong - see bug 1839277 + p= i ? Values[0].Name : Values[1].Name; +//this assignment has some sideeffect on the following one +//in fact it is the evaluation of 'Values[0].Name' itself has the effect, not the assignment + p= Values[0].Name; +//'Values[0].Name' subexpression is evaluated as follows second: +//mov r2,#_Values +//mov r3,#(_Values >> 8) +//mov r4,#0x00 ;this is different from first occurrence but also wrong + p= i ? Values[0].Name : Values[1].Name; +#if defined(SDCC_mcs51) + v = (unsigned long)p; + ASSERT((unsigned char)(v>>16)==0x80); +#endif +} -- 2.30.2