* src/SDCCptropt.c (ptrPseudoSymConvert): fixed bug 1536762
authorMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 4 Mar 2008 14:09:24 +0000 (14:09 +0000)
committerMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 4 Mar 2008 14:09:24 +0000 (14:09 +0000)
* support/regression/tests/bug1536762.c: new, added

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5067 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCptropt.c
support/regression/tests/bug1536762.c [new file with mode: 0644]

index 85d94709139b748bcd689215eaebcad37d6387c2..b3ff931f885b0db7c837f57b8772ddd81d631838 100644 (file)
@@ -249,7 +249,7 @@ ptrBaseRematSym (symbol *ptrsym)
 
 
 /*--------------------------------------------------------------------*/
-/* ptrPseudoSymSafe - check to see if the convertion of the result of */
+/* ptrPseudoSymSafe - check to see if the conversion of the result of */
 /*   a pointerGet of a rematerializable pointer to a pseudo symbol is */
 /*   safe. Returns true if safe, or false if hazards were detected.   */
 /*--------------------------------------------------------------------*/
@@ -375,10 +375,10 @@ void
 ptrPseudoSymConvert (symbol *sym, iCode *dic, char *name)
 {
   symbol *psym = newSymbol (name, 1);
-  psym->type = sym->type;
-  psym->etype = sym->etype;
   psym->psbase = ptrBaseRematSym (OP_SYMBOL (IC_LEFT (dic)));
-                
+  psym->type = sym->type;
+  psym->etype = psym->psbase->etype;
+
   strcpy (psym->rname, psym->name);
   sym->isspilt = 1;
   sym->usl.spillLoc = psym;
diff --git a/support/regression/tests/bug1536762.c b/support/regression/tests/bug1536762.c
new file mode 100644 (file)
index 0000000..8c90163
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+   bug1536762.c
+*/
+
+#include <testfwk.h>
+#include <string.h>
+#include <stdint.h>
+
+xdata uint8_t c = 1;
+
+struct d {
+        xdata struct d *n;
+        uint8_t f;
+        uint8_t s;
+        xdata uint8_t *buffer;
+        uint16_t length;
+};
+
+
+xdata struct d xd = {&xd, 1, 0xab, &c, 3};
+
+
+struct {
+        xdata struct d *c;
+        int16_t count;
+        xdata uint8_t *bptr;
+} s = {&xd, -1, &c};
+
+
+void blurb(void)
+{
+        if (s.count < 0) {
+                s.c->s = 0xef;
+                s.count = s.c->length - 1;
+                s.bptr = s.c->buffer;
+        }
+        *s.bptr = 0;
+        s.bptr++;
+        s.count--;
+}
+
+
+void 
+testBug(void)
+{
+  ASSERT(xd.s == 0xab);
+  ASSERT(s.c->s == 0xab);
+  
+  s.c->s = 0xcd;
+
+  ASSERT(xd.s == 0xcd);
+  ASSERT(s.c->s == 0xcd);
+
+  blurb();
+
+  ASSERT(xd.s == 0xef);
+  ASSERT(s.c->s == 0xef);
+  ASSERT(c == 0);
+}
+