Cygwin: Add 'fallthrough' pseudo keyword for switch/case use

This patch has been inspired by the Linux kernel patch

  294f69e662d1 compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use

written by Joe Perches <joe AT perches DOT com> based on an idea from
Dan Carpenter <dan DOT carpenter AT oracle DOT com>.  The following text
is from the original log message:

Reserve the pseudo keyword 'fallthrough' for the ability to convert the
various case block /* fallthrough */ style comments to appear to be an
actual reserved word with the same gcc case block missing fallthrough
warning capability.

All switch/case blocks now should end in one of:

	break;
	fallthrough;
	goto <label>;
	return [expression];
	continue;

In C mode, GCC supports the __fallthrough__ attribute since 7.1,
the same time the warning and the comment parsing were introduced.

Cygwin-only: add an explicit -Wimplicit-fallthrough=5 to the build
flags.
This commit is contained in:
Corinna Vinschen 2020-08-05 21:58:22 +02:00 committed by Ken Brown
parent 758e0d2f5f
commit b6cedcd9a4
33 changed files with 67 additions and 63 deletions

View File

@ -73,7 +73,7 @@ CRT0:=$(cygwin_build)/crt0.o
#
MT_SAFE:=@MT_SAFE@
CCEXTRA=
COMMON_CFLAGS=-MMD ${$(*F)_CFLAGS} -Werror -fmerge-constants -ftracer $(CCEXTRA)
COMMON_CFLAGS=-MMD ${$(*F)_CFLAGS} -Wimplicit-fallthrough=5 -Werror -fmerge-constants -ftracer $(CCEXTRA)
ifeq ($(target_cpu),x86_64)
COMMON_CFLAGS+=-mcmodel=small
endif

View File

@ -698,7 +698,7 @@ aio_read (struct aiocb *aio)
if (slot >= 0)
debug_printf ("slot %d released", slot);
}
/* fall through */
fallthrough;
case ENOBUFS:
aio->aio_errno = EINPROGRESS;
@ -888,7 +888,7 @@ aio_write (struct aiocb *aio)
if (slot >= 0)
debug_printf ("slot %d released", slot);
}
/* fall through */
fallthrough;
case ENOBUFS:
aio->aio_errno = EINPROGRESS;

View File

@ -551,7 +551,7 @@ get_cygwin_startup_info ()
case _CH_FORK:
in_forkee = true;
should_be_cb = sizeof (child_info_fork);
/* fall through */;
fallthrough;
case _CH_SPAWN:
case _CH_EXEC:
if (!should_be_cb)
@ -570,7 +570,7 @@ get_cygwin_startup_info ()
break;
default:
system_printf ("unknown exec type %u", res->type);
/* intentionally fall through */
fallthrough;
case _CH_WHOOPS:
res = NULL;
break;

View File

@ -741,7 +741,7 @@ exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in,
Linux behaviour and also makes a lot of sense on Windows. */
if (me.altstack.ss_flags)
global_sigs[SIGSEGV].sa_handler = SIG_DFL;
/*FALLTHRU*/
fallthrough;
case STATUS_ARRAY_BOUNDS_EXCEEDED:
case STATUS_IN_PAGE_ERROR:
case STATUS_NO_MEMORY:

View File

@ -255,7 +255,7 @@ retry:
break;
}
}
/*FALLTHRU*/
fallthrough;
case STATUS_INVALID_DEVICE_REQUEST:
case STATUS_INVALID_PARAMETER:
case STATUS_INVALID_HANDLE:
@ -265,6 +265,7 @@ retry:
len = (size_t) -1;
break;
}
fallthrough;
default:
__seterrno_from_nt_status (status);
len = (size_t) -1;

View File

@ -1067,7 +1067,7 @@ fhandler_dev_dsp::open (int flags, mode_t)
case O_RDWR:
if ((num_in = waveInGetNumDevs ()) == 0)
err = ENXIO;
/* Fall through */
fallthrough;
case O_WRONLY:
if ((num_out = waveOutGetNumDevs ()) == 0)
err = ENXIO;

