* src/mcs51/gen.c (toBoolean): fixed bug 1065458
authormaartenbrock <maartenbrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 14 Nov 2004 11:53:10 +0000 (11:53 +0000)
committermaartenbrock <maartenbrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 14 Nov 2004 11:53:10 +0000 (11:53 +0000)
* device/lib/Makefile.in: z80 uses printf_large.c, sprintf.c and
  vprintf.c now
* device/lib/printf_large.c (calculate_digit): fixed bug 1057979
* device/lib/z80/Makefile: don't use printf.c as it fails bug 1057979
  WARNING: remove device/lib/build/z80/printf.o by hand when
  updating from previous build!
* device/lib/z80/printf.c: updated comment
* support/regression/tests/bug1057979.c: test all ports now
* support/regression/tests/bug1065458.c: file added

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

ChangeLog
device/lib/Makefile.in
device/lib/printf_large.c
device/lib/z80/Makefile
device/lib/z80/printf.c
src/mcs51/gen.c
support/regression/tests/bug1057979.c
support/regression/tests/bug1065458.c [new file with mode: 0644]

index acd6c943b32ffd8dd6569955b80604b2960d995f..8a90d5e28daea2d024cc4dab5c86d5be63144d55 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,23 @@
+2004-11-11 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/mcs51/gen.c (toBoolean): fixed bug 1065458
+       * device/lib/Makefile.in: z80 uses printf_large.c, sprintf.c and
+         vprintf.c now
+       * device/lib/printf_large.c (calculate_digit): fixed bug 1057979
+       * device/lib/z80/Makefile: don't use printf.c as it fails bug 1057979
+         WARNING: remove device/lib/build/z80/printf.o by hand when
+         updating from previous build!
+       * device/lib/z80/printf.c: updated comment
+       * support/regression/tests/bug1057979.c: test all ports now
+       * support/regression/tests/bug1065458.c: file added
+
 2004-11-12 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
 
        * src/z80/gen.c (genFunction, genEndFunction): avoided generating
          *_start and *_end symbols for static functions
 
 2004-11-11 Maarten Brock <sourceforge.brock AT dse.nl>
-       
+
        * src/SDCCmain.c (linkEdit): don't suppress crt0 if --nostdlib is used
          and search crt0.o in all library paths,
          (setIncludePath): proper handling of --nostdinc,
index 447ef06b410ac6b7a5adc9438cf617b73782dcb2..7f542c83d63e35d64faf3cb3bff5e79d98098fff 100644 (file)
@@ -83,12 +83,12 @@ Z80SOURCES      = _atof.c _atoi.c \
                  _strcspn.c _strlen.c _strncat.c _strncmp.c \
                  _strncpy.c _strpbrk.c _strrchr.c _strspn.c \
                  _strstr.c _strtok.c \
-                 puts.c gets.c \
                  assert.c \
                  _modslong.c _modulong.c \
                  _mullong.c \
                  _divslong.c _divulong.c \
                  calloc.c malloc.c realloc.c free.c \
+                 printf_large.c sprintf.c vprintf.c puts.c gets.c \
                  _fs2schar.c _fs2sint.c _fs2slong.c \
                  _fs2uchar.c _fs2uint.c _fs2ulong.c _fsadd.c \
                  _fsdiv.c _fseq.c _fsgt.c _fslt.c _fsmul.c \
index e2a99447880e60247404003e548deed995ba5a80..cad0a0476f93a0b0d7e63b5d4a8a1680535ee3de 100644 (file)
@@ -183,7 +183,7 @@ static void calculate_digit( value_t* value, unsigned char radix )
     if (radix <= value->byte[4] )
     {
       value->byte[4] -= radix;
-      value->byte[0]++;
+      value->ul |= 1;
     }
   }
 }
@@ -200,7 +200,7 @@ static void calculate_digit( unsigned char radix )
     if (radix <= value.byte[4] )
     {
       value.byte[4] -= radix;
-      value.byte[0]++;
+      value.ul |= 1;
     }
   }
 }
