diff --git a/configure.ac b/configure.ac index f2a6a6f3..347c34cf 100644 --- a/configure.ac +++ b/configure.ac @@ -267,6 +267,17 @@ AS_IF([test $ok != yes], [ok=yes; AC_DEFINE([HAVE_POPCNT], [1], [Define to 1 if you have __popcnt function.])]) AC_MSG_RESULT($ok)]) +AC_MSG_CHECKING([__attribute__((noreturn))]) +AC_LINK_IFELSE( + [AC_LANG_PROGRAM([extern void fatal() __attribute__((noreturn));], [return 0;])], + [ + AC_DEFINE(NORETURN, [__attribute__((noreturn))], [The "noreturn" function attribute.]) + AC_MSG_RESULT([yes]) + ], + [ + AC_DEFINE(NORETURN, [], [The "noreturn" function attribute.]) + AC_MSG_RESULT([no]) + ]) # Check for inline AC_C_INLINE diff --git a/sources/declare.h b/sources/declare.h index 951def5f..47e8a016 100644 --- a/sources/declare.h +++ b/sources/declare.h @@ -410,7 +410,7 @@ static inline ULONG LongAbs(LONG x) */ static inline int UnsignedToInt(unsigned int x) { - extern void TerminateImpl(int, const char*, int, const char*); + extern void TerminateImpl(int, const char*, int, const char*) NORETURN; if ( x <= INT_MAX ) return(x); if ( x >= (unsigned int)INT_MIN ) return((int)(x - (unsigned int)INT_MIN) + INT_MIN); @@ -420,7 +420,7 @@ static inline int UnsignedToInt(unsigned int x) static inline WORD UWordToWord(UWORD x) { - extern void TerminateImpl(int, const char*, int, const char*); + extern void TerminateImpl(int, const char*, int, const char*) NORETURN; if ( x <= WORD_MAX_VALUE ) return(x); if ( x >= (UWORD)WORD_MIN_VALUE ) return((WORD)(x - (UWORD)WORD_MIN_VALUE) + WORD_MIN_VALUE); @@ -430,7 +430,7 @@ static inline WORD UWordToWord(UWORD x) static inline LONG ULongToLong(ULONG x) { - extern void TerminateImpl(int, const char*, int, const char*); + extern void TerminateImpl(int, const char*, int, const char*) NORETURN; if ( x <= LONG_MAX_VALUE ) return(x); if ( x >= (ULONG)LONG_MIN_VALUE ) return((LONG)(x - (ULONG)LONG_MIN_VALUE) + LONG_MIN_VALUE); @@ -791,7 +791,7 @@ extern void PositionStream(STREAM *,LONG); extern int ReverseStatements(STREAM *); extern int ProcessOption(UBYTE *,UBYTE *,int); extern int DoSetups(void); -extern void TerminateImpl(int, const char *,int, const char *); +extern void TerminateImpl(int, const char *,int, const char *) NORETURN; extern NAMENODE *GetNode(NAMETREE *,UBYTE *); extern int AddName(NAMETREE *,UBYTE *,WORD,WORD,int *); extern int GetName(NAMETREE *,UBYTE *,WORD *,int); @@ -990,7 +990,7 @@ extern int DoPolyratfun(UBYTE *); extern int CompileStatement(UBYTE *); extern UBYTE *ToToken(UBYTE *); extern int GetDollar(UBYTE *); -extern int MesWork(void); +extern void MesWork(void) NORETURN; extern int MesPrint(const char *,...); extern int MesCall(char *); extern UBYTE *NumCopy(WORD,UBYTE *); diff --git a/sources/execute.c b/sources/execute.c index 80ff8429..3fd8fd78 100644 --- a/sources/execute.c +++ b/sources/execute.c @@ -1118,7 +1118,9 @@ WORD PutBracket(PHEAD WORD *termin) WORD *bbb = 0, *bind, *binst = 0, bwild = 0, *bss = 0, *bns = 0, bset = 0; term1 = AT.WorkPointer+1; term2 = (WORD *)(((UBYTE *)(term1)) + AM.MaxTer); - if ( ( (WORD *)(((UBYTE *)(term2)) + AM.MaxTer) ) > AT.WorkTop ) return(MesWork()); + if ( ( (WORD *)(((UBYTE *)(term2)) + AM.MaxTer) ) > AT.WorkTop ) { + MesWork(); + } if ( AR.BracketOn < 0 ) { t2 = term1; t1 = term2; /* AntiBracket */ } diff --git a/sources/message.c b/sources/message.c index 788296ba..6c7a512a 100644 --- a/sources/message.c +++ b/sources/message.c @@ -53,7 +53,7 @@ static char hex[] = {'0','1','2','3','4','5','6','7','8','9', #[ Error0 : */ -void Error0(char *s) +NORETURN void Error0(char *s) { MesPrint("=== %s",s); Terminate(-1); @@ -64,7 +64,7 @@ void Error0(char *s) #[ Error1 : */ -void Error1(char *s, UBYTE *t) +NORETURN void Error1(char *s, UBYTE *t) { MesPrint("@%s %s",s,t); Terminate(-1); @@ -75,7 +75,7 @@ void Error1(char *s, UBYTE *t) #[ Error2 : */ -void Error2(char *s1, char *s2, UBYTE *t) +NORETURN void Error2(char *s1, char *s2, UBYTE *t) { MesPrint("@%s%s %s",s1,s2,t); Terminate(-1); @@ -86,12 +86,11 @@ void Error2(char *s1, char *s2, UBYTE *t) #[ MesWork : */ -int MesWork(void) +NORETURN void MesWork(void) { MesPrint("=== Workspace overflow. %l bytes is not enough.",AM.WorkSize); MesPrint("=== Change parameter WorkSpace in %s",setupfilename); Terminate(-1); - return(-1); } /* diff --git a/sources/parallel.c b/sources/parallel.c index 745dcf04..488c1c92 100644 --- a/sources/parallel.c +++ b/sources/parallel.c @@ -1558,7 +1558,9 @@ int PF_Processor(EXPRESSIONS e, WORD i, WORD LastExpression) } #endif - if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer ) ) > AT.WorkTop ) return(MesWork()); + if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer ) ) > AT.WorkTop ) { + MesWork(); + } /* For redefine statements. */ if ( AC.numpfirstnum > 0 ) { diff --git a/sources/proces.c b/sources/proces.c index e290de9d..c5061062 100644 --- a/sources/proces.c +++ b/sources/proces.c @@ -99,7 +99,9 @@ WORD Processor(void) AR.CompressPointer = AR.CompressBuffer; AR.NoCompress = AC.NoCompress; term = AT.WorkPointer; - if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer) ) > AT.WorkTop ) return(MesWork()); + if ( ( (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer) ) > AT.WorkTop ) { + MesWork(); + } UpdatePositions(); C->rhs[C->numrhs+1] = C->Pointer; AR.KeptInHold = 0; diff --git a/sources/reshuf.c b/sources/reshuf.c index bae74c8f..3c1743d8 100644 --- a/sources/reshuf.c +++ b/sources/reshuf.c @@ -1875,7 +1875,7 @@ WORD DoPartitions(PHEAD WORD *term, WORD level) t2 = twhere+twhere[1]; to = termout = AT.WorkPointer; if ( termout + *term + part.numpart*FUNHEAD + AM.MaxTal >= AT.WorkTop ) { - return(MesWork()); + MesWork(); } for ( i = 0; i < ncoeffnum; i++ ) coeff[i] = coeffnum[i]; ncoeff = ncoeffnum; diff --git a/sources/sort.c b/sources/sort.c index b54bed72..67a8b5e3 100644 --- a/sources/sort.c +++ b/sources/sort.c @@ -1540,7 +1540,7 @@ WORD PutOut(PHEAD WORD *term, POSITION *position, FILEHANDLE *fi, WORD ncomp) MLOCK(ErrorMessageLock); MesPrint("Ran into precompressed term"); MUNLOCK(ErrorMessageLock); - Crash(); + Terminate(-1); return(-1); } } @@ -1617,7 +1617,7 @@ WORD PutOut(PHEAD WORD *term, POSITION *position, FILEHANDLE *fi, WORD ncomp) MLOCK(ErrorMessageLock); MesPrint("CompressSize of %10l is insufficient",AM.CompressSize); MUNLOCK(ErrorMessageLock); - Crash(); + Terminate(-1); return(-1); } }