View File

@ -103,7 +103,7 @@ fhandler_serial::raw_read (void *ptr, size_t& ulen)
default: /* Handle an error case from cygwait basically like
a cancel condition and see if we got "something" */
CancelIo (get_handle ());
/*FALLTHRU*/
fallthrough;
case WAIT_OBJECT_0:
if (!GetOverlappedResult (get_handle (), &ov, &read_bytes,
TRUE))

View File

@ -140,7 +140,7 @@ fhandler_socket::ioctl (unsigned int cmd, void *p)
case OLD_SIOCGIFMTU:
case OLD_SIOCGIFINDEX:
cmd = CONV_OLD_TO_NEW_SIO (cmd);
/*FALLTHRU*/
fallthrough;
case SIOCGIFFLAGS:
case SIOCGIFBRDADDR:
case SIOCGIFNETMASK:

View File

@ -92,7 +92,7 @@ fhandler_termios::tcsetpgrp (const pid_t pgid)
if (_my_tls.call_signal_handler ())
continue;
set_errno (EINTR);
/* fall through intentionally */
fallthrough;
default:
res = -1;
break;

View File

@ -1550,7 +1550,7 @@ fhandler_pty_slave::write (const void *ptr, size_t len)
{
case ERROR_NO_DATA:
err = ERROR_IO_DEVICE;
/*FALLTHRU*/
fallthrough;
default:
__seterrno_from_win_error (err);
}
@ -2163,7 +2163,7 @@ fhandler_pty_slave::facl (int cmd, int nentries, aclent_t *aclbufp)
set_errno (EFAULT);
break;
}
/*FALLTHRU*/
fallthrough;
case GETACLCNT:
if (!input_available_event)
{

View File

@ -112,7 +112,7 @@ fhandler_windows::read (void *buf, size_t& len)
pthread::static_cancel_self ();
break;
}
/*FALLTHRU*/
fallthrough;
case WAIT_OBJECT_0 + 2:
if (!PeekMessageW (ptr, hWnd_, 0, 0, PM_REMOVE))
{

View File

@ -347,7 +347,7 @@ globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv, size_t *l
i--;
break;
}
/* FALLTHROUGH */
fallthrough;
case COMMA:
if (i && *pm == COMMA)
break;

View File

@ -404,7 +404,7 @@ gr_ent::enumerate_caches ()
}
cnt = 0;
max = 1;
/*FALLTHRU*/
fallthrough;
case 1:
if (from_files)
{
@ -415,7 +415,7 @@ gr_ent::enumerate_caches ()
}
cnt = 0;
max = 2;
/*FALLTHRU*/
fallthrough;
case 2:
if (from_db)
{

View File

@ -282,7 +282,7 @@ b64_pton(char const *src, unsigned char *target, size_t targsize)
return (-1);
ch = *src++; /* Skip the = */
/* Fall through to "single trailing =" case. */
/* FALLTHROUGH */
fallthrough;
case 3: /* Valid, means two bytes of info */
/*

View File

@ -193,7 +193,7 @@ fnmatch1(const char *pattern, const char *string, const char *stringstart,
return (FNM_NOMATCH);
pattern += pclen;
}
/* FALLTHROUGH */
fallthrough;
default:
norm:
string += sclen;

View File

@ -88,7 +88,7 @@ ftw(const char *path, int (*fn)(const char *, const struct stat *, int),
break;
case FTS_DC:
errno = ELOOP;
/* FALLTHROUGH */
fallthrough;
default:
error = -1;
goto done;

View File

@ -81,6 +81,7 @@ static pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
#else
#include "../locale/setlocale.h"
#include "winsup.h"
#define SIZE_T_MAX __SIZE_MAX__
#define _close close
#define _open open
@ -233,7 +234,7 @@ catopen(const char *name, int type)
break;
case '%':
++nlspath;
/* FALLTHROUGH */
fallthrough;
default:
if (pathP - path >=
sizeof(path) - 1)

View File

@ -105,7 +105,7 @@ nftw(const char *path, int (*fn)(const char *, const struct stat *, int,
break;
case FTS_DC:
errno = ELOOP;
/* FALLTHROUGH */
fallthrough;
default:
error = -1;
goto done;

View File

@ -179,7 +179,7 @@ next:
case DEFAULT:
usedefault = 1;
/* FALL THROUGH */
fallthrough;
case MACH:
if (!usedefault) {

View File

@ -524,7 +524,7 @@ literal:
case 'k': /* The hour (24-hour clock representation). */
LEGAL_ALT(0);
/* FALLTHROUGH */
fallthrough;
case 'H':
LEGAL_ALT(ALT_O);
bp = conv_num(bp, &tm->tm_hour, 0, 23, ALT_DIGITS);
@ -532,7 +532,7 @@ literal:
case 'l': /* The hour (12-hour clock representation). */
LEGAL_ALT(0);
/* FALLTHROUGH */
fallthrough;
case 'I':
LEGAL_ALT(ALT_O);
bp = conv_num(bp, &tm->tm_hour, 1, 12, ALT_DIGITS);

View File

@ -381,27 +381,27 @@ pg_ent::getent (void)
{
case rewound:
state = from_cache;
/*FALLTHRU*/
fallthrough;
case from_cache:
if (nss_db_enum_caches ()
&& (entry = enumerate_caches ()))
return entry;
state = from_file;
/*FALLTHRU*/
fallthrough;
case from_file:
if (from_files
&& nss_db_enum_files ()
&& (entry = enumerate_file ()))
return entry;
state = from_builtin;
/*FALLTHRU*/
fallthrough;
case from_builtin:
if (from_db
&& nss_db_enum_builtin ()
&& (entry = enumerate_builtin ()))
return entry;
state = from_local;
/*FALLTHRU*/
fallthrough;
case from_local:
if (from_db
&& nss_db_enum_local ()
@ -410,7 +410,7 @@ pg_ent::getent (void)
&& (entry = enumerate_local ()))
return entry;
state = from_sam;
/*FALLTHRU*/
fallthrough;
case from_sam:
if (from_db
&& nss_db_enum_local ()
@ -422,14 +422,14 @@ pg_ent::getent (void)
&& (entry = enumerate_sam ()))
return entry;
state = from_ad;
/*FALLTHRU*/
fallthrough;
case from_ad:
if (cygheap->dom.member_machine ()
&& from_db
&& (entry = enumerate_ad ()))
return entry;
state = finished;
/*FALLTHRU*/
fallthrough;
case finished:
break;
}
@ -673,7 +673,7 @@ pw_ent::enumerate_caches ()
}
cnt = 0;
max = 1;
/*FALLTHRU*/
fallthrough;
case 1:
if (from_files)
{
@ -684,7 +684,7 @@ pw_ent::enumerate_caches ()
}
cnt = 0;
max = 2;
/*FALLTHRU*/
fallthrough;
default:
if (from_db)
{

View File

@ -829,7 +829,7 @@ path_conv::check (const char *src, unsigned opt,
opt &= ~PC_SYM_FOLLOW;
sym.path_flags |= PATH_RESOLVE_PROCFD;
}
/*FALLTHRU*/
fallthrough;
case virt_symlink:
goto is_virtual_symlink;
case virt_pipe:
@ -866,7 +866,7 @@ path_conv::check (const char *src, unsigned opt,
| FILE_ATTRIBUTE_DEVICE;
goto out;
}
/*FALLTHRU*/
fallthrough;
case virt_chr:
if (component == 0)
fileattr = FILE_ATTRIBUTE_DEVICE;
@ -2021,7 +2021,7 @@ symlink_worker (const char *oldpath, path_conv &win32_newpath, bool isdevice)
}
/* Otherwise, fall back to default symlink type. */
wsym_type = WSYM_sysfile;
/*FALLTHRU*/
fallthrough;
case WSYM_sysfile:
if (win32_newpath.fs_flags () & FILE_SUPPORTS_REPARSE_POINTS)
{

View File

@ -221,7 +221,7 @@ restart1:
case WAIT_OBJECT_0 + 2:
if (timer_idx != 2)
pthread::static_cancel_self ();
/*FALLTHRU*/
fallthrough;
case WAIT_OBJECT_0 + 3:
ret = ETIMEDOUT;
break;
@ -249,7 +249,7 @@ restart1:
case WAIT_OBJECT_0 + 2:
if (timer_idx != 2)
pthread_testcancel ();
/*FALLTHRU*/
fallthrough;
case WAIT_OBJECT_0 + 3:
ret = ETIMEDOUT;
break;

View File

@ -58,7 +58,7 @@ quotactl (int cmd, const char *special, int id, caddr_t addr)
set_errno (EINVAL);
return -1;
}
/*FALLTHRU*/
fallthrough;
case Q_QUOTAOFF:
case Q_SETINFO:
access |= FILE_WRITE_DATA;
@ -68,7 +68,7 @@ quotactl (int cmd, const char *special, int id, caddr_t addr)
break;
case Q_SETQUOTA:
access |= FILE_WRITE_DATA;
/*FALLTHRU*/
fallthrough;
case Q_GETQUOTA:
/* Windows feature: Default limits. Get or set them with id == -1. */
if (id != -1)

View File

@ -445,7 +445,7 @@ p_ere_exp(struct parse *p)
break;
case '{': /* okay as ordinary except if digit follows */
(void)REQUIRE(!MORE() || !isdigit((uch)PEEK()), REG_BADRPT);
/* FALLTHROUGH */
fallthrough;
default:
p->next--;
wc = WGETNEXT();
@ -656,7 +656,7 @@ p_simp_re(struct parse *p,
break;
case '*':
(void)REQUIRE(starordinary, REG_BADRPT);
/* FALLTHROUGH */
fallthrough;
default:
p->next--;
wc = WGETNEXT();
@ -1545,7 +1545,7 @@ findmust(struct parse *p, struct re_guts *g)
return;
}
} while (OP(s) != O_QUEST && OP(s) != O_CH);
/* FALLTHROUGH */
fallthrough;
case OBOW: /* things that break a sequence */
case OEOW:
case OBOL:

View File

@ -1427,7 +1427,7 @@ __aclcalcmask (aclent_t *aclbufp, int nentries)
case USER:
case GROUP:
need_mask = true;
/*FALLTHRU*/
fallthrough;
case GROUP_OBJ:
mask |= aclbufp[idx].a_perm;
break;

View File

@ -453,7 +453,7 @@ acl_set_tag_type (acl_entry_t entry_d, acl_tag_t tag_type)
case ACL_MASK:
case ACL_OTHER:
acl->entry[idx].a_id = ACL_UNDEFINED_ID;
/*FALLTHRU*/
fallthrough;
case ACL_USER:
case ACL_GROUP:
acl->entry[idx].a_type = tag_type;

View File

@ -469,7 +469,7 @@ was_timeout:
pthread::static_cancel_self ();
/*NOTREACHED*/
}
/*FALLTHRU*/
fallthrough;
default:
/* Timer event? */
if (wait_ret == timer_idx)
@ -1679,7 +1679,7 @@ thread_socket (void *arg)
case WAIT_OBJECT_0:
if (!i) /* Socket event set. */
goto out;
/*FALLTHRU*/
fallthrough;
default:
break;
}

View File

@ -205,7 +205,7 @@ proc_subproc (DWORD what, uintptr_t val)
set_errno (EAGAIN);
break;
}
/* fall through intentionally */
fallthrough;
case PROC_DETACHED_CHILD:
if (vchild != myself)
@ -1078,7 +1078,7 @@ child_info::proc_retry (HANDLE h)
case STATUS_CONTROL_C_EXIT:
if (saw_ctrl_c ())
return EXITCODE_OK;
/* fall through intentionally */
fallthrough;
case STATUS_DLL_INIT_FAILED:
case STATUS_DLL_INIT_FAILED_LOGOFF:
case EXITCODE_RETRY:
@ -1387,10 +1387,10 @@ wait_sig (VOID *)
sig_clear (-pack.si.si_signo);
else
sigq.add (pack);
/*FALLTHRU*/
fallthrough;
case __SIGNOHOLD:
sig_held = false;
/*FALLTHRU*/
fallthrough;
case __SIGFLUSH:
case __SIGFLUSHFAST:
if (!sig_held)

View File

@ -180,7 +180,7 @@ __small_vsprintf (char *dst, const char *fmt, va_list ap)
pad = '0';
continue;
}
/*FALLTHRU*/
fallthrough;
case '1' ... '9':
len = len * 10 + (c - '0');
continue;
@ -254,7 +254,7 @@ __small_vsprintf (char *dst, const char *fmt, va_list ap)
case 'y':
*dst++ = '0';
*dst++ = 'x';
/*FALLTHRU*/
fallthrough;
case 'x':
base = 16;
addsign = 0;
@ -279,7 +279,7 @@ gen_decimal:
case 'Y':
*dst++ = '0';
*dst++ = 'x';
/*FALLTHRU*/
fallthrough;
case 'X':
base = 16;
addsign = 0;
@ -299,7 +299,7 @@ gen_decimalLL:
n = strtol (fmt, (char **) &fmt, 10);
if (*fmt++ != 's')
goto endfor;
/*FALLTHRU*/
fallthrough;
case 's':
s = va_arg (ap, char *);
if (s == NULL)
@ -540,7 +540,7 @@ __small_vswprintf (PWCHAR dst, const WCHAR *fmt, va_list ap)
pad = L'0';
continue;
}
/*FALLTHRU*/
fallthrough;
case L'1' ... L'9':
len = len * 10 + (c - L'0');
continue;
@ -597,7 +597,7 @@ __small_vswprintf (PWCHAR dst, const WCHAR *fmt, va_list ap)
case 'y':
*dst++ = '0';
*dst++ = 'x';
/*FALLTHRU*/
fallthrough;
case 'x':
base = 16;
addsign = 0;
@ -622,7 +622,7 @@ gen_decimal:
case 'Y':
*dst++ = '0';
*dst++ = 'x';
/*FALLTHRU*/
fallthrough;
case 'X':
base = 16;
addsign = 0;
@ -645,7 +645,7 @@ gen_decimalLL:
n = wcstoul (fmt, (wchar_t **) &fmt, 10);
if (*fmt++ != L's')
goto endfor;
/*FALLTHRU*/
fallthrough;
case L's':
s = va_arg (ap, char *);
if (s == NULL)

View File

@ -147,7 +147,7 @@ tcsetattr (int fd, int a, const struct termios *t)
if (_my_tls.call_signal_handler ())
continue;
res = -1;
/* fall through intentionally */
fallthrough;
default:
e = get_errno ();
break;

View File

@ -1743,7 +1743,7 @@ pwdgrp::fetch_account_from_file (fetch_user_arg_t &arg)
/* Override SID with SID string. */
arg.sid->string (str);
arg.name = str;
/*FALLTHRU*/
fallthrough;
case NAME_arg:
arg.len = strlen (arg.name);
break;
@ -2300,7 +2300,7 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
if (!its_ok)
return NULL;
}
/*FALLTHRU*/
fallthrough;
case SidTypeGroup:
case SidTypeAlias:
/* Predefined alias? */

View File

@ -20,6 +20,8 @@ details. */
#define EXPORT_ALIAS(sym,symalias) __typeof (sym) symalias __attribute__ ((alias(#sym)));
#endif
#define fallthrough __attribute__((__fallthrough__))
#define _WIN32_WINNT 0x0a00
#define WINVER 0x0a00