Skip to content

Commit dc7b1d2

Browse files
authored
Enable implicit fallthrough warning (#43397)
* Enable implicit fallthrough warning This change enables warnings for implicit fallthrough in switch cases and fixes all the cases where the warning was reported. It also fixes some places where the fall through was incorrect. Fortunately, these places were not causing functional issues.
1 parent 159a6ea commit dc7b1d2

File tree

94 files changed

+380
-247
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+380
-247
lines changed

eng/native/configurecompiler.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ if (CLR_CMAKE_HOST_UNIX)
324324
add_compile_options(-Wno-unused-function)
325325
add_compile_options(-Wno-tautological-compare)
326326

327+
check_cxx_compiler_flag(-Wimplicit-fallthrough COMPILER_SUPPORTS_W_IMPLICIT_FALLTHROUGH)
328+
if (COMPILER_SUPPORTS_W_IMPLICIT_FALLTHROUGH)
329+
add_compile_options(-Wimplicit-fallthrough)
330+
endif()
331+
327332
#These seem to indicate real issues
328333
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-invalid-offsetof>)
329334

src/coreclr/src/ToolBox/superpmi/mcs/verbildump.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ void DumpILToConsoleBare(unsigned char* ilCode, int len)
893893
LogError("unknown ilCode 0xfe%2x at offset %d in MethodGen::PrettyPrint", ilCode[i], i);
894894
break;
895895
}
896+
break;
896897
default:
897898
LogError("unknown ilCode 0x%02x at offset %d in MethodGen::PrettyPrint", ilCode[i], i);
898899
break;

src/coreclr/src/classlibnative/bcltype/varargsnative.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,8 @@ VarArgsNative::GetNextArgHelper(
575575
}
576576
#endif
577577

578-
// fall through
578+
FALLTHROUGH;
579+
579580
case ELEMENT_TYPE_CLASS: {
580581
value->type = data->SigPtr.GetTypeHandleThrowing(data->ArgCookie->pModule, &typeContext);
581582

src/coreclr/src/debug/di/rstype.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ HRESULT CordbType::MkType(CordbAppDomain * pAppDomain,
590590

591591
pClass->SetIsValueClass(true);
592592
pClass->SetIsValueClassKnown(true);
593-
// drop through
593+
FALLTHROUGH;
594594

595595
case ELEMENT_TYPE_CLASS:
596596
{
@@ -2009,6 +2009,7 @@ void CordbType::TypeToExpandedTypeData(DebuggerIPCE_ExpandedTypeData *data)
20092009
}
20102010
case ELEMENT_TYPE_END:
20112011
_ASSERTE(!"bad element type!");
2012+
break;
20122013

20132014
default:
20142015
data->elementType = m_elementType;
@@ -2389,6 +2390,7 @@ HRESULT CordbType::GetTypeID(COR_TYPEID *pId)
23892390
case ELEMENT_TYPE_BYREF:
23902391
case ELEMENT_TYPE_FNPTR:
23912392
IfFailThrow(CORDBG_E_UNSUPPORTED);
2393+
break;
23922394
default:
23932395
_ASSERTE(!"unexpected element type!");
23942396
IfFailThrow(CORDBG_E_UNSUPPORTED);

src/coreclr/src/debug/ee/amd64/amd64walker.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ static int opSize(Amd64InstrDecode::InstrForm form, int pp, bool W, bool L, bool
580580
// P_M6B_or_M4B
581581
case Amd64InstrDecode::InstrForm::MOnly_P_M6B_or_M4B:
582582
opSize = P ? 6 : 4;
583+
break;
583584
// M4B
584585
case Amd64InstrDecode::InstrForm::M1st_M4B:
585586
case Amd64InstrDecode::InstrForm::M1st_M4B_I1B:
@@ -833,7 +834,7 @@ void NativeWalker::DecodeInstructionForPatchSkip(const BYTE *address, Instructio
833834
opCodeMap = Primary;
834835
break;
835836
}
836-
// Fall through
837+
FALLTHROUGH;
837838
case 0xc4: // Vex 3-byte
838839
opCodeMap = (OpcodeMap)(int(address[0]) << 8 | (address[1] & 0x1f));
839840
// W is the top bit of opcode2.
@@ -965,7 +966,7 @@ void NativeWalker::DecodeInstructionForPatchSkip(const BYTE *address, Instructio
965966
case 2:
966967
case 3:
967968
pInstrAttrib->m_fIsCall = true;
968-
// fall through
969+
FALLTHROUGH;
969970
case 4:
970971
case 5:
971972
pInstrAttrib->m_fIsAbsBranch = true;

src/coreclr/src/debug/ee/controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5883,7 +5883,7 @@ bool DebuggerStepper::TrapStep(ControllerStackInfo *info, bool in)
58835883
// the case we want to use...
58845884
fIsJump = true;
58855885

5886-
// fall through...
5886+
FALLTHROUGH;
58875887

58885888
case WALK_CALL:
58895889
LOG((LF_CORDB,LL_INFO10000, "DC::TS:Imm:WALK_CALL ip=%p nextip=%p skipip=%p\n", walker.GetIP(), walker.GetNextIP(), walker.GetSkipIP()));

src/coreclr/src/debug/ee/debugger.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10722,6 +10722,7 @@ bool Debugger::HandleIPCEvent(DebuggerIPCEvent * pEvent)
1072210722
//
1072310723
// For regular (non-jit) attach, fall through to do an async break.
1072410724
//
10725+
FALLTHROUGH;
1072510726

1072610727
case DB_IPCE_ASYNC_BREAK:
1072710728
{
@@ -12138,7 +12139,7 @@ void Debugger::TypeHandleToExpandedTypeInfo(AreValueTypesBoxed boxed,
1213812139
case ELEMENT_TYPE_VALUETYPE:
1213912140
if (boxed == OnlyPrimitivesUnboxed || boxed == AllBoxed)
1214012141
res->elementType = ELEMENT_TYPE_CLASS;
12141-
// drop through
12142+
FALLTHROUGH;
1214212143

1214312144
case ELEMENT_TYPE_CLASS:
1214412145
{

src/coreclr/src/gc/unix/gcenv.unix.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
#undef min
2929
#undef max
3030

31+
#if __has_cpp_attribute(fallthrough)
32+
#define FALLTHROUGH [[fallthrough]]
33+
#else
34+
#define FALLTHROUGH
35+
#endif
36+
3137
#include <algorithm>
3238

3339
#if HAVE_SYS_TIME_H
@@ -792,8 +798,10 @@ bool ReadMemoryValueFromFile(const char* filename, uint64_t* val)
792798
{
793799
case 'g':
794800
case 'G': multiplier = 1024;
801+
FALLTHROUGH;
795802
case 'm':
796803
case 'M': multiplier = multiplier * 1024;
804+
FALLTHROUGH;
797805
case 'k':
798806
case 'K': multiplier = multiplier * 1024;
799807
}

src/coreclr/src/ilasm/assem.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,16 +1611,26 @@ unsigned hash(
16111611
switch(len) /* all the case statements fall through */
16121612
{
16131613
case 11: c+=((unsigned)k[10] << 24);
1614+
FALLTHROUGH;
16141615
case 10: c+=((unsigned)k[9] << 16);
1616+
FALLTHROUGH;
16151617
case 9 : c+=((unsigned)k[8] << 8);
1618+
FALLTHROUGH;
16161619
/* the first byte of c is reserved for the length */
16171620
case 8 : b+=((unsigned)k[7] << 24);
1621+
FALLTHROUGH;
16181622
case 7 : b+=((unsigned)k[6] << 16);
1623+
FALLTHROUGH;
16191624
case 6 : b+=((unsigned)k[5] << 8);
1625+
FALLTHROUGH;
16201626
case 5 : b+=k[4];
1627+
FALLTHROUGH;
16211628
case 4 : a+=((unsigned)k[3] << 24);
1629+
FALLTHROUGH;
16221630
case 3 : a+=((unsigned)k[2] << 16);
1631+
FALLTHROUGH;
16231632
case 2 : a+=((unsigned)k[1] << 8);
1633+
FALLTHROUGH;
16241634
case 1 : a+=k[0];
16251635
/* case 0: nothing left to add */
16261636
}

src/coreclr/src/ilasm/assembler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,7 @@ void Assembler::EmitInstrVarByName(Instr* instr, __in __nullterminated char* lab
15781578
case CEE_STARG:
15791579
case CEE_STARG_S:
15801580
nArgVarFlag++;
1581+
FALLTHROUGH;
15811582
case CEE_LDLOCA:
15821583
case CEE_LDLOCA_S:
15831584
case CEE_LDLOC:

src/coreclr/src/ilasm/prebuilt/asmparse.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,7 @@ YYLOCAL YYNEAR YYPASCAL YYPARSER()
20192019

20202020
yyerrlab:
20212021
++yynerrs;
2022+
FALLTHROUGH;
20222023

20232024
case 1:
20242025
case 2: /* incompletely recovered error ... try again */

src/coreclr/src/ildasm/dasm.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,7 @@ BYTE* PrettyPrintCABlobValue(PCCOR_SIGNATURE &typePtr,
20082008
break;
20092009
case ELEMENT_TYPE_CLASS :
20102010
typePtr += CorSigUncompressToken(typePtr, &tk); //skip the following token
2011+
FALLTHROUGH;
20112012
case SERIALIZATION_TYPE_TYPE :
20122013
appendStr(out,KEYWORD("type"));
20132014
appendStr(out,appendix);
@@ -2668,6 +2669,7 @@ void DumpDefaultValue(mdToken tok, __inout __nullterminated char* szString, void
26682669
break;
26692670
}
26702671
//else fall thru to default case, to report the error
2672+
FALLTHROUGH;
26712673

26722674
default:
26732675
szptr+=sprintf_s(szptr,SZSTRING_REMAINING_SIZE(szptr),ERRORMSG(" /* ILLEGAL CONSTANT type:0x%02X, size:%d bytes, blob: "),MDDV.m_bType,MDDV.m_cbSize);

src/coreclr/src/ildasm/dasm_sz.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ unsigned SizeOfField(PCCOR_SIGNATURE *ppSig, ULONG cSig, IMDInternalImport* pImp
211211
case ELEMENT_TYPE_CMOD_OPT :
212212
case ELEMENT_TYPE_CMOD_REQD :
213213
*ppSig += CorSigUncompressToken(*ppSig, &tk);
214+
FALLTHROUGH;
214215
case ELEMENT_TYPE_PINNED :
215216
case ELEMENT_TYPE_SZARRAY : // uElementNumber doesn't change
216217
if(*ppSig < pSigEnd) Reiterate = TRUE;

src/coreclr/src/inc/palclr_win.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,8 @@
140140
typedef HMODULE NATIVE_LIBRARY_HANDLE;
141141
#endif // HOST_WINDOWS
142142

143+
#ifndef FALLTHROUGH
144+
#define FALLTHROUGH __fallthrough
145+
#endif // FALLTHROUGH
146+
143147
#endif // __PALCLR_WIN_H__

src/coreclr/src/jit/assertionprop.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4546,7 +4546,7 @@ void Compiler::optImpliedByCopyAssertion(AssertionDsc* copyAssertion, AssertionD
45464546
// This is the ngen case where we have an indirection of an address.
45474547
noway_assert((impAssertion->op1.kind == O1K_EXACT_TYPE) || (impAssertion->op1.kind == O1K_SUBTYPE));
45484548

4549-
__fallthrough;
4549+
FALLTHROUGH;
45504550

45514551
case O2K_CONST_INT:
45524552
usable = op1MatchesCopy && (impAssertion->op2.u1.iconVal == depAssertion->op2.u1.iconVal);

src/coreclr/src/jit/codegenarmarch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
207207
case GT_AND:
208208
assert(varTypeIsIntegralOrI(treeNode));
209209

210-
__fallthrough;
210+
FALLTHROUGH;
211211

212212
#if !defined(TARGET_64BIT)
213213
case GT_ADD_LO:

src/coreclr/src/jit/codegencommon.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ bool CodeGen::genCreateAddrMode(GenTree* addr,
14211421
return false; // Need overflow check
14221422
}
14231423

1424-
__fallthrough;
1424+
FALLTHROUGH;
14251425

14261426
case GT_LSH:
14271427

@@ -1486,7 +1486,7 @@ bool CodeGen::genCreateAddrMode(GenTree* addr,
14861486
break;
14871487
}
14881488

1489-
__fallthrough;
1489+
FALLTHROUGH;
14901490

14911491
case GT_LSH:
14921492

@@ -1568,7 +1568,7 @@ bool CodeGen::genCreateAddrMode(GenTree* addr,
15681568
break;
15691569
}
15701570

1571-
__fallthrough;
1571+
FALLTHROUGH;
15721572

15731573
case GT_LSH:
15741574

@@ -8401,7 +8401,7 @@ void CodeGen::genFnEpilog(BasicBlock* block)
84018401

84028402
// otherwise the target address doesn't fit in an immediate
84038403
// so we have to burn a register...
8404-
__fallthrough;
8404+
FALLTHROUGH;
84058405

84068406
case IAT_PVALUE:
84078407
// Load the address into a register, load indirect and call through a register

src/coreclr/src/jit/codegenlinear.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ void CodeGen::genCodeForBBlist()
720720

721721
case BBJ_EHCATCHRET:
722722
genEHCatchRet(block);
723-
__fallthrough;
723+
FALLTHROUGH;
724724

725725
case BBJ_EHFINALLYRET:
726726
case BBJ_EHFILTERRET:
@@ -731,6 +731,7 @@ void CodeGen::genCodeForBBlist()
731731

732732
case BBJ_EHCATCHRET:
733733
noway_assert(!"Unexpected BBJ_EHCATCHRET"); // not used on x86
734+
break;
734735

735736
case BBJ_EHFINALLYRET:
736737
case BBJ_EHFILTERRET:

src/coreclr/src/jit/codegenxarch.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
14811481
#ifdef TARGET_X86
14821482
assert(!treeNode->IsIconHandle(GTF_ICON_TLS_HDL));
14831483
#endif // TARGET_X86
1484-
__fallthrough;
1484+
FALLTHROUGH;
14851485

14861486
case GT_CNS_DBL:
14871487
genSetRegToConst(targetReg, targetType, treeNode);
@@ -1504,7 +1504,7 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
15041504
genCodeForBinary(treeNode->AsOp());
15051505
break;
15061506
}
1507-
__fallthrough;
1507+
FALLTHROUGH;
15081508
case GT_MOD:
15091509
case GT_UMOD:
15101510
case GT_UDIV:
@@ -1516,7 +1516,7 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
15161516
case GT_AND:
15171517
assert(varTypeIsIntegralOrI(treeNode));
15181518

1519-
__fallthrough;
1519+
FALLTHROUGH;
15201520

15211521
#if !defined(TARGET_64BIT)
15221522
case GT_ADD_LO:

src/coreclr/src/jit/compiler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8745,7 +8745,7 @@ void cTreeFlags(Compiler* comp, GenTree* tree)
87458745
{
87468746
chars += printf("[INX_STRING_LAYOUT]");
87478747
}
8748-
__fallthrough;
8748+
FALLTHROUGH;
87498749
case GT_INDEX_ADDR:
87508750
if (tree->gtFlags & GTF_INX_RNGCHK)
87518751
{
@@ -8963,7 +8963,7 @@ void cTreeFlags(Compiler* comp, GenTree* tree)
89638963
{
89648964
chars += printf("[BLK_HASGCPTR]");
89658965
}
8966-
__fallthrough;
8966+
FALLTHROUGH;
89678967

89688968
case GT_BLK:
89698969
case GT_DYN_BLK:

src/coreclr/src/jit/compiler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10349,7 +10349,7 @@ class GenTreeVisitor
1034910349
return result;
1035010350
}
1035110351
}
10352-
__fallthrough;
10352+
FALLTHROUGH;
1035310353

1035410354
// Leaf nodes
1035510355
case GT_CATCH_ARG:
@@ -10394,7 +10394,7 @@ class GenTreeVisitor
1039410394
return result;
1039510395
}
1039610396
}
10397-
__fallthrough;
10397+
FALLTHROUGH;
1039810398

1039910399
// Standard unary operators
1040010400
case GT_NOT:

src/coreclr/src/jit/compiler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4347,7 +4347,7 @@ void GenTree::VisitOperands(TVisitor visitor)
43474347
{
43484348
return;
43494349
}
4350-
__fallthrough;
4350+
FALLTHROUGH;
43514351

43524352
// Standard unary operators
43534353
case GT_STORE_LCL_VAR:

src/coreclr/src/jit/disasm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ size_t DisAssembler::CbDisassemble(DIS* pdis,
964964
}
965965
}
966966

967-
__fallthrough;
967+
FALLTHROUGH;
968968

969969
case DISX86::trmtaJmpShort:
970970
case DISX86::trmtaJmpNear:
@@ -1022,7 +1022,7 @@ size_t DisAssembler::CbDisassemble(DIS* pdis,
10221022
}
10231023
}
10241024

1025-
__fallthrough;
1025+
FALLTHROUGH;
10261026

10271027
case DISARM64::TRMTA::trmtaBra:
10281028
case DISARM64::TRMTA::trmtaBraCase:

src/coreclr/src/jit/eeinterface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const char* Compiler::eeGetMethodFullName(CORINFO_METHOD_HANDLE hnd)
142142
}
143143
}
144144
}
145-
__fallthrough;
145+
FALLTHROUGH;
146146
default:
147147
pParam->pArgNames[i] = varTypeName(type);
148148
break;
@@ -177,7 +177,7 @@ const char* Compiler::eeGetMethodFullName(CORINFO_METHOD_HANDLE hnd)
177177
}
178178
}
179179
}
180-
__fallthrough;
180+
FALLTHROUGH;
181181
default:
182182
pParam->returnType = varTypeName(retType);
183183
break;

0 commit comments

Comments
 (0)