From 9a78221b8d5ba5b146f65bdd50f611fa93aa82c9 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 15 Jan 2020 10:07:46 +0000 Subject: A few more "break" statements, so any compiler knows these are no FALLTHROUGH situations. --- generic/tclCompCmdsSZ.c | 1 + generic/tclExecute.c | 76 ++++++++++++++++++++++++++++++++++++++----------- generic/tclInterp.c | 2 ++ generic/tclStrToD.c | 1 + 4 files changed, 63 insertions(+), 17 deletions(-) diff --git a/generic/tclCompCmdsSZ.c b/generic/tclCompCmdsSZ.c index 1d59cc6..1ce4582 100644 --- a/generic/tclCompCmdsSZ.c +++ b/generic/tclCompCmdsSZ.c @@ -637,6 +637,7 @@ TclCompileStringIsCmd( OP( LNOT); return TCL_OK; } + break; case STR_IS_DOUBLE: { int satisfied, isEmpty; diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 3c2816c..171515d 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -317,12 +317,16 @@ VarHashCreateVar( switch (*pc) { \ case INST_JUMP_FALSE1: \ NEXT_INST_F(((condition)? 2 : TclGetInt1AtPtr(pc+1)), (cleanup), 0); \ + break; \ case INST_JUMP_TRUE1: \ NEXT_INST_F(((condition)? TclGetInt1AtPtr(pc+1) : 2), (cleanup), 0); \ + break; \ case INST_JUMP_FALSE4: \ NEXT_INST_F(((condition)? 5 : TclGetInt4AtPtr(pc+1)), (cleanup), 0); \ + break; \ case INST_JUMP_TRUE4: \ NEXT_INST_F(((condition)? TclGetInt4AtPtr(pc+1) : 5), (cleanup), 0); \ + break; \ default: \ if ((condition) < 0) { \ TclNewIntObj(objResultPtr, -1); \ @@ -330,6 +334,7 @@ VarHashCreateVar( objResultPtr = TCONST((condition) > 0); \ } \ NEXT_INST_F(0, (cleanup), 1); \ + break; \ } \ } while (0) #define JUMP_PEEPHOLE_V(condition, pcAdjustment, cleanup) \ @@ -338,12 +343,16 @@ VarHashCreateVar( switch (*pc) { \ case INST_JUMP_FALSE1: \ NEXT_INST_V(((condition)? 2 : TclGetInt1AtPtr(pc+1)), (cleanup), 0); \ + break; \ case INST_JUMP_TRUE1: \ NEXT_INST_V(((condition)? TclGetInt1AtPtr(pc+1) : 2), (cleanup), 0); \ + break; \ case INST_JUMP_FALSE4: \ NEXT_INST_V(((condition)? 5 : TclGetInt4AtPtr(pc+1)), (cleanup), 0); \ + break; \ case INST_JUMP_TRUE4: \ NEXT_INST_V(((condition)? TclGetInt4AtPtr(pc+1) : 5), (cleanup), 0); \ + break; \ default: \ if ((condition) < 0) { \ TclNewIntObj(objResultPtr, -1); \ @@ -351,6 +360,7 @@ VarHashCreateVar( objResultPtr = TCONST((condition) > 0); \ } \ NEXT_INST_V(0, (cleanup), 1); \ + break; \ } \ } while (0) #else /* TCL_COMPILE_DEBUG */ @@ -2604,7 +2614,7 @@ TEBCresume( #ifdef TCL_COMPILE_DEBUG /* FIXME: What is the right thing to trace? */ { - register int i; + int i; TRACE(("%d [", opnd)); for (i=opnd-1 ; i>=0 ; i--) { @@ -2669,23 +2679,27 @@ TEBCresume( objResultPtr = codePtr->objArrayPtr[TclGetUInt4AtPtr(pc+1)]; TRACE_WITH_OBJ(("%u => ", TclGetUInt4AtPtr(pc+1)), objResultPtr); NEXT_INST_F(5, 0, 1); + break; case INST_POP: TRACE_WITH_OBJ(("=> discarding "), OBJ_AT_TOS); objPtr = POP_OBJECT(); TclDecrRefCount(objPtr); NEXT_INST_F(1, 0, 0); + break; case INST_DUP: objResultPtr = OBJ_AT_TOS; TRACE_WITH_OBJ(("=> "), objResultPtr); NEXT_INST_F(1, 0, 1); + break; case INST_OVER: opnd = TclGetUInt4AtPtr(pc+1); objResultPtr = OBJ_AT_DEPTH(opnd); TRACE_WITH_OBJ(("%u => ", opnd), objResultPtr); NEXT_INST_F(5, 0, 1); + break; case INST_REVERSE: { Tcl_Obj **a, **b; @@ -2702,6 +2716,7 @@ TEBCresume( TRACE(("%u => OK\n", opnd)); NEXT_INST_F(5, 0, 0); } + break; case INST_STR_CONCAT1: { int appendLen = 0; @@ -2883,6 +2898,7 @@ TEBCresume( PUSH_TAUX_OBJ(objPtr); TRACE(("=> mark depth as %d\n", (int) CURR_DEPTH)); NEXT_INST_F(1, 0, 0); + break; case INST_EXPAND_DROP: /* @@ -2961,6 +2977,7 @@ TEBCresume( Tcl_DecrRefCount(objPtr); NEXT_INST_F(5, 0, 0); } + break; case INST_EXPR_STK: { ByteCode *newCodePtr; @@ -3008,6 +3025,7 @@ TEBCresume( TclNewObj(objResultPtr); NEXT_INST_F(1, 0, 1); + break; case INST_INVOKE_STK4: objc = TclGetUInt4AtPtr(pc+1); @@ -4296,6 +4314,7 @@ TEBCresume( } NEXT_INST_F(5, 0, 0); } + break; /* * End of INST_UNSET instructions. @@ -4516,6 +4535,7 @@ TEBCresume( TRACE_APPEND(("link made\n")); NEXT_INST_F(5, 1, 0); } + break; /* * End of variable linking instructions. @@ -4527,6 +4547,7 @@ TEBCresume( TRACE(("%d => new pc %u\n", opnd, (unsigned)(pc + opnd - codePtr->codeStart))); NEXT_INST_F(opnd, 0, 0); + break; case INST_JUMP4: opnd = TclGetInt4AtPtr(pc+1); @@ -4589,6 +4610,7 @@ TEBCresume( #endif NEXT_INST_F(jmpOffset[b], 1, 0); } + break; case INST_JUMP_TABLE: { Tcl_HashEntry *hPtr; @@ -4614,6 +4636,7 @@ TEBCresume( NEXT_INST_F(5, 1, 0); } } + break; /* * These two instructions are now redundant: the complete logic of the LOR @@ -4658,6 +4681,7 @@ TEBCresume( TRACE(("%.20s %.20s => %d\n", O2S(valuePtr),O2S(value2Ptr),iResult)); NEXT_INST_F(1, 2, 1); } + break; /* * ----------------------------------------------------------------- @@ -4676,6 +4700,7 @@ TEBCresume( TRACE_WITH_OBJ(("=> "), objResultPtr); NEXT_INST_F(1, 0, 1); } + break; case INST_COROUTINE_NAME: { CoroutineData *corPtr = iPtr->execEnvPtr->corPtr; @@ -4687,14 +4712,16 @@ TEBCresume( TRACE_WITH_OBJ(("=> "), objResultPtr); NEXT_INST_F(1, 0, 1); } + break; case INST_INFO_LEVEL_NUM: TclNewIntObj(objResultPtr, iPtr->varFramePtr->level); TRACE_WITH_OBJ(("=> "), objResultPtr); NEXT_INST_F(1, 0, 1); + break; case INST_INFO_LEVEL_ARGS: { int level; - register CallFrame *framePtr = iPtr->varFramePtr; - register CallFrame *rootFramePtr = iPtr->rootFramePtr; + CallFrame *framePtr = iPtr->varFramePtr; + CallFrame *rootFramePtr = iPtr->rootFramePtr; TRACE(("\"%.30s\" => ", O2S(OBJ_AT_TOS))); if (TclGetIntFromObj(interp, OBJ_AT_TOS, &level) != TCL_OK) { @@ -4991,7 +5018,7 @@ TEBCresume( } { - register Method *const mPtr = + Method *const mPtr = contextPtr->callPtr->chain[newDepth].mPtr; return mPtr->typePtr->callProc(mPtr->clientData, interp, @@ -6248,6 +6275,7 @@ TEBCresume( lResult = l1 - l2*lResult; goto longResultOfArithmetic; } + break; case INST_RSHIFT: if (l2 < 0) { @@ -6296,6 +6324,7 @@ TEBCresume( lResult = l1 >> ((int) l2); goto longResultOfArithmetic; } + break; case INST_LSHIFT: if (l2 < 0) { @@ -6504,6 +6533,7 @@ TEBCresume( Tcl_SetWideIntObj(valuePtr, wResult); TRACE(("%s\n", O2S(valuePtr))); NEXT_INST_F(1, 1, 0); + break; case INST_DIV: if (l2 == 0) { @@ -6643,6 +6673,7 @@ TEBCresume( /* -NaN => NaN */ TRACE_APPEND(("%s\n", O2S(valuePtr))); NEXT_INST_F(1, 0, 0); + break; case TCL_NUMBER_LONG: l1 = *((const long *) ptr1); if (l1 != LONG_MIN) { @@ -6751,6 +6782,7 @@ TEBCresume( TRACE_APPEND(("numeric, same Tcl_Obj\n")); NEXT_INST_F(1, 0, 0); } + break; /* * End of numeric operator instructions. @@ -6767,6 +6799,7 @@ TEBCresume( } TRACE_WITH_OBJ(("\"%.30s\" => ", O2S(valuePtr)), objResultPtr); NEXT_INST_F(1, 0, 1); + break; case INST_BREAK: /* @@ -7146,6 +7179,7 @@ TEBCresume( Tcl_ListObjAppendElement(NULL, objPtr, OBJ_AT_TOS); NEXT_INST_F(1, 1, 0); } + break; case INST_BEGIN_CATCH4: /* @@ -7159,6 +7193,7 @@ TEBCresume( TclGetUInt4AtPtr(pc+1), (int) (catchTop - initCatchTop - 1), (int) CURR_DEPTH)); NEXT_INST_F(5, 0, 0); + break; case INST_END_CATCH: catchTop--; @@ -7168,6 +7203,7 @@ TEBCresume( result = TCL_OK; TRACE(("=> catchTop=%d\n", (int) (catchTop - initCatchTop - 1))); NEXT_INST_F(1, 0, 0); + break; case INST_PUSH_RESULT: objResultPtr = Tcl_GetObjResult(interp); @@ -7181,11 +7217,13 @@ TEBCresume( Tcl_IncrRefCount(objPtr); iPtr->objResultPtr = objPtr; NEXT_INST_F(1, 0, -1); + break; case INST_PUSH_RETURN_CODE: TclNewIntObj(objResultPtr, result); TRACE(("=> %u\n", result)); NEXT_INST_F(1, 0, 1); + break; case INST_PUSH_RETURN_OPTIONS: DECACHE_STACK_INFO(); @@ -7193,6 +7231,7 @@ TEBCresume( CACHE_STACK_INFO(); TRACE_WITH_OBJ(("=> "), objResultPtr); NEXT_INST_F(1, 0, 1); + break; case INST_RETURN_CODE_BRANCH: { int code; @@ -7816,6 +7855,7 @@ TEBCresume( TRACE_APPEND(("OK\n")); NEXT_INST_F(5, 2, 0); } + break; /* * End of dictionary-related instructions. @@ -7849,11 +7889,11 @@ TEBCresume( default: Tcl_Panic("clockRead instruction with unknown clock#"); } - /* TclNewWideObj(objResultPtr, wval); doesn't exist */ objResultPtr = Tcl_NewWideIntObj(wval); TRACE_WITH_OBJ(("=> "), objResultPtr); NEXT_INST_F(2, 0, 1); } + break; default: Tcl_Panic("TclNRExecuteByteCode: unrecognized opCode %u", *pc); @@ -8521,7 +8561,7 @@ ExecuteExtendedBinaryMathOp( mp_init(&bigResult); mp_init(&bigRemainder); mp_div(&big1, &big2, &bigResult, &bigRemainder); - if ((bigRemainder.used) != 0 && (bigRemainder.sign != big2.sign)) { + if (!mp_iszero(&bigRemainder) && (bigRemainder.sign != big2.sign)) { /* * Convert to Tcl's integer division rules. */ @@ -8852,7 +8892,6 @@ ExecuteExtendedBinaryMathOp( type1 = TCL_NUMBER_LONG; goto pwrLongBase; } - break; #endif } if (negativeExponent) { @@ -8861,7 +8900,6 @@ ExecuteExtendedBinaryMathOp( * Integers with magnitude greater than 1 raise to a negative * power yield the answer zero (see TIP 123). */ - return constants[0]; } @@ -9245,7 +9283,7 @@ ExecuteExtendedUnaryMathOp( #endif Tcl_TakeBignumFromObj(NULL, valuePtr, &big); /* ~a = - a - 1 */ - mp_neg(&big, &big); + (void)mp_neg(&big, &big); mp_sub_d(&big, 1, &big); BIG_RESULT(&big); case INST_UMINUS: @@ -9271,7 +9309,7 @@ ExecuteExtendedUnaryMathOp( default: Tcl_TakeBignumFromObj(NULL, valuePtr, &big); } - mp_neg(&big, &big); + (void)mp_neg(&big, &big); BIG_RESULT(&big); } @@ -9377,6 +9415,7 @@ TclCompareTwoNumbers( mp_clear(&big2); return compare; } + break; #ifndef TCL_WIDE_INT_IS_LONG case TCL_NUMBER_WIDE: @@ -9407,7 +9446,7 @@ TclCompareTwoNumbers( goto wideCompare; case TCL_NUMBER_BIG: Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2); - if (mp_cmp_d(&big2, 0) == MP_LT) { + if (mp_isneg(&big2)) { compare = MP_GT; } else { compare = MP_LT; @@ -9415,6 +9454,7 @@ TclCompareTwoNumbers( mp_clear(&big2); return compare; } + break; #endif case TCL_NUMBER_DOUBLE: @@ -9462,7 +9502,7 @@ TclCompareTwoNumbers( } Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2); if ((d1 < (double)LONG_MAX) && (d1 > (double)LONG_MIN)) { - if (mp_cmp_d(&big2, 0) == MP_LT) { + if (mp_isneg(&big2)) { compare = MP_GT; } else { compare = MP_LT; @@ -9479,6 +9519,7 @@ TclCompareTwoNumbers( Tcl_InitBignumFromDouble(NULL, d1, &big1); goto bigCompare; } + break; case TCL_NUMBER_BIG: Tcl_TakeBignumFromObj(NULL, valuePtr, &big1); @@ -9518,10 +9559,11 @@ TclCompareTwoNumbers( mp_clear(&big2); return compare; } + break; default: Tcl_Panic("unexpected number type"); - return TCL_ERROR; } + return TCL_ERROR; } #ifdef TCL_COMPILE_DEBUG @@ -9690,12 +9732,12 @@ IllegalExprOperandType( ClientData ptr; int type; const unsigned char opcode = *pc; - const char *description, *operator = "unknown"; + const char *description, *op = "unknown"; if (opcode == INST_EXPON) { - operator = "**"; + op = "**"; } else if (opcode <= INST_LNOT) { - operator = operatorStrings[opcode - INST_LOR]; + op = operatorStrings[opcode - INST_LOR]; } if (GetNumberFromObj(NULL, opndPtr, &ptr, &type) != TCL_OK) { @@ -9719,7 +9761,7 @@ IllegalExprOperandType( } Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "can't use %s as operand of \"%s\"", description, operator)); + "can't use %s as operand of \"%s\"", description, op)); Tcl_SetErrorCode(interp, "ARITH", "DOMAIN", description, NULL); } diff --git a/generic/tclInterp.c b/generic/tclInterp.c index 8a0d653..ac66324 100644 --- a/generic/tclInterp.c +++ b/generic/tclInterp.c @@ -987,6 +987,7 @@ NRInterpCmd( return SlaveTimeLimitCmd(interp, slaveInterp, 4, objc, objv); } } + break; case OPT_MARKTRUSTED: if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "path"); @@ -2621,6 +2622,7 @@ NRSlaveCmd( return SlaveTimeLimitCmd(interp, slaveInterp, 3, objc, objv); } } + break; case OPT_MARKTRUSTED: if (objc != 2) { Tcl_WrongNumArgs(interp, 2, objv, NULL); diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c index b9026cd..16eca19 100644 --- a/generic/tclStrToD.c +++ b/generic/tclStrToD.c @@ -841,6 +841,7 @@ TclParseNumber( acceptState = state; acceptPoint = p; acceptLen = len; + /* FALLTHRU */ case ZERO_B: zerob: if (c == '0') { -- cgit v0.12