From 94e3fff083eed4833b6e8547dc1be822397e4aa6 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Fri, 4 Apr 2014 12:16:59 +0100 Subject: [PATCH] Turn on -wswitch-default for gcc. Add missing default: cases to switch statements. Copied from Perforce Change: 185226 ServerID: perforce.ravenbrook.com --- mps/code/eventcnv.c | 3 +++ mps/code/fbmtest.c | 23 ++++++++++++----------- mps/code/gc.gmk | 1 + mps/code/gcbench.c | 8 ++++++-- mps/code/mpsicv.c | 5 +++-- mps/code/prmci3li.c | 9 +++++---- mps/code/prmci3w3.c | 9 +++++---- mps/code/prmci3xc.c | 9 +++++---- mps/code/prmci6li.c | 9 +++++---- mps/code/prmci6w3.c | 9 +++++---- mps/code/prmci6xc.c | 9 +++++---- mps/code/sacss.c | 18 +++++++++--------- 12 files changed, 64 insertions(+), 48 deletions(-) diff --git a/mps/code/eventcnv.c b/mps/code/eventcnv.c index 82fef956eba..355b6efa2a2 100644 --- a/mps/code/eventcnv.c +++ b/mps/code/eventcnv.c @@ -264,6 +264,9 @@ static void readLog(FILE *stream) event->EventInit.f5, MPS_WORD_WIDTH); break; + default: + /* No special treatment needed. */ + break; } (void)EVENT_CLOCK_PRINT(stdout, eventTime); diff --git a/mps/code/fbmtest.c b/mps/code/fbmtest.c index f98c49032a9..2b6437c216d 100644 --- a/mps/code/fbmtest.c +++ b/mps/code/fbmtest.c @@ -432,20 +432,23 @@ static void find(FBMState state, Size size, Bool high, FindDelete findDelete) remainderLimit = origLimit = addrOfIndex(state, expectedLimit); switch(findDelete) { - case FindDeleteNONE: { + case FindDeleteNONE: /* do nothing */ - } break; - case FindDeleteENTIRE: { + break; + case FindDeleteENTIRE: remainderBase = remainderLimit; - } break; - case FindDeleteLOW: { + break; + case FindDeleteLOW: expectedLimit = expectedBase + size; remainderBase = addrOfIndex(state, expectedLimit); - } break; - case FindDeleteHIGH: { + break; + case FindDeleteHIGH: expectedBase = expectedLimit - size; remainderLimit = addrOfIndex(state, expectedBase); - } break; + break; + default: + cdie(0, "invalid findDelete"); + break; } if (findDelete != FindDeleteNONE) { @@ -528,9 +531,7 @@ static void test(FBMState state, unsigned n) { size = fbmRnd(ArraySize / 10) + 1; high = fbmRnd(2) ? TRUE : FALSE; switch(fbmRnd(6)) { - case 0: - case 1: - case 2: findDelete = FindDeleteNONE; break; + default: findDelete = FindDeleteNONE; break; case 3: findDelete = FindDeleteLOW; break; case 4: findDelete = FindDeleteHIGH; break; case 5: findDelete = FindDeleteENTIRE; break; diff --git a/mps/code/gc.gmk b/mps/code/gc.gmk index 608ced354b0..826cb0ef659 100644 --- a/mps/code/gc.gmk +++ b/mps/code/gc.gmk @@ -25,6 +25,7 @@ CFLAGSCOMPILER := \ -Wshadow \ -Wstrict-aliasing=2 \ -Wstrict-prototypes \ + -Wswitch-default \ -Wwrite-strings CFLAGSCOMPILERSTRICT := -ansi -pedantic diff --git a/mps/code/gcbench.c b/mps/code/gcbench.c index 214636649f1..61b6e925e94 100644 --- a/mps/code/gcbench.c +++ b/mps/code/gcbench.c @@ -331,8 +331,8 @@ int main(int argc, char *argv[]) { double mort = 0.0; cap = (size_t)strtoul(optarg, &p, 10); switch(toupper(*p)) { - case 'G': cap *= 1024; - case 'M': cap *= 1024; + case 'G': cap *= 1024; /* fall through */ + case 'M': cap *= 1024; /* fall through */ case 'K': p++; break; default: cap = 0; break; } @@ -356,6 +356,10 @@ int main(int argc, char *argv[]) { case 'G': arenasize *= 1024; case 'M': arenasize *= 1024; case 'K': arenasize *= 1024; break; + case '\0': break; + default: + fprintf(stderr, "Bad arena size %s\n", optarg); + return EXIT_FAILURE; } } break; diff --git a/mps/code/mpsicv.c b/mps/code/mpsicv.c index cba8a69f300..a4d8c3750b5 100644 --- a/mps/code/mpsicv.c +++ b/mps/code/mpsicv.c @@ -516,7 +516,8 @@ static void *test(void *arg, size_t s) if (rnd() % patternFREQ == 0) { switch(rnd() % 4) { - case 0: case 1: + case 0: /* fall through */ + case 1: die(mps_ap_alloc_pattern_begin(ap, ramp), "alloc_pattern_begin"); ++rampCount; break; @@ -528,7 +529,7 @@ static void *test(void *arg, size_t s) --rampCount; } break; - case 3: + default: die(mps_ap_alloc_pattern_reset(ap), "alloc_pattern_reset"); rampCount = 0; break; diff --git a/mps/code/prmci3li.c b/mps/code/prmci3li.c index 8d1b409e2dc..6a36ae7db2b 100644 --- a/mps/code/prmci3li.c +++ b/mps/code/prmci3li.c @@ -1,7 +1,7 @@ /* prmci3li.c: PROTECTION MUTATOR CONTEXT INTEL 386 (LINUX) * * $Id$ - * Copyright (c) 2001-2013 Ravenbrook Limited. See end of file for license. + * Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license. * * .purpose: This module implements the part of the protection module * that decodes the MutatorFaultContext. @@ -57,9 +57,10 @@ MRef Prmci3AddressHoldingReg(MutatorFaultContext mfc, unsigned int regnum) case 5: return (MRef)((char *)&mfc->ucontext->uc_mcontext.gregs[REG_EBP]); case 6: return (MRef)((char *)&mfc->ucontext->uc_mcontext.gregs[REG_ESI]); case 7: return (MRef)((char *)&mfc->ucontext->uc_mcontext.gregs[REG_EDI]); + default: + NOTREACHED; + return NULL; /* Avoids compiler warning. */ } - NOTREACHED; - return (MRef)NULL; /* Avoids compiler warning. */ } @@ -107,7 +108,7 @@ Res MutatorFaultContextScan(ScanState ss, MutatorFaultContext mfc) /* C. COPYRIGHT AND LICENSE * - * Copyright (C) 2001-2013 Ravenbrook Limited . + * Copyright (C) 2001-2014 Ravenbrook Limited . * All rights reserved. This is an open source license. Contact * Ravenbrook for commercial licensing options. * diff --git a/mps/code/prmci3w3.c b/mps/code/prmci3w3.c index f3d2e2386cc..4cf9584c988 100644 --- a/mps/code/prmci3w3.c +++ b/mps/code/prmci3w3.c @@ -1,7 +1,7 @@ /* prmci3w3.c: PROTECTION MUTATOR CONTEXT INTEL 386 (Win32) * * $Id$ - * Copyright (c) 2001-2013 Ravenbrook Limited. See end of file for license. + * Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license. * * PURPOSE * @@ -46,9 +46,10 @@ MRef Prmci3AddressHoldingReg(MutatorFaultContext context, unsigned int regnum) case 5: return (MRef)&wincont->Ebp; case 6: return (MRef)&wincont->Esi; case 7: return (MRef)&wincont->Edi; + default: + NOTREACHED; + return NULL; /* suppress warning */ } - NOTREACHED; - return NULL; /* suppress warning */ } @@ -80,7 +81,7 @@ void Prmci3StepOverIns(MutatorFaultContext context, Size inslen) /* C. COPYRIGHT AND LICENSE * - * Copyright (C) 2001-2013 Ravenbrook Limited . + * Copyright (C) 2001-2014 Ravenbrook Limited . * All rights reserved. This is an open source license. Contact * Ravenbrook for commercial licensing options. * diff --git a/mps/code/prmci3xc.c b/mps/code/prmci3xc.c index b08ee3a1c4c..786145fc084 100644 --- a/mps/code/prmci3xc.c +++ b/mps/code/prmci3xc.c @@ -1,7 +1,7 @@ /* prmci3xc.c: PROTECTION MUTATOR CONTEXT INTEL 386 (MAC OS X) * * $Id$ - * Copyright (c) 2001-2013 Ravenbrook Limited. See end of file for license. + * Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license. * * .purpose: This module implements the part of the protection module * that decodes the MutatorFaultContext. @@ -55,9 +55,10 @@ MRef Prmci3AddressHoldingReg(MutatorFaultContext mfc, unsigned int regnum) case 5: return (MRef)((char *)&mfc->threadState->__ebp); case 6: return (MRef)((char *)&mfc->threadState->__esi); case 7: return (MRef)((char *)&mfc->threadState->__edi); + default: + NOTREACHED; + return NULL; /* Avoids compiler warning. */ } - NOTREACHED; - return (MRef)NULL; /* Avoids compiler warning. */ } @@ -104,7 +105,7 @@ Res MutatorFaultContextScan(ScanState ss, MutatorFaultContext mfc) /* C. COPYRIGHT AND LICENSE * - * Copyright (C) 2001-2013 Ravenbrook Limited . + * Copyright (C) 2001-2014 Ravenbrook Limited . * All rights reserved. This is an open source license. Contact * Ravenbrook for commercial licensing options. * diff --git a/mps/code/prmci6li.c b/mps/code/prmci6li.c index 9c15fcdf6ff..2f8bf9afc62 100644 --- a/mps/code/prmci6li.c +++ b/mps/code/prmci6li.c @@ -1,7 +1,7 @@ /* prmci6li.c: PROTECTION MUTATOR CONTEXT x64 (LINUX) * * $Id$ - * Copyright (c) 2001-2013 Ravenbrook Limited. See end of file for license. + * Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license. * * .purpose: This module implements the part of the protection module * that decodes the MutatorFaultContext. @@ -61,9 +61,10 @@ MRef Prmci6AddressHoldingReg(MutatorFaultContext mfc, unsigned int regnum) case 13: return &gregs[REG_R13]; case 14: return &gregs[REG_R14]; case 15: return &gregs[REG_R15]; + default: + NOTREACHED; + return NULL; /* Avoids compiler warning. */ } - NOTREACHED; - return (MRef)NULL; /* Avoids compiler warning. */ } @@ -111,7 +112,7 @@ Res MutatorFaultContextScan(ScanState ss, MutatorFaultContext mfc) /* C. COPYRIGHT AND LICENSE * - * Copyright (C) 2001-2013 Ravenbrook Limited . + * Copyright (C) 2001-2014 Ravenbrook Limited . * All rights reserved. This is an open source license. Contact * Ravenbrook for commercial licensing options. * diff --git a/mps/code/prmci6w3.c b/mps/code/prmci6w3.c index 8faca025450..81641c00526 100644 --- a/mps/code/prmci6w3.c +++ b/mps/code/prmci6w3.c @@ -1,7 +1,7 @@ /* prmci6w3.c: PROTECTION MUTATOR CONTEXT INTEL 386 (Win32) * * $Id$ - * Copyright (c) 2001-2013 Ravenbrook Limited. See end of file for license. + * Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license. * * PURPOSE * @@ -52,9 +52,10 @@ MRef Prmci6AddressHoldingReg(MutatorFaultContext context, unsigned int regnum) case 13: return (MRef)&wincont->R13; case 14: return (MRef)&wincont->R14; case 15: return (MRef)&wincont->R15; + default: + NOTREACHED; + return NULL; /* suppress warning */ } - NOTREACHED; - return NULL; /* suppress warning */ } @@ -86,7 +87,7 @@ void Prmci6StepOverIns(MutatorFaultContext context, Size inslen) /* C. COPYRIGHT AND LICENSE * - * Copyright (C) 2001-2013 Ravenbrook Limited . + * Copyright (C) 2001-2014 Ravenbrook Limited . * All rights reserved. This is an open source license. Contact * Ravenbrook for commercial licensing options. * diff --git a/mps/code/prmci6xc.c b/mps/code/prmci6xc.c index f3d0413d1a6..02ccb840b6c 100644 --- a/mps/code/prmci6xc.c +++ b/mps/code/prmci6xc.c @@ -1,7 +1,7 @@ /* prmci6xc.c: PROTECTION MUTATOR CONTEXT x64 (MAC OS X) * * $Id$ - * Copyright (c) 2001-2013 Ravenbrook Limited. See end of file for license. + * Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license. * * .purpose: This module implements the part of the protection module * that decodes the MutatorFaultContext. @@ -58,9 +58,10 @@ MRef Prmci6AddressHoldingReg(MutatorFaultContext mfc, unsigned int regnum) case 13: return (MRef)((char *)&mfc->threadState->__r13); case 14: return (MRef)((char *)&mfc->threadState->__r14); case 15: return (MRef)((char *)&mfc->threadState->__r15); + default: + NOTREACHED; + return NULL; /* Avoids compiler warning. */ } - NOTREACHED; - return (MRef)NULL; /* Avoids compiler warning. */ } @@ -107,7 +108,7 @@ Res MutatorFaultContextScan(ScanState ss, MutatorFaultContext mfc) /* C. COPYRIGHT AND LICENSE * - * Copyright (C) 2001-2013 Ravenbrook Limited . + * Copyright (C) 2001-2014 Ravenbrook Limited . * All rights reserved. This is an open source license. Contact * Ravenbrook for commercial licensing options. * diff --git a/mps/code/sacss.c b/mps/code/sacss.c index 91f951524fc..ee86c83989d 100644 --- a/mps/code/sacss.c +++ b/mps/code/sacss.c @@ -94,26 +94,26 @@ static mps_res_t stress(mps_class_t class, /* upper half, as when allocating them again we want smaller objects */ /* see randomSize() */ switch (k % 2) { - case 0: { + case 0: for (i=testSetSIZE/2; i