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
|
@ -645,14 +645,23 @@ static void set(char *argv[], struct termios *sp)
|
|||
off=1;
|
||||
}
|
||||
if(!(tp=lookup(cp)) || (off && (tp->type!=BIT) && (tp->type!=TABS)))
|
||||
{
|
||||
error(ERROR_exit(1),"%s: unknown mode",cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
switch(tp->type)
|
||||
{
|
||||
case CHAR:
|
||||
if(off)
|
||||
{
|
||||
error(ERROR_exit(1),"%s: unknown mode",cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!*argv)
|
||||
{
|
||||
error(ERROR_exit(1),"missing argument to %s",cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
c = gettchar(*argv++);
|
||||
if(c>=0)
|
||||
sp->c_cc[tp->mask] = c;
|
||||
|
@ -697,7 +706,10 @@ static void set(char *argv[], struct termios *sp)
|
|||
struct winsize win;
|
||||
int n;
|
||||
if(ioctl(0,TIOCGWINSZ,&win)<0)
|
||||
{
|
||||
error(ERROR_system(1),"cannot set %s",tp->name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!(cp= *argv))
|
||||
{
|
||||
sfprintf(sfstdout,"%d\n",tp->mask?win.ws_col:win.ws_row);
|
||||
|
@ -706,13 +718,19 @@ static void set(char *argv[], struct termios *sp)
|
|||
argv++;
|
||||
n=strtol(cp,&cp,10);
|
||||
if(*cp)
|
||||
{
|
||||
error(ERROR_system(1),"%d: invalid number of %s",argv[-1],tp->name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(tp->mask)
|
||||
win.ws_col = n;
|
||||
else
|
||||
win.ws_row = n;
|
||||
if(ioctl(0,TIOCSWINSZ,&win)<0)
|
||||
{
|
||||
error(ERROR_system(1),"cannot set %s",tp->name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
@ -727,11 +745,15 @@ static void set(char *argv[], struct termios *sp)
|
|||
break;
|
||||
}
|
||||
error(ERROR_exit(1), "%s: missing numeric argument", tp->name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv++;
|
||||
c = (int)strtol(cp, &ep, 10);
|
||||
if (*ep)
|
||||
{
|
||||
error(ERROR_exit(1), "%s: %s: numeric argument expected", tp->name, cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
switch (tp->field)
|
||||
{
|
||||
#if _mem_c_line_termios
|
||||
|
@ -748,7 +770,10 @@ static void set(char *argv[], struct termios *sp)
|
|||
cfsetospeed(sp, c);
|
||||
}
|
||||
else
|
||||
{
|
||||
error(ERROR_exit(1), "%s: %s: invalid speed", tp->name, cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
case T_CHAR:
|
||||
sp->c_cc[tp->mask] = c;
|
||||
|
@ -941,19 +966,28 @@ b_stty(int argc, char** argv, Shbltin_t* context)
|
|||
if (!opt_info.offset)
|
||||
error(2, "%s", opt_info.arg);
|
||||
else if (!(tp = lookup(argv[opt_info.index]+1)) || (tp->type != BIT && tp->type != TABS))
|
||||
{
|
||||
error(ERROR_exit(1), "%s: unknown mode", argv[opt_info.index]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
error(ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if (error_info.errors || (flags && *argv) || (flags&(flags-1)))
|
||||
{
|
||||
error(ERROR_usage(2), "%s", optusage(NiL));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if (tcgetattr(fd, &tty) < 0)
|
||||
{
|
||||
error(ERROR_system(1), "not a tty");
|
||||
UNREACHABLE();
|
||||
}
|
||||
if (flags & T_FLAG)
|
||||
sfprintf(sfstdout, "%d\n", tcgetpgrp(0));
|
||||
else if (*argv)
|
||||
|
@ -963,7 +997,10 @@ b_stty(int argc, char** argv, Shbltin_t* context)
|
|||
else
|
||||
set(argv, &tty);
|
||||
if (tcsetattr(0, TCSANOW, &tty) < 0)
|
||||
{
|
||||
error(ERROR_system(1), "cannot set tty");
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
else
|
||||
output(&tty, flags);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue