* support/regression/tests/bug1839277.c: new, added
authorMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 21 Mar 2008 22:55:47 +0000 (22:55 +0000)
committerMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 21 Mar 2008 22:55:47 +0000 (22:55 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5112 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
support/regression/tests/bug1839277.c [new file with mode: 0644]

index 67ae67737e7163220985b5cb63e79fdcb755d7cb..86e619de84bb7725d341f7858fa116477b3c375b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
          fixed bug 1839277
        * src/mcs51/gen.c: throughout only output hex constants
        * src/SDCCicode.c (getPtrType, geniCodeCast): fixed code size regression
+       * support/regression/tests/bug1839277.c: new, added
 
 2008-03-21 Philipp Klaus Krause <pkk AT spth.de>
 
diff --git a/support/regression/tests/bug1839277.c b/support/regression/tests/bug1839277.c
new file mode 100644 (file)
index 0000000..78dae84
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+    bug 1839277
+*/
+
+#include <testfwk.h>
+
+code struct Value {
+  code char* Name[2];
+} Values[2]= {{{"abc", "def"}}, {{"ghi", "jkl"}}};
+
+char i=1;
+
+void
+testBug(void)
+{
+       volatile char code* * p;
+       unsigned long v = 0;
+//first subexpression 'Values[0].Name' is evaluted as follows:
+//mov     r2,#_Values
+//mov     r3,#(_Values >> 8)
+//mov     r4,#(_Values >> 16) ;this is wrong - should be 'mov r4,#128' shouldn't it?
+//second subexpression 'Values[1].Name' is evaluted as follows:
+//mov     a,#0x04
+//add     a,#_Values
+//mov     r2,a
+//clr     a
+//addc    a,#(_Values >> 8)
+//mov     r3,a
+//mov     r4,#128 ;this is all right
+       p = i ? Values[0].Name : Values[1].Name;
+#if defined(SDCC_mcs51)
+       v = (unsigned long)p;
+       ASSERT((unsigned char)(v>>16)==0x80);
+#endif
+
+//everything is all right with explicit typecast - but why do I need it?
+       p = i ? (char code**)Values[0].Name : (char code**)Values[1].Name;
+#if defined(SDCC_mcs51)
+       v = (unsigned long)p;
+       ASSERT((unsigned char)(v>>16)==0x80);
+#endif
+
+//this is the best/optimal version - again with explicit typecast
+//Question: Why is it necessary to have explicit typecast to make things right?
+       p = i ? (char code* code*)Values[0].Name : (char code* code*)Values[1].Name;
+#if defined(SDCC_mcs51)
+       v = (unsigned long)p;
+       ASSERT((unsigned char)(v>>16)==0x80);
+#endif
+}