@@ -648,12 +648,6 @@ get_conversion_spec:
         if (char_argument)
         {
           value.l = va_arg(ap,char);
-          if (!signed_argument)
-          {
-            value.byte[1] = 0x00;
-            value.byte[2] = 0x00;
-            value.byte[3] = 0x00;
-          }
         }
         else if (long_argument)
         {
@@ -662,11 +656,6 @@ get_conversion_spec:
         else // must be int
         {
           value.l = va_arg(ap,int);
-          if (!signed_argument)
-          {
-            value.byte[2] = 0x00;
-            value.byte[3] = 0x00;
-          }
         }
 
         if ( signed_argument )
index ae0e16f4ed7f05947da80b0e8e44457d9213b7da..fad51ae981325b4c9a731dee7c7cc914859653bd 100644 (file)
@@ -5,8 +5,7 @@ TOPDIR = ../../..
 SCC = $(TOPDIR)/bin/sdcc -mz80
 SAS = $(TOPDIR)/bin/as-z80
 
-OBJ = div.o mul.o putchar.o printf.o shift.o stubs.o crt0_rle.o heap.o \
-       fstubs.o
+OBJ = div.o mul.o putchar.o shift.o stubs.o crt0_rle.o heap.o fstubs.o
 
 LIB = z80.lib
 CC = $(SCC)
index a81b4e80cd5924f900f48bb7df8ca26bc0e397fc..65c25b9732de3f67423291f52d37a502d49ea267 100644 (file)
@@ -1,5 +1,5 @@
 /** Simple printf implementation
-    Again a stub - will use the std one later...
+    This stub has been replaced by the std printf_large / sprintf / vprintf
 */
 
 #include <stdarg.h>
index 5cea9722c0c00d082e9a0eaec04ce094afcbee9e..4f0f8054166e9118cea9e97dabb9049de02140ce 100644 (file)
@@ -1590,28 +1590,30 @@ toBoolean (operand * oper)
 {
   int size = AOP_SIZE (oper) - 1;
   int offset = 1;
-  char *l = aopGet (AOP (oper), 0, FALSE, FALSE);
+  bool AccUsed = FALSE;
   bool pushedB;
 
-  if (!strncmp (l, "a", 2) || !strncmp (l, "acc", 4))
+  while (!AccUsed && size--)
     {
-      if (size--)
+      AccUsed |= aopGetUsesAcc(AOP (oper), offset++);
+    }
+
+  size = AOP_SIZE (oper) - 1;
+  offset = 1;
+  MOVA (aopGet (AOP (oper), 0, FALSE, FALSE));
+  if (AccUsed && (AOP (oper)->type != AOP_ACC))
+    {
+      pushedB = pushB ();
+      emitcode("mov", "b,a");
+      while (size--)
         {
-          pushedB = pushB ();
-          emitcode("mov", "b,a");
-          while (size--)
-            {
-              MOVA (aopGet (AOP (oper), offset++, FALSE, FALSE));
-              emitcode ("orl", "b,a");
-            }
-          MOVA (aopGet (AOP (oper), offset, FALSE, FALSE));
-          emitcode ("orl", "a,b");
-          popB (pushedB);
+          MOVA (aopGet (AOP (oper), offset++, FALSE, FALSE));
+          emitcode ("orl", "b,a");
         }
+      popB (pushedB);
     }
   else
     {
-      MOVA (l);
       while (size--)
         {
           emitcode ("orl", "a,%s", aopGet (AOP (oper), offset++, FALSE, FALSE));
@@ -2768,26 +2770,23 @@ genFunction (iCode * ic)
     }
 
 
-  if (IFFUNC_ISREENT (sym->type) || options.stackAuto)
+  if (reentrant)
     {
-
       if (options.useXstack)
         {
-          if (!accIsFree)
-            emitcode ("push", "acc");
-          emitcode ("mov", "r0,%s", spname);
-          emitcode ("mov", "a,_bp");
-          emitcode ("movx", "@r0,a");
-          emitcode ("inc", "%s", spname);
-          if (!accIsFree)
-            emitcode ("pop", "acc");
+              emitcode ("inc", "%s", spname);
+              emitcode ("mov", "r0,%s", spname);
+              emitcode ("xch", "a,_bp");
+              emitcode ("movx", "@r0,a");
+              emitcode ("mov", "a,r0");
+              emitcode ("xch", "a,_bp");
         }
       else
         {
           /* set up the stack */
           emitcode ("push", "_bp");     /* save the callers stack  */
+          emitcode ("mov", "_bp,%s", spname);
         }
-      emitcode ("mov", "_bp,%s", spname);
     }
 
   /* For some cases it is worthwhile to perform a RECEIVE iCode */
@@ -2853,7 +2852,6 @@ genFunction (iCode * ic)
   /* adjust the stack for the function */
   if (stackAdjust)
     {
-
       int i = stackAdjust;
       if (i > 256)
         werror (W_STACK_OVERFLOW, sym->name);
@@ -2934,12 +2932,13 @@ genFunction (iCode * ic)
 static void
 genEndFunction (iCode * ic)
 {
-  symbol *sym = OP_SYMBOL (IC_LEFT (ic));
+  symbol   *sym = OP_SYMBOL (IC_LEFT (ic));
   lineNode *lnp = lineCurr;
-  bitVect *regsUsed;
-  bitVect *regsUsedPrologue;
-  bitVect *regsUnneeded;
-  int idx;
+  bitVect  *regsUsed;
+  bitVect  *regsUsedPrologue;
+  bitVect  *regsUnneeded;
+  int      accIsFree = sym->recvSize < 4;
+  int      idx;
 
   _G.currentFunc = NULL;
   if (IFFUNC_ISNAKED(sym->type))
@@ -2966,20 +2965,24 @@ genEndFunction (iCode * ic)
      local stack */
   if (options.useXstack && sym->stack)
     {
+      if (!accIsFree)
+        emitcode ("push", "acc");
       emitcode ("mov", "a,sp");
       emitcode ("add", "a,#0x%02x", ((char) -sym->stack) & 0xff);
       emitcode ("mov", "sp,a");
+      if (!accIsFree)
+        emitcode ("pop", "acc");
     }
 
-
   if ((IFFUNC_ISREENT (sym->type) || options.stackAuto))
     {
       if (options.useXstack)
         {
+          emitcode ("xch", "a,_bp");
           emitcode ("mov", "r0,%s", spname);
           emitcode ("movx", "a,@r0");
-          emitcode ("mov", "_bp,a");
-          emitcode ("dec", "%s", spname);
+          emitcode ("xch", "a,_bp");
+          emitcode ("dec", "%s", spname); //read before freeing stack space (interrupts)
         }
       else
         {
@@ -4992,7 +4995,7 @@ genCmpGt (iCode * ic, iCode * ifx)
   aopOp (right, ic, FALSE);
   aopOp (result, ic, TRUE);
 
-  genCmp (right, left, result, ifx, sign,ic);
+  genCmp (right, left, result, ifx, sign, ic);
 
   freeAsmop (result, NULL, ic, TRUE);
 }
@@ -10162,20 +10165,22 @@ genCritical (iCode *ic)
   D(emitcode(";     genCritical",""));
 
   if (IC_RESULT (ic))
-    aopOp (IC_RESULT (ic), ic, TRUE);
-
-  emitcode ("setb", "c");
-  emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */
-  emitcode ("clr", "c");
-  emitcode ("", "%05d$:", (tlbl->key + 100));
-
-  if (IC_RESULT (ic))
-    outBitC (IC_RESULT (ic)); /* save old ea in an operand */
+    {
+      aopOp (IC_RESULT (ic), ic, TRUE);
+      aopPut (AOP (IC_RESULT (ic)), one, 0, 0);
+      emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */
+      aopPut (AOP (IC_RESULT (ic)), zero, 0, 0);
+      emitcode ("", "%05d$:", (tlbl->key + 100));
+      freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+    }
   else
-    emitcode ("push", "psw"); /* save old ea via c in psw on top of stack*/
-
-  if (IC_RESULT (ic))
-    freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+    {
+      emitcode ("setb", "c");
+      emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */
+      emitcode ("clr", "c");
+      emitcode ("", "%05d$:", (tlbl->key + 100));
+      emitcode ("push", "psw"); /* save old ea via c in psw on top of stack*/
+    }
 }
 
 /*-----------------------------------------------------------------*/
@@ -10196,7 +10201,8 @@ genEndCritical (iCode *ic)
         }
       else
         {
-          MOVA (aopGet (AOP (IC_RIGHT (ic)), 0, FALSE, FALSE));
+          if (AOP_TYPE (IC_RIGHT (ic)) != AOP_DUMMY)
+            MOVA (aopGet (AOP (IC_RIGHT (ic)), 0, FALSE, FALSE));
           emitcode ("rrc", "a");
           emitcode ("mov", "ea,c");
         }
index 202149f59acaf42c93d4daf53caf5a25d09a374c..258774959680b93b540fc8b4e8b10b23578caf08 100644 (file)
@@ -14,8 +14,6 @@ test_sprintf(void)
 {
   s[12] = 0x12;
 
-#if defined(SDCC_mcs51) || defined(SDCC_ds390) || defined(PORT_HOST)
-//This still fails dramatically for hc08 and z80
   sprintf( s, "%d", 99 );
   ASSERT( 0 == strcmp( s, "99" ) );
   sprintf( s, "%d", 100 );
@@ -24,7 +22,6 @@ test_sprintf(void)
   ASSERT( 0 == strcmp( s, "2004" ) );
   sprintf( s, "%ld", 2147483647L );
   ASSERT( 0 == strcmp( s, "2147483647" ) );
-#endif
 
   ASSERT( s[12]==0x12 );
 }
diff --git a/support/regression/tests/bug1065458.c b/support/regression/tests/bug1065458.c
new file mode 100644 (file)
index 0000000..2495b87
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+   bug1065458.c
+*/
+
+#include <testfwk.h>
+
+unsigned short f()
+{
+  return 0xff00;
+}
+
+unsigned short g()
+{
+  return f() ? 1 : 0;
+}
+
+void
+test_1065458(void)
+{
+  ASSERT( 1 == g() );
+}