Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable implicit fallthrough warning #43397

Merged
merged 14 commits into from
Oct 21, 2020
5 changes: 5 additions & 0 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ if (CLR_CMAKE_HOST_UNIX)
add_compile_options(-Wno-unused-function)
add_compile_options(-Wno-tautological-compare)

check_cxx_compiler_flag(-Wimplicit-fallthrough COMPILER_SUPPORTS_W_IMPLICIT_FALLTHROUGH)
if (COMPILER_SUPPORTS_W_IMPLICIT_FALLTHROUGH)
add_compile_options(-Wimplicit-fallthrough)
endif()

#These seem to indicate real issues
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-invalid-offsetof>)

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/src/ToolBox/superpmi/mcs/verbildump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ void DumpILToConsoleBare(unsigned char* ilCode, int len)
LogError("unknown ilCode 0xfe%2x at offset %d in MethodGen::PrettyPrint", ilCode[i], i);
break;
}
break;
default:
LogError("unknown ilCode 0x%02x at offset %d in MethodGen::PrettyPrint", ilCode[i], i);
break;
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/src/classlibnative/bcltype/varargsnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ VarArgsNative::GetNextArgHelper(
}
#endif

// fall through
FALLTHROUGH;

case ELEMENT_TYPE_CLASS: {
value->type = data->SigPtr.GetTypeHandleThrowing(data->ArgCookie->pModule, &typeContext);

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/src/debug/di/rstype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ HRESULT CordbType::MkType(CordbAppDomain * pAppDomain,

pClass->SetIsValueClass(true);
pClass->SetIsValueClassKnown(true);
// drop through
FALLTHROUGH;

case ELEMENT_TYPE_CLASS:
{
Expand Down Expand Up @@ -2009,6 +2009,7 @@ void CordbType::TypeToExpandedTypeData(DebuggerIPCE_ExpandedTypeData *data)
}
case ELEMENT_TYPE_END:
_ASSERTE(!"bad element type!");
break;

default:
data->elementType = m_elementType;
Expand Down Expand Up @@ -2389,6 +2390,7 @@ HRESULT CordbType::GetTypeID(COR_TYPEID *pId)
case ELEMENT_TYPE_BYREF:
case ELEMENT_TYPE_FNPTR:
IfFailThrow(CORDBG_E_UNSUPPORTED);
break;
default:
_ASSERTE(!"unexpected element type!");
IfFailThrow(CORDBG_E_UNSUPPORTED);
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/src/debug/ee/amd64/amd64walker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ static int opSize(Amd64InstrDecode::InstrForm form, int pp, bool W, bool L, bool
// P_M6B_or_M4B
case Amd64InstrDecode::InstrForm::MOnly_P_M6B_or_M4B:
opSize = P ? 6 : 4;
break;
// M4B
case Amd64InstrDecode::InstrForm::M1st_M4B:
case Amd64InstrDecode::InstrForm::M1st_M4B_I1B:
Expand Down Expand Up @@ -833,7 +834,7 @@ void NativeWalker::DecodeInstructionForPatchSkip(const BYTE *address, Instructio
opCodeMap = Primary;
break;
}
// Fall through
FALLTHROUGH;
case 0xc4: // Vex 3-byte
opCodeMap = (OpcodeMap)(int(address[0]) << 8 | (address[1] & 0x1f));
// W is the top bit of opcode2.
Expand Down Expand Up @@ -965,7 +966,7 @@ void NativeWalker::DecodeInstructionForPatchSkip(const BYTE *address, Instructio
case 2:
case 3:
pInstrAttrib->m_fIsCall = true;
// fall through
FALLTHROUGH;
case 4:
case 5:
pInstrAttrib->m_fIsAbsBranch = true;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/debug/ee/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5883,7 +5883,7 @@ bool DebuggerStepper::TrapStep(ControllerStackInfo *info, bool in)
// the case we want to use...
fIsJump = true;

// fall through...
FALLTHROUGH;

case WALK_CALL:
LOG((LF_CORDB,LL_INFO10000, "DC::TS:Imm:WALK_CALL ip=%p nextip=%p skipip=%p\n", walker.GetIP(), walker.GetNextIP(), walker.GetSkipIP()));
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/src/debug/ee/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10722,6 +10722,7 @@ bool Debugger::HandleIPCEvent(DebuggerIPCEvent * pEvent)
//
// For regular (non-jit) attach, fall through to do an async break.
//
FALLTHROUGH;

case DB_IPCE_ASYNC_BREAK:
{
Expand Down Expand Up @@ -12138,7 +12139,7 @@ void Debugger::TypeHandleToExpandedTypeInfo(AreValueTypesBoxed boxed,
case ELEMENT_TYPE_VALUETYPE:
if (boxed == OnlyPrimitivesUnboxed || boxed == AllBoxed)
res->elementType = ELEMENT_TYPE_CLASS;
// drop through
FALLTHROUGH;

case ELEMENT_TYPE_CLASS:
{
Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/src/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
#undef min
#undef max

#if __has_cpp_attribute(fallthrough)
#define FALLTHROUGH [[fallthrough]]
#else
#define FALLTHROUGH
#endif

#include <algorithm>

#if HAVE_SYS_TIME_H
Expand Down Expand Up @@ -792,8 +798,10 @@ bool ReadMemoryValueFromFile(const char* filename, uint64_t* val)
{
case 'g':
case 'G': multiplier = 1024;
FALLTHROUGH;
case 'm':
case 'M': multiplier = multiplier * 1024;
FALLTHROUGH;
case 'k':
case 'K': multiplier = multiplier * 1024;
}
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/src/ilasm/assem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1611,16 +1611,26 @@ unsigned hash(
switch(len) /* all the case statements fall through */
{
case 11: c+=((unsigned)k[10] << 24);
FALLTHROUGH;
case 10: c+=((unsigned)k[9] << 16);
FALLTHROUGH;
case 9 : c+=((unsigned)k[8] << 8);
FALLTHROUGH;
/* the first byte of c is reserved for the length */
case 8 : b+=((unsigned)k[7] << 24);
FALLTHROUGH;
case 7 : b+=((unsigned)k[6] << 16);
FALLTHROUGH;
case 6 : b+=((unsigned)k[5] << 8);
FALLTHROUGH;
case 5 : b+=k[4];
FALLTHROUGH;
case 4 : a+=((unsigned)k[3] << 24);
FALLTHROUGH;
case 3 : a+=((unsigned)k[2] << 16);
FALLTHROUGH;
case 2 : a+=((unsigned)k[1] << 8);
FALLTHROUGH;
case 1 : a+=k[0];
/* case 0: nothing left to add */
}
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/src/ilasm/assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,7 @@ void Assembler::EmitInstrVarByName(Instr* instr, __in __nullterminated char* lab
case CEE_STARG:
case CEE_STARG_S:
nArgVarFlag++;
FALLTHROUGH;
case CEE_LDLOCA:
case CEE_LDLOCA_S:
case CEE_LDLOC:
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/src/ilasm/prebuilt/asmparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,7 @@ YYLOCAL YYNEAR YYPASCAL YYPARSER()

yyerrlab:
++yynerrs;
FALLTHROUGH;

case 1:
case 2: /* incompletely recovered error ... try again */
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/src/ildasm/dasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2008,6 +2008,7 @@ BYTE* PrettyPrintCABlobValue(PCCOR_SIGNATURE &typePtr,
break;
case ELEMENT_TYPE_CLASS :
typePtr += CorSigUncompressToken(typePtr, &tk); //skip the following token
FALLTHROUGH;
case SERIALIZATION_TYPE_TYPE :
appendStr(out,KEYWORD("type"));
appendStr(out,appendix);
Expand Down Expand Up @@ -2668,6 +2669,7 @@ void DumpDefaultValue(mdToken tok, __inout __nullterminated char* szString, void
break;
}
//else fall thru to default case, to report the error
FALLTHROUGH;

default:
szptr+=sprintf_s(szptr,SZSTRING_REMAINING_SIZE(szptr),ERRORMSG(" /* ILLEGAL CONSTANT type:0x%02X, size:%d bytes, blob: "),MDDV.m_bType,MDDV.m_cbSize);
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/src/ildasm/dasm_sz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ unsigned SizeOfField(PCCOR_SIGNATURE *ppSig, ULONG cSig, IMDInternalImport* pImp
case ELEMENT_TYPE_CMOD_OPT :
case ELEMENT_TYPE_CMOD_REQD :
*ppSig += CorSigUncompressToken(*ppSig, &tk);
FALLTHROUGH;
case ELEMENT_TYPE_PINNED :
case ELEMENT_TYPE_SZARRAY : // uElementNumber doesn't change
if(*ppSig < pSigEnd) Reiterate = TRUE;
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/src/inc/palclr_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,8 @@
typedef HMODULE NATIVE_LIBRARY_HANDLE;
#endif // HOST_WINDOWS

#ifndef FALLTHROUGH
#define FALLTHROUGH __fallthrough
#endif // FALLTHROUGH

#endif // __PALCLR_WIN_H__
2 changes: 1 addition & 1 deletion src/coreclr/src/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4546,7 +4546,7 @@ void Compiler::optImpliedByCopyAssertion(AssertionDsc* copyAssertion, AssertionD
// This is the ngen case where we have an indirection of an address.
noway_assert((impAssertion->op1.kind == O1K_EXACT_TYPE) || (impAssertion->op1.kind == O1K_SUBTYPE));

__fallthrough;
FALLTHROUGH;

case O2K_CONST_INT:
usable = op1MatchesCopy && (impAssertion->op2.u1.iconVal == depAssertion->op2.u1.iconVal);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
case GT_AND:
assert(varTypeIsIntegralOrI(treeNode));

__fallthrough;
FALLTHROUGH;

#if !defined(TARGET_64BIT)
case GT_ADD_LO:
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/src/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ bool CodeGen::genCreateAddrMode(GenTree* addr,
return false; // Need overflow check
}

__fallthrough;
FALLTHROUGH;

case GT_LSH:

Expand Down Expand Up @@ -1486,7 +1486,7 @@ bool CodeGen::genCreateAddrMode(GenTree* addr,
break;
}

__fallthrough;
FALLTHROUGH;

case GT_LSH:

Expand Down Expand Up @@ -1568,7 +1568,7 @@ bool CodeGen::genCreateAddrMode(GenTree* addr,
break;
}

__fallthrough;
FALLTHROUGH;

case GT_LSH:

Expand Down Expand Up @@ -8401,7 +8401,7 @@ void CodeGen::genFnEpilog(BasicBlock* block)

// otherwise the target address doesn't fit in an immediate
// so we have to burn a register...
__fallthrough;
FALLTHROUGH;

case IAT_PVALUE:
// Load the address into a register, load indirect and call through a register
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/src/jit/codegenlinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ void CodeGen::genCodeForBBlist()

case BBJ_EHCATCHRET:
genEHCatchRet(block);
__fallthrough;
FALLTHROUGH;

case BBJ_EHFINALLYRET:
case BBJ_EHFILTERRET:
Expand All @@ -731,6 +731,7 @@ void CodeGen::genCodeForBBlist()

case BBJ_EHCATCHRET:
noway_assert(!"Unexpected BBJ_EHCATCHRET"); // not used on x86
break;

case BBJ_EHFINALLYRET:
case BBJ_EHFILTERRET:
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/src/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
#ifdef TARGET_X86
assert(!treeNode->IsIconHandle(GTF_ICON_TLS_HDL));
#endif // TARGET_X86
__fallthrough;
FALLTHROUGH;

case GT_CNS_DBL:
genSetRegToConst(targetReg, targetType, treeNode);
Expand All @@ -1504,7 +1504,7 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
genCodeForBinary(treeNode->AsOp());
break;
}
__fallthrough;
FALLTHROUGH;
case GT_MOD:
case GT_UMOD:
case GT_UDIV:
Expand All @@ -1516,7 +1516,7 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
case GT_AND:
assert(varTypeIsIntegralOrI(treeNode));

__fallthrough;
FALLTHROUGH;

#if !defined(TARGET_64BIT)
case GT_ADD_LO:
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/src/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8747,7 +8747,7 @@ void cTreeFlags(Compiler* comp, GenTree* tree)
{
chars += printf("[INX_STRING_LAYOUT]");
}
__fallthrough;
FALLTHROUGH;
case GT_INDEX_ADDR:
if (tree->gtFlags & GTF_INX_RNGCHK)
{
Expand Down Expand Up @@ -8965,7 +8965,7 @@ void cTreeFlags(Compiler* comp, GenTree* tree)
{
chars += printf("[BLK_HASGCPTR]");
}
__fallthrough;
FALLTHROUGH;

case GT_BLK:
case GT_DYN_BLK:
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10348,7 +10348,7 @@ class GenTreeVisitor
return result;
}
}
__fallthrough;
FALLTHROUGH;

// Leaf nodes
case GT_CATCH_ARG:
Expand Down Expand Up @@ -10393,7 +10393,7 @@ class GenTreeVisitor
return result;
}
}
__fallthrough;
FALLTHROUGH;

// Standard unary operators
case GT_NOT:
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4347,7 +4347,7 @@ void GenTree::VisitOperands(TVisitor visitor)
{
return;
}
__fallthrough;
FALLTHROUGH;

// Standard unary operators
case GT_STORE_LCL_VAR:
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/src/jit/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ size_t DisAssembler::CbDisassemble(DIS* pdis,
}
}

__fallthrough;
FALLTHROUGH;

case DISX86::trmtaJmpShort:
case DISX86::trmtaJmpNear:
Expand Down Expand Up @@ -1022,7 +1022,7 @@ size_t DisAssembler::CbDisassemble(DIS* pdis,
}
}

__fallthrough;
FALLTHROUGH;

case DISARM64::TRMTA::trmtaBra:
case DISARM64::TRMTA::trmtaBraCase:
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/src/jit/eeinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const char* Compiler::eeGetMethodFullName(CORINFO_METHOD_HANDLE hnd)
}
}
}
__fallthrough;
FALLTHROUGH;
default:
pParam->pArgNames[i] = varTypeName(type);
break;
Expand Down Expand Up @@ -177,7 +177,7 @@ const char* Compiler::eeGetMethodFullName(CORINFO_METHOD_HANDLE hnd)
}
}
}
__fallthrough;
FALLTHROUGH;
default:
pParam->returnType = varTypeName(retType);
break;
Expand Down
Loading