From: tecodev Date: Sun, 5 Oct 2008 23:07:36 +0000 (+0000) Subject: * device/include/pic16/stdio.h, X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=503506adabdfdde204ab0fc7daeed9f9105ca460;p=fw%2Fsdcc * 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 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5249 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 7e0b8201..d3362dcc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2008-10-06 Raphael Neider + + * 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 * 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 diff --git a/device/include/pic16/stdio.h b/device/include/pic16/stdio.h index 3c81810a..bec27f3f 100644 --- a/device/include/pic16/stdio.h +++ b/device/include/pic16/stdio.h @@ -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 */ diff --git a/device/lib/pic16/libc/stdio/putchar.c b/device/lib/pic16/libc/stdio/putchar.c index 19de6b98..1ce624dc 100644 --- a/device/lib/pic16/libc/stdio/putchar.c +++ b/device/lib/pic16/libc/stdio/putchar.c @@ -33,10 +33,7 @@ * 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; } diff --git a/device/lib/pic16/libc/stdio/strmgpsim.c b/device/lib/pic16/libc/stdio/strmgpsim.c index 300cffd3..57306296 100644 --- a/device/lib/pic16/libc/stdio/strmgpsim.c +++ b/device/lib/pic16/libc/stdio/strmgpsim.c @@ -37,7 +37,7 @@ extern WREG; void __stream_gpsim_putchar (char c) __wparam __naked { - c; + (void)c; __asm MOVFF _WREG, 0xf7f RETURN diff --git a/device/lib/pic16/libc/stdio/strmmssp.c b/device/lib/pic16/libc/stdio/strmmssp.c index bc0e7fcb..3b0702dc 100644 --- a/device/lib/pic16/libc/stdio/strmmssp.c +++ b/device/lib/pic16/libc/stdio/strmmssp.c @@ -36,7 +36,7 @@ extern SSPBUF; void __stream_mssp_putchar (char c) __wparam __naked { - c; + (void)c; __asm MOVWF _SSPBUF RETURN diff --git a/device/lib/pic16/libc/stdio/strmusart.c b/device/lib/pic16/libc/stdio/strmusart.c index 141b1c27..60a7e462 100644 --- a/device/lib/pic16/libc/stdio/strmusart.c +++ b/device/lib/pic16/libc/stdio/strmusart.c @@ -39,7 +39,7 @@ extern TXSTA; void __stream_usart_putchar (char c) __wparam __naked { - c; + (void)c; __asm @1: BTFSS _TXSTA, 1 diff --git a/src/pic16/pcode.c b/src/pic16/pcode.c index e174f554..4318e1af 100644 --- a/src/pic16/pcode.c +++ b/src/pic16/pcode.c @@ -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);