clang-10: use AFS_FALLTHROUGH for case fallthrough

Clang-10 will not recognize '/* fallthrough */' as an indicator to
turn off the fallthrough diagnostic due to the lack of a 'break' in a
case statement.  Clang-10 requires the '__attribute__((fallthrough))'
statement to disable the diagnostic.

In addition clang-10 is finding additional locations where fall throughs
occur.

Determine if the compiler supports '__attribute__((fallthrough))' to
disable the implicit fallthrough diagnostic.

Define a new macro 'AFS_FALLTHROUGH' that will disable the fallthrough
diagnostic. Set it as a wrapper for the Linux kernel's 'fallthrough'
macro if available, otherwise set it as a wrapper macro for
'__attribute__((fallthrough))' if the compiler supports it.

Update CODING to document the use of AFS_FALLTHROUGH when needing to
fallthrough between case statements.

Replace the '/* fallthrough */' comments with AFS_FALLTHROUGH, and add
AFS_FALLTHROUGH as needed.

Replace some fallthroughs with a break (or goto) if the flow was was
just to a break (or goto).

e.g.   case x:                 case x:
           somestmt;               somestmt;
                                   break;
       case y:                 case y:
           break;                  break;

Correct a mis-indented brace '}' in src/WINNT/afsd/smb3.c

Note, the clang maintainers have rejected the use of comments as a flag
to turn off the fall through warnings.

Change-Id: Ia5da10fc14fc1874baca035a3cf471e618e0d5f5
Reviewed-on: https://gerrit.openafs.org/14274
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
This commit is contained in:
Cheyenne Wills 2020-07-27 08:33:03 -06:00 committed by Benjamin Kaduk
parent e61ab9353e
commit 16f1b2f894
32 changed files with 113 additions and 60 deletions

41
CODING
View File

@ -115,6 +115,47 @@ Instead of:
do_something();
}
In switch statements, to fall through from one case statement to another, use
AFS_FALLTHROUGH to mark the intentional fall through. Do not use fall through
comments (e.g. /* fallthrough */), as some compilers do not recognize them and
will flag the case statement with an implied fallthrough warning.
Use:
switch (x) {
case 1:
do_something();
AFS_FALLTHROUGH;
case 2:
do_something_else();
AFS_FALLTHROUGH;
default:
do_some_action();
}
Instead of using fallthrough comments:
switch (x) {
case 1:
do_something();
/* fallthrough */
case 2:
do_something_else();
/* fallthrough */
default:
do_some_action();
}
Or not marking the fall through:
switch (x) {
case 1:
do_something();
case 2:
do_something_else();
default:
do_some_action();
}
Dependencies required to build OpenAFS from source
--------------------------------------------------

View File

@ -653,7 +653,7 @@ void AfsAdmSvr_Action_StartRefresh (ASID idScope)
{
case itCELL:
AfsAdmSvr_MarkRefreshThread (idScope);
// fall through
AFS_FALLTHROUGH;
case itSERVER:
ASACTION Action;

View File

@ -1995,7 +1995,7 @@ MultiInputDialogProc( HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam)
if ( !GetDlgItemText(hDialog, ID_MID_TEXT+i, mid_tb[i].buf, mid_tb[i].len) )
*mid_tb[i].buf = '\0';
}
/* fallthrough */
AFS_FALLTHROUGH;
case IDCANCEL:
EndDialog(hDialog, LOWORD(wParam));
return TRUE;

View File

@ -252,7 +252,8 @@ void * cm_BkgDaemon(void * vparm)
cm_daemons[daemonID].retryCount++;
osi_QAddT((osi_queue_t **) &cm_daemons[daemonID].head, (osi_queue_t **)&cm_daemons[daemonID].tail, &rp->q);
break;
} /* otherwise fall through */
}
AFS_FALLTHROUGH;
case 0: /* success */
default: /* other error */
if (code == 0) {

View File

@ -768,7 +768,7 @@ int cm_MatchMask(clientchar_t *namep, clientchar_t *maskp, int flags)
break;
case '.':
dot++;
/* fallthrough */
AFS_FALLTHROUGH;
default:
if ( star ) {
newmask[j++] = '*';

View File

@ -877,12 +877,12 @@ NET_API_STATUS NetrShareGetInfo(
NetrIntGenerateSharePath(ServerName, &scp->fid);
/* must be the empty string */
InfoStruct->ShareInfo2->shi2_passwd = wcsdup(L"");
/* fall-through */
AFS_FALLTHROUGH;
case 1:
InfoStruct->ShareInfo1->shi1_type = STYPE_DISKTREE;
InfoStruct->ShareInfo1->shi1_remark =
NetrIntGenerateShareRemark(scp, &scp->fid);
/* fall-through */
AFS_FALLTHROUGH;
case 0:
/* Canonicalized version of NetName parameter */
InfoStruct->ShareInfo0->shi0_netname = wcsdup(NetName);
@ -995,7 +995,7 @@ NET_API_STATUS NetrServerGetInfo(
switch (Level) {
case 103:
InfoStruct->ServerInfo103->sv103_capabilities = 0;
/* fall-through */
AFS_FALLTHROUGH;
case 102:
InfoStruct->ServerInfo102->sv102_users = 0xFFFFFFFF;
InfoStruct->ServerInfo102->sv102_disc = SV_NODISC;
@ -1004,13 +1004,13 @@ NET_API_STATUS NetrServerGetInfo(
InfoStruct->ServerInfo102->sv102_anndelta = 0;
InfoStruct->ServerInfo102->sv102_licenses = 0;
InfoStruct->ServerInfo102->sv102_userpath = wcsdup(L"C:\\");
/* fall-through */
AFS_FALLTHROUGH;
case 101:
InfoStruct->ServerInfo101->sv101_version_major = AFSPRODUCT_VERSION_MAJOR;
InfoStruct->ServerInfo101->sv101_version_minor = AFSPRODUCT_VERSION_MINOR;
InfoStruct->ServerInfo101->sv101_type = SV_TYPE_WORKSTATION | SV_TYPE_SERVER | SV_TYPE_SERVER_UNIX;
InfoStruct->ServerInfo101->sv101_comment = wcsdup(wAFSVersion);
/* fall-through */
AFS_FALLTHROUGH;
case 100:
InfoStruct->ServerInfo100->sv100_platform_id = SV_PLATFORM_ID_AFS;
/* The Netbios Name */

View File

@ -9471,7 +9471,7 @@ void smb_Server(VOID *parmp)
case NRC_SNUMOUT:
case NRC_SABORT:
LogEvent(EVENTLOG_WARNING_TYPE, MSG_UNEXPECTED_SMB_SESSION_CLOSE, ncb_error_string(rc));
/* fallthrough */
AFS_FALLTHROUGH;
case NRC_SCLOSED:
/* Client closed session */
vcp = smb_FindVC(ncbp->ncb_lsn, 0, lanas[idx_session]);

View File

@ -5392,12 +5392,12 @@ long smb_T2SearchDirSingle(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *op
shortName);
fp->u.FfileBothDirectoryInfo.shortNameLength = cm_ClientStrLen(shortName);
#endif
}
/* Fallthrough */
}
AFS_FALLTHROUGH;
case SMB_FIND_FILE_FULL_DIRECTORY_INFO:
fp->u.FfileFullDirectoryInfo.eaSize = 0;
/* Fallthrough */
AFS_FALLTHROUGH;
case SMB_FIND_FILE_DIRECTORY_INFO:
fp->u.FfileDirectoryInfo.nextEntryOffset = 0;
@ -6108,11 +6108,11 @@ long smb_ReceiveTran2SearchDir(smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t
fp->u.FfileBothDirectoryInfo.shortNameLength = cm_ClientStrLen(shortName);
#endif
}
/* Fallthrough */
AFS_FALLTHROUGH;
case SMB_FIND_FILE_FULL_DIRECTORY_INFO:
fp->u.FfileFullDirectoryInfo.eaSize = 0;
/* Fallthrough */
AFS_FALLTHROUGH;
case SMB_FIND_FILE_DIRECTORY_INFO:
fp->u.FfileDirectoryInfo.nextEntryOffset = orbytes + align;

View File

@ -97,7 +97,7 @@ BOOL WINAPI Server_GetDates_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
{
case IDOK:
Server_GetDates_OnOK (hDlg);
// fall through
AFS_FALLTHROUGH;
case IDCANCEL:
DestroyWindow (hDlg);

View File

@ -94,7 +94,7 @@ BOOL WINAPI Server_Install_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
{
case IDOK:
Server_Install_OnOK (hDlg);
// fall through
AFS_FALLTHROUGH;
case IDCANCEL:
DestroyWindow (hDlg);

View File

@ -94,7 +94,7 @@ BOOL WINAPI Server_Prune_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
{
case IDOK:
Server_Prune_OnOK (hDlg);
// fall through
AFS_FALLTHROUGH;
case IDCANCEL:
DestroyWindow (hDlg);

View File

@ -93,7 +93,7 @@ static int afs_encode_fh(struct dentry *de, __u32 *fh, int *max_len,
if (*max_len < 5) {
return 255;
}
/* fall through */
AFS_FALLTHROUGH;
case VN_TYPE_CELL:
case VN_TYPE_ALIAS:

View File

@ -2638,7 +2638,7 @@ afs_linux_can_bypass(struct inode *ip) {
case LARGE_FILES_BYPASS_CACHE:
if (i_size_read(ip) > cache_bypass_threshold)
return 1;
/* fall through */
AFS_FALLTHROUGH;
default:
return 0;
}

View File

@ -288,7 +288,7 @@ addRandomKey(struct afsconf_dir *dir, int argc, char **argv)
switch (argc) {
case 5:
subtype = atoi(argv[4]);
/* fall through */
AFS_FALLTHROUGH;
case 4:
type = stringToType(argv[2]);
kvno = atoi(argv[3]);

View File

@ -247,12 +247,12 @@ k5_to_k4_name(krb5_context k5context,
i = get_princ_len(k5context, k5princ, 1);
if (i > MAXKTCNAMELEN-1) i = MAXKTCNAMELEN-1;
memcpy(ktcprinc->instance, get_princ_str(k5context, k5princ, 1), i);
/* fall through */
AFS_FALLTHROUGH;
case 1:
i = get_princ_len(k5context, k5princ, 0);
if (i > MAXKTCNAMELEN-1) i = MAXKTCNAMELEN-1;
memcpy(ktcprinc->name, get_princ_str(k5context, k5princ, 0), i);
/* fall through */
AFS_FALLTHROUGH;
case 0:
break;
}

View File

@ -868,7 +868,7 @@ dumpPass(struct dumpRock * dparamsPtr, int passNumber)
dparamsPtr->volumesFailed++;
continue;
}
/* fall through */
AFS_FALLTHROUGH;
case RWVOL:
for (e = 0; e < vldbEntry.nServers; e++) { /* Find the RW volume */
if (vldbEntry.serverFlags[e] & VLSF_RWVOL)

View File

@ -9,6 +9,7 @@ dnl roken. The HAVE___ATTRIBUTE__ symbol is not used in the OpenAFS code.
dnl
AC_DEFUN([OPENAFS_C_ATTRIBUTE], [
AX_GCC_FUNC_ATTRIBUTE([always_inline])
AX_GCC_FUNC_ATTRIBUTE([fallthrough])
AX_GCC_FUNC_ATTRIBUTE([format])
AX_GCC_FUNC_ATTRIBUTE([nonnull])
AX_GCC_FUNC_ATTRIBUTE([noreturn])

View File

@ -691,7 +691,7 @@ ResetSyntax(struct cmd_syndesc *as)
case CMD_SINGLE_OR_FLAG:
if (tp->items == &dummy)
break;
/* fall through */
AFS_FALLTHROUGH;
case CMD_SINGLE:
case CMD_LIST:
/* free whole list in both cases, just for fun */

View File

@ -307,6 +307,14 @@ hdr_static_inline(unsigned long long) afs_printable_uint64_lu(afs_uint64 d) { re
# define AFS_NONNULL(x)
#endif
#if defined(AFS_LINUX26_ENV) && defined(fallthrough)
# define AFS_FALLTHROUGH fallthrough
#elif defined(HAVE_FUNC_ATTRIBUTE_FALLTHROUGH)
# define AFS_FALLTHROUGH __attribute__((fallthrough))
#else
# define AFS_FALLTHROUGH do {} while(0)
#endif
/*
* Conditionally remove unreached statements under Solaris Studio.
*/

View File

@ -79,13 +79,10 @@ opr_jhash(const afs_uint32 *k, size_t length, afs_uint32 initval)
/* All the case statements fall through */
switch(length) {
case 3 : c+=k[2];
/* fall through */
case 2 : b+=k[1];
/* fall through */
case 3 : c+=k[2]; AFS_FALLTHROUGH;
case 2 : b+=k[1]; AFS_FALLTHROUGH;
case 1 : a+=k[0];
opr_jhash_final(a, b, c);
/* fall through */
opr_jhash_final(a, b, c); AFS_FALLTHROUGH;
case 0: /* case 0: nothing left to add */
break;
}
@ -150,19 +147,19 @@ opr_jhash_opaque(const void *val, size_t length, afs_uint32 initval)
/* All the case statements fall through */
switch(length) {
case 12 : c += (afs_uint32) str[11]<<24; /* fall through */
case 11 : c += (afs_uint32) str[10]<<16; /* fall through */
case 10 : c += (afs_uint32) str[9]<<8; /* fall through */
case 9 : c += (afs_uint32) str[8]; /* fall through */
case 8 : b += (afs_uint32) str[7]<<24; /* fall through */
case 7 : b += (afs_uint32) str[6]<<16; /* fall through */
case 6 : b += (afs_uint32) str[5]<<8; /* fall through */
case 5 : b += (afs_uint32) str[4]; /* fall through */
case 4 : a += (afs_uint32) str[3]<<24; /* fall through */
case 3 : a += (afs_uint32) str[2]<<16; /* fall through */
case 2 : a += (afs_uint32) str[1]<<8; /* fall through */
case 12 : c += (afs_uint32) str[11]<<24; AFS_FALLTHROUGH;
case 11 : c += (afs_uint32) str[10]<<16; AFS_FALLTHROUGH;
case 10 : c += (afs_uint32) str[9]<<8; AFS_FALLTHROUGH;
case 9 : c += (afs_uint32) str[8]; AFS_FALLTHROUGH;
case 8 : b += (afs_uint32) str[7]<<24; AFS_FALLTHROUGH;
case 7 : b += (afs_uint32) str[6]<<16; AFS_FALLTHROUGH;
case 6 : b += (afs_uint32) str[5]<<8; AFS_FALLTHROUGH;
case 5 : b += (afs_uint32) str[4]; AFS_FALLTHROUGH;
case 4 : a += (afs_uint32) str[3]<<24; AFS_FALLTHROUGH;
case 3 : a += (afs_uint32) str[2]<<16; AFS_FALLTHROUGH;
case 2 : a += (afs_uint32) str[1]<<8; AFS_FALLTHROUGH;
case 1 : a += (afs_uint32) str[0];
opr_jhash_final(a, b, c); /* fall through */
opr_jhash_final(a, b, c); AFS_FALLTHROUGH;
case 0: /* case 0: nothing left to add */
break;
}

View File

@ -122,6 +122,8 @@ rxi_calltrace(unsigned int event, struct rx_call *call)
case RX_CALL_ARRIVAL:
call->traceWait = now;
break;
default:
break;
}

View File

@ -424,7 +424,7 @@ xdr_bytes(XDR * xdrs, char **cpp, u_int * sizep,
if (sp == NULL) {
return (FALSE);
}
/* fall through */
AFS_FALLTHROUGH;
case XDR_ENCODE:
return (xdr_opaque(xdrs, sp, nodesize));
@ -519,7 +519,7 @@ xdr_string(XDR * xdrs, char **cpp, u_int maxsize)
if (sp == NULL) {
return (TRUE); /* already free */
}
/* Fall through */
AFS_FALLTHROUGH;
case XDR_ENCODE:
size = strlen(sp);
break;
@ -547,7 +547,7 @@ xdr_string(XDR * xdrs, char **cpp, u_int maxsize)
return (FALSE);
}
sp[size] = 0;
/* fall through */
AFS_FALLTHROUGH;
case XDR_ENCODE:
return (xdr_opaque(xdrs, sp, size));

View File

@ -750,7 +750,7 @@ tkt_DeriveDesKey(int enctype, void *keydata, size_t keylen,
case KRB5_ENCTYPE_DES3_CBC_SHA1:
if (compress_parity_bits(keydata, &keylen))
return 1;
/* FALLTHROUGH */
AFS_FALLTHROUGH;
default:
if (enctype < 0)
return 1;

View File

@ -442,7 +442,7 @@ xyzprintf(struct state *state, const char *char_format, va_list ap)
}
case '\0':
--format;
/* FALLTHROUGH */
AFS_FALLTHROUGH;
case '%':
if ((*state->append_char) (state, c))
return -1;

View File

@ -27,7 +27,7 @@
*/
/* parsevnode.c - Parse a VNode */
#include <afsconfig.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <errno.h>
@ -480,7 +480,7 @@ parse_vdata(XFILE * X, unsigned char *tag, tagged_field * field,
return r;
break;
}
/* fall through */
AFS_FALLTHROUGH;
default:
if ((r = xfskip(X, v->size)))
return r;

View File

@ -140,7 +140,7 @@ pass2()
#else /* no ACLS */
statemap[ROOTINO] = DSTATE;
#endif /* ACLS */
/* fall into ... */
AFS_FALLTHROUGH;
case DSTATE:
descend(&rootdesc, ROOTINO);
@ -347,7 +347,7 @@ pass2check(idesc)
else if ((n = reply("REMOVE")) == 1)
break;
}
/* fall through */
AFS_FALLTHROUGH;
case FSTATE:
#ifdef VICE

View File

@ -213,7 +213,7 @@ pass5()
case DCLEAR:
case DFOUND:
newcg->cg_cs.cs_ndir++;
/* fall through */
AFS_FALLTHROUGH;
#ifdef VICE
case VSTATE:

View File

@ -954,6 +954,7 @@ FSYNC_com_VolOff(FSSYNC_VolOp_command * vcom, SYNC_response * res)
VOL_CV_WAIT(&V_attachCV(vp));
}
break;
case debugUtility:
break;
@ -996,7 +997,7 @@ FSYNC_com_VolOff(FSSYNC_VolOp_command * vcom, SYNC_response * res)
* attaching the volume would be safe */
VRegisterVolOp_r(vp, &info);
vp->pending_vol_op->vol_op_state = FSSYNC_VolOpRunningUnknown;
/* fall through */
goto done;
case VOL_STATE_DELETED:
goto done;
@ -1026,7 +1027,7 @@ FSYNC_com_VolOff(FSSYNC_VolOp_command * vcom, SYNC_response * res)
* attaching the volume would be safe */
VRegisterVolOp_r(vp, &info);
vp->pending_vol_op->vol_op_state = FSSYNC_VolOpRunningUnknown;
/* fall through */
goto done;
case VOL_STATE_DELETED:
goto done;

View File

@ -478,7 +478,7 @@ SalvageClient(VolumeId vid, char * pname)
switch (sres.state) {
case SALVSYNC_STATE_ERROR:
printf("salvageserver reports salvage ended in an error; check log files for more details\n");
/* fall through */
AFS_FALLTHROUGH;
case SALVSYNC_STATE_DONE:
case SALVSYNC_STATE_UNKNOWN:
done = 1;

View File

@ -940,7 +940,7 @@ LinkNode(struct SalvageQueueNode * parent,
switch (clone->state) {
case SALVSYNC_STATE_QUEUED:
DeleteFromSalvageQueue(clone);
/* fall through */
AFS_FALLTHROUGH;
case SALVSYNC_STATE_SALVAGING:
switch (parent->state) {
case SALVSYNC_STATE_UNKNOWN:

View File

@ -1790,18 +1790,18 @@ ShutdownVolumeWalk_r(struct DiskPartition64 * dp, int pass,
(V_attachState(vp) != VOL_STATE_PREATTACHED)) {
break;
}
/* fall through */
AFS_FALLTHROUGH;
case 1:
if ((V_attachState(vp) == VOL_STATE_ATTACHED) &&
(vp->header == NULL)) {
break;
}
/* fall through */
AFS_FALLTHROUGH;
case 2:
if (VIsExclusiveState(V_attachState(vp))) {
break;
}
/* fall through */
AFS_FALLTHROUGH;
case 3:
*idx = nqp;
DeleteVolumeFromVByPList_r(vp);
@ -1845,6 +1845,7 @@ VShutdownVolume_r(Volume * vp)
case VOL_STATE_PREATTACHED:
case VOL_STATE_ERROR:
VChangeState_r(vp, VOL_STATE_UNATTACHED);
break;
case VOL_STATE_UNATTACHED:
case VOL_STATE_DELETED:
break;

View File

@ -2276,6 +2276,7 @@ GetVolInfo(afs_uint32 partId,
case VOL_INFO_LIST_SINGLE:
Log("1 Volser: GetVolInfo: Volume %" AFS_VOLID_FMT " (%s:%s) will be destroyed on next salvage\n",
afs_printable_VolumeId_lu(volumeId), pname, volname);
goto drop;
default:
goto drop;