* src/SDCCast.c (decorateType): don't decorate/process parms twice,
authorbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 11 Apr 2004 21:42:02 +0000 (21:42 +0000)
committerbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 11 Apr 2004 21:42:02 +0000 (21:42 +0000)
(processParms): fixed bug #927659: don't copy parms, this will clear decorated flag
* support/regression/tests/bug-927659.c: added

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

ChangeLog
src/SDCCast.c
support/regression/tests/bug-927659.c [new file with mode: 0644]

index d5edd6b699391f339115e7aea22ecae74975e628..73102d6405c859ad1350b4f76e08afd7b7260dfe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,7 +4,11 @@
        (geniCodeLogicAndOr): added in order to fix bug #905492,
        (ast2iCode): fixed bug #905492
        * support/regression/tests/bug-905492.c: added
-        
+       * src/SDCCast.c (decorateType): don't decorate/process parms twice,
+       (processParms): fixed bug #927659: don't copy parms, this will clear
+       decorated flag
+       * support/regression/tests/bug-927659.c: added
+
 2004-03-29 Bernhard Held <bernhard AT bernhardheld.de>
 
        * src/SDCCast.c (addCast): don't cast float to char
index a7cbd7c0185f937617641c4aa2f0dd827f584460..d32cace449739efcb32523d69973029ba01a5ca3 100644 (file)
@@ -770,17 +770,14 @@ processParms (ast *func,
        }
       
       if (newType)
-       {
-         /* cast required; change this op to a cast. */
-         ast *parmCopy = resolveSymbols (copyAst (*actParm));
-
-         (*actParm)->type = EX_OP;
-         (*actParm)->opval.op = CAST;
-         (*actParm)->left = newType;
-         (*actParm)->right = parmCopy;
-         (*actParm)->decorated = 0; /* force typechecking */
-         decorateType (*actParm, RESULT_TYPE_NONE);
-       }
+        {
+          /* cast required; change this op to a cast. */
+          (*actParm)->decorated = 0;
+           *actParm = newNode (CAST, newType, *actParm);
+          (*actParm)->lineno = (*actParm)->right->lineno;
+          
+          decorateType (*actParm, RESULT_TYPE_NONE);
+        }
       return 0;
     } /* vararg */
 
@@ -4121,29 +4118,34 @@ decorateType (ast * tree, RESULT_TYPE resultType)
          goto errorTreeReturn;
        }
 
-      {
-       sym_link *functype;      
-       parmNumber = 1;
+      /* if there are parms, make sure that
+         parms are decorate / process / reverse only once */
+      if (!tree->right ||
+          !tree->right->decorated)
+        {
+          sym_link *functype;      
+          parmNumber = 1;
 
-       if (IS_CODEPTR(LTYPE(tree)))
-         functype = LTYPE (tree)->next;
-       else
-         functype = LTYPE (tree);
+          if (IS_CODEPTR(LTYPE(tree)))
+            functype = LTYPE (tree)->next;
+          else
+            functype = LTYPE (tree);
 
-       if (processParms (tree->left, FUNC_ARGS(functype),
-                         &tree->right, &parmNumber, TRUE)) {
-         goto errorTreeReturn;
-        }
-
-       if ((options.stackAuto || IFFUNC_ISREENT (functype)) && 
-           !IFFUNC_ISBUILTIN(functype))
-         {
-           reverseParms (tree->right);
-         }
+          if (processParms (tree->left, FUNC_ARGS(functype),
+                            &tree->right, &parmNumber, TRUE))
+            {
+              goto errorTreeReturn;
+            }
+        
+          if ((options.stackAuto || IFFUNC_ISREENT (functype)) && 
+             !IFFUNC_ISBUILTIN(functype))
+            {
+              reverseParms (tree->right);
+            }
 
-       TTYPE (tree) = functype->next;
-       TETYPE (tree) = getSpec (TTYPE (tree));
-      }
+           TTYPE (tree) = functype->next;
+           TETYPE (tree) = getSpec (TTYPE (tree));
+        }
       return tree;
 
       /*------------------------------------------------------------------*/
diff --git a/support/regression/tests/bug-927659.c b/support/regression/tests/bug-927659.c
new file mode 100644 (file)
index 0000000..dde1e77
--- /dev/null
@@ -0,0 +1,59 @@
+/* bug-927659.c
+
+   double processing resp. reversing of params
+*/
+
+#include <testfwk.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+unsigned char
+foo(unsigned char a, ...) REENTRANT
+{
+  va_list argptr;
+  unsigned char b;
+
+  va_start (argptr, a);
+  b = va_arg (argptr, int);
+  va_end (argptr);
+  
+  return b;
+}
+
+unsigned char
+bar(unsigned char a, unsigned char b) REENTRANT
+{
+  return b / a;
+}
+
+void
+testReverse(void)
+{
+  ASSERT(foo (0, bar (1, 2)) == 2);
+}
+
+/*************************************************************/
+
+#ifndef PORT_HOST
+void putchar (char c)
+{
+  c;
+}
+#endif
+
+void
+testAddFunc(void)
+{
+#ifndef SDCC_z80
+  char buf[5];
+  unsigned char count = 0;
+
+  count += sprintf (buf, "%d", 5);
+  ASSERT(count == 1 &&
+         buf[0] == '5' &&
+         buf[1] == '\0');
+#else
+  ASSERT(1);
+#endif
+}
+//#endif