* device/include/pic16/stdio.h,
authortecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 5 Oct 2008 23:07:36 +0000 (23:07 +0000)
committertecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 5 Oct 2008 23:07:36 +0000 (23:07 +0000)
  device/lib/pic16/libc/stdio/putchar.c: putchar should not be
  declared __naked for convenience, named all arguments
* device/lib/pic16/libc/stdio/strmgpsim.c,
  device/lib/pic16/libc/stdio/strmmssp.c,
  device/lib/pic16/libc/stdio/strmusart.c: cosmetic changes

* src/pic16/pcode.c (createReachingDefinitions): avoid segfault on
  empty __naked functions,
* (pCodeLabelDestruct, pic16_unlinkpCode, pic16_pCodeUnlink): fix
  corner cases (unlink first/last pCode in list), reuse more code

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

ChangeLog
device/include/pic16/stdio.h
device/lib/pic16/libc/stdio/putchar.c
device/lib/pic16/libc/stdio/strmgpsim.c
device/lib/pic16/libc/stdio/strmmssp.c
device/lib/pic16/libc/stdio/strmusart.c
src/pic16/pcode.c

index 7e0b8201f0b5974ae57b57d999e97998e446e55d..d3362dcc5fa846d02a32bdbc1fd5d20f1cb51a9c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2008-10-06 Raphael Neider <rneider AT web.de>
+
+       * device/include/pic16/stdio.h,
+         device/lib/pic16/libc/stdio/putchar.c: putchar should not be
+         declared __naked for convenience, named all arguments
+       * device/lib/pic16/libc/stdio/strmgpsim.c,
+         device/lib/pic16/libc/stdio/strmmssp.c,
+         device/lib/pic16/libc/stdio/strmusart.c: cosmetic changes
+       
+       * src/pic16/pcode.c (createReachingDefinitions): avoid segfault on
+         empty __naked functions,
+       * (pCodeLabelDestruct, pic16_unlinkpCode, pic16_pCodeUnlink): fix
+         corner cases (unlink first/last pCode in list), reuse more code
+
 2008-10-05 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * src/ds390/main.c (_ds390_genInitStartup): added
@@ -13,7 +27,7 @@
 
        * src/pic16/glue.c:
          definition of absolute address symbols without initial value,
-         fixed SDCC cresh "do not know how to intialize symbol"
+         fixed SDCC crash "do not know how to intialize symbol"
 
 2008-09-16 Maarten Brock <sourceforge.brock AT dse.nl>
 
index 3c81810a028ed1075dd2b4e7ab1080fc2486ff6c..bec27f3f4a571f8362e96bb26d4c4fef1e80581a 100644 (file)
@@ -92,32 +92,32 @@ typedef char *FILE;
 #define GPSIM_DEREF     0xe
 #define STREAM_GPSIM    ((FILE *)(0x002e0000UL))
 
-extern FILE * stdin;
-extern FILE * stdout;
+extern FILE *stdin;
+extern FILE *stdout;
 
 /* printf_small() supports float print */
-void printf_small (const char *, ...);
+void printf_small (const char *fmt, ...);
 
 /* printf_tiny() does not support float print */
-void printf_tiny (const char *, ...);  // __reentrant;
+void printf_tiny (const char *fmt, ...);  // __reentrant;
 
-extern int printf (const char *,...);
-extern int fprintf (FILE *, const char *,...);
-extern int sprintf (char *, const char *, ...);
+extern int printf (const char *fmt, ...);
+extern int fprintf (FILE *stream, const char *fmt, ...);
+extern int sprintf (char *str, const char *fmt, ...);
 
-extern int vprintf (const char *, va_list);
-extern int vfprintf (FILE * stream, const char *fmt, va_list ap);
-extern int vsprintf (char *, const char *, va_list);
+extern int vprintf (const char *fmt, va_list ap);
+extern int vfprintf (FILE *stream, const char *fmt, va_list ap);
+extern int vsprintf (char *str, const char *fmt, va_list ap);
 
-extern void putchar (char) __wparam __naked;
+extern void putchar (char c) __wparam;
 
-extern void __stream_putchar (FILE *, char);
+extern void __stream_putchar (FILE *stream, char c);
 
 extern void __stream_usart_putchar (char c) __wparam __naked;
 extern void __stream_mssp_putchar (char c) __wparam __naked;
 extern void __stream_gpsim_putchar (char c) __wparam __naked;
 
-extern char *gets (char *);
+extern char *gets (char *str);
 extern char getchar (void);
 
 #endif /* __STDIO_H */
index 19de6b98e7cffa3e4c67ba108f233a608b392138..1ce624dc566c391503fd4fb6cfd3e88e4df59a33 100644 (file)
  * have the argument in WCHAR (via the wparam pragma) */
 
 void
-putchar (char c) __wparam __naked
+putchar (char c) __wparam
 {
-  c;
-  __asm
-    return
-  __endasm;
+  (void)c;
 }
index 300cffd3d9905a028954adc75d2e17856b14a505..57306296203708ca4eb859f1abcc95926dc6d366 100644 (file)
@@ -37,7 +37,7 @@ extern WREG;
 void
 __stream_gpsim_putchar (char c) __wparam __naked
 {
-  c;
+  (void)c;
   __asm
     MOVFF       _WREG, 0xf7f
     RETURN
index bc0e7fcbb5602ce46552388077879e7bf83cd936..3b0702dce283fbcc3902a443a52c9999cfe8c296 100644 (file)
@@ -36,7 +36,7 @@ extern SSPBUF;
 void
 __stream_mssp_putchar (char c) __wparam __naked
 {
-  c;
+  (void)c;
   __asm
     MOVWF       _SSPBUF
     RETURN
index 141b1c272175a25b610f214dd679cb7251dcce8c..60a7e462cf75c582301786c28af0fee77917da85 100644 (file)
@@ -39,7 +39,7 @@ extern TXSTA;
 void
 __stream_usart_putchar (char c) __wparam __naked
 {
-  c;
+  (void)c;
   __asm
 @1:
     BTFSS       _TXSTA, 1
index e174f5543ad0c428cf15df96aad2281290cc062d..4318e1af837491bfe5ff3e550e384cc754308806 100644 (file)
@@ -3804,6 +3804,8 @@ static void pCodeLabelDestruct(pCode *pc)
   if(!pc)
     return;
 
+  pic16_unlinkpCode(pc);
+
 //  if((pc->type == PC_LABEL) && PCL(pc)->label)
 //    Safe_free(PCL(pc)->label);
 
@@ -4661,10 +4663,16 @@ void pic16_unlinkpCode(pCode *pc)
     fprintf(stderr,"Unlinking: ");
     printpCode(stderr, pc);
 #endif
-    if(pc->prev)
+    if(pc->prev) {
       pc->prev->next = pc->next;
-    if(pc->next)
+    } else if (pc->pb && (pc->pb->pcHead == pc)) {
+        pc->pb->pcHead = pc->next;
+    }
+    if(pc->next) {
       pc->next->prev = pc->prev;
+    } else if (pc->pb && (pc->pb->pcTail == pc)) {
+        pc->pb->pcTail = pc->prev;
+    }
 
     /* move C source line down (or up) */
     if (isPCI(pc) && PCI(pc)->cline) {
@@ -5332,31 +5340,10 @@ void pic16_pCodeUnlink(pCode *pc)
   pBranch *pb1,*pb2;
   pCode *pc1;
 
-  if(!pc->prev || !pc->next) {
-    fprintf(stderr,"unlinking bad pCode in %s:%d\n",__FILE__,__LINE__);
-    exit(1);
-  }
-
-  /* move C source line down (or up) */
-  if (isPCI(pc) && PCI(pc)->cline) {
-    pc1 = pic16_findNextInstruction (pc->next);
-    if (pc1 && isPCI(pc1) && !PCI(pc1)->cline) {
-      PCI(pc1)->cline = PCI(pc)->cline;
-    } else {
-      pc1 = pic16_findPrevInstruction (pc->prev);
-      if (pc1 && isPCI(pc1) && !PCI(pc1)->cline)
-        PCI(pc1)->cline = PCI(pc)->cline;
-    }
+  if (!pc) {
+    return;
   }
 
-  /* first remove the pCode from the chain */
-  pc->prev->next = pc->next;
-  pc->next->prev = pc->prev;
-
-  pc->prev = pc->next = NULL;
-
-  /* Now for the hard part... */
-
   /* Remove the branches */
 
   pb1 = PCI(pc)->from;
@@ -5379,6 +5366,7 @@ void pic16_pCodeUnlink(pCode *pc)
     pb1 = pb1->next;
   }
 
+  pic16_unlinkpCode (pc);
 
 }
 #endif
@@ -11241,6 +11229,10 @@ static void createReachingDefinitions (pBlock *pb) {
   } // for
 
   pc = pic16_findNextInstruction (pb->pcHead);
+  if (!pc) {
+      // empty function, avoid NULL pointer dereference
+      return;
+  } // if
   todo = NULL; blacklist = NULL;
   addSetHead (&todo, PCI(pc)->pcflow);