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
/*
- bug 1839277
+ bug 1839277 & 1839299
*/
#include <testfwk.h>
char i=1;
void
-testBug(void)
+testBug1839277(void)
{
volatile char code* * p;
unsigned long v = 0;
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
+}