mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Introduce usage of __builtin_unreachable() and noreturn (#248)
This commit adds an UNREACHABLE() macro that expands to either the __builtin_unreachable() compiler builtin (for release builds) or abort(3) (for development builds). This is used to mark code paths that are never to be reached. It also adds the 'noreturn' attribute to functions that never return: path_exec(), sh_done() and sh_syntax(). The UNREACHABLE() macro is not added after calling these. The purpose of these is: * to slightly improve GCC/Clang compiler optimizations; * to fix a few compiler warnings; * to add code clarity. Changes of note: src/cmd/ksh93/sh/io.c: outexcept(): - Avoid using __builtin_unreachable() here since errormsg can return despite using ERROR_system(1), as shp->jmplist->mode is temporarily set to 0. See: https://github.com/att/ast/issues/1336 src/cmd/ksh93/tests/io.sh: - Add a regression test for the ksh2020 bug referenced above. src/lib/libast/features/common: - Detect the existence of either the C11 stdnoreturn.h header or the GCC noreturn attribute, preferring the former when available. - Test for the existence of __builtin_unreachable(). Use it for release builds. On development builds, use abort() instead, which crahses reliably for debugging when unreachable code is reached. Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
parent
56913f8c2a
commit
c4f980eb29
87 changed files with 1170 additions and 122 deletions
|
|
@ -221,11 +221,11 @@ static int rand_shift;
|
|||
/*
|
||||
* out of memory routine for stak routines
|
||||
*/
|
||||
static char *nomemory(int unused)
|
||||
static noreturn char *nomemory(int unused)
|
||||
{
|
||||
NOT_USED(unused);
|
||||
errormsg(SH_DICT, ERROR_SYSTEM|ERROR_PANIC, "out of memory");
|
||||
return(NIL(char*));
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -371,7 +371,10 @@ static void put_restricted(register Namval_t* np,const char *val,int flags,Namfu
|
|||
Pathcomp_t *pp;
|
||||
char *name = nv_name(np);
|
||||
if(!(flags&NV_RDONLY) && sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(np==PATHNOD || (path_scoped=(strcmp(name,PATHNOD->nvname)==0)))
|
||||
{
|
||||
/* Clear the hash table */
|
||||
|
|
@ -1195,7 +1198,10 @@ static void put_mode(Namval_t* np, const char* val, int flag, Namfun_t* nfp)
|
|||
else
|
||||
mode = strperm(val, &last,0);
|
||||
if(*last)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),"%s: invalid mode string",val);
|
||||
UNREACHABLE();
|
||||
}
|
||||
nv_putv(np,(char*)&mode,NV_INTEGER,nfp);
|
||||
}
|
||||
else
|
||||
|
|
@ -1472,7 +1478,10 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit)
|
|||
#ifdef SHELLMAGIC
|
||||
/* careful of #! setuid scripts with name beginning with - */
|
||||
if(shp->login_sh && argv[1] && strcmp(argv[0],argv[1])==0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_prohibited);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#endif /*SHELLMAGIC*/
|
||||
}
|
||||
else
|
||||
|
|
@ -1700,7 +1709,10 @@ found:
|
|||
shp->last_table = SH_STATS;
|
||||
}
|
||||
else
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_notelem,n,name,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(nq);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue