Skip to content

Commit

Permalink
silence implicit fallthrough gcc warnings
Browse files Browse the repository at this point in the history
All changes in this patch tries to address implicit fallthrough warnings on the
newer gcc compiler.

Signed-off-by: Ani Sinha <[email protected]>
  • Loading branch information
ani-sinha committed Jun 4, 2022
1 parent 3c77f38 commit b323733
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3704,6 +3704,9 @@ _build_callargs(PyCFuncPtrObject *self, PyObject *argtypes,
*pinoutmask |= (1 << i); /* mark as inout arg */
(*pnumretvals)++;
/* fall through to PARAMFLAG_FIN... */
#if defined(__GNUC__) && __GNUC__ >= 7
__attribute__ ((fallthrough));
#endif
case 0:
case PARAMFLAG_FIN:
/* 'in' parameter. Copy it from inargs. */
Expand Down
4 changes: 4 additions & 0 deletions Modules/zlib/inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
#include "inflate.h"
#include "inffast.h"

#if defined(__GNUC__) && __GNUC__ >= 7
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#endif

#ifdef MAKEFIXED
# ifndef BUILDFIXED
# define BUILDFIXED
Expand Down
1 change: 1 addition & 0 deletions Objects/stringobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ string_dealloc(PyObject *op)

case SSTATE_INTERNED_IMMORTAL:
Py_FatalError("Immortal interned string died.");
// fall through

default:
Py_FatalError("Inconsistent interned string state.");
Expand Down
3 changes: 3 additions & 0 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,9 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
#endif
/* fall through... */
}
#if defined(__GNUC__) && __GNUC__ >= 7
__attribute__ ((fallthrough));
#endif
case '%':
n++;
break;
Expand Down
3 changes: 3 additions & 0 deletions Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ ast_for_comp_op(struct compiling *c, const node *n)
return In;
if (strcmp(STR(n), "is") == 0)
return Is;
break;
default:
PyErr_Format(PyExc_SystemError, "invalid comp_op: %s",
STR(n));
Expand All @@ -563,6 +564,7 @@ ast_for_comp_op(struct compiling *c, const node *n)
return NotIn;
if (strcmp(STR(CHILD(n, 0)), "is") == 0)
return IsNot;
break;
default:
PyErr_Format(PyExc_SystemError, "invalid comp_op: %s %s",
STR(CHILD(n, 0)), STR(CHILD(n, 1)));
Expand Down Expand Up @@ -2417,6 +2419,7 @@ ast_for_flow_stmt(struct compiling *c, const node *n)
return Raise(expr1, expr2, expr3, LINENO(n), n->n_col_offset,
c->c_arena);
}
break;
default:
PyErr_Format(PyExc_SystemError,
"unexpected flow_stmt: %d", TYPE(ch));
Expand Down
9 changes: 9 additions & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@

#include <ctype.h>

#if defined(__GNUC__) && __GNUC__ >= 7
#define fallthrough __attribute__((fallthrough));
#else
#define fallthrough ;
#endif

#ifndef WITH_TSC

#define READ_TIMESTAMP(var)
Expand Down Expand Up @@ -724,12 +730,14 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
#define TARGET_NOARG(op) \
TARGET_##op: \
opcode = op; \
fallthrough; \
case op:\

#define TARGET(op) \
TARGET_##op: \
opcode = op; \
oparg = NEXTARG(); \
fallthrough; \
case op:\


Expand Down Expand Up @@ -2057,6 +2065,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
/* Fallthrough */
case 1:
w = POP(); /* exc */
// fall through
case 0: /* Fallthrough */
why = do_raise(w, v, u);
break;
Expand Down
6 changes: 6 additions & 0 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3079,12 +3079,18 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
switch (e->v.Attribute.ctx) {
case AugLoad:
ADDOP(c, DUP_TOP);
#if defined(__GNUC__) && __GNUC__ >= 7
__attribute__ ((fallthrough));
#endif
/* Fall through to load */
case Load:
ADDOP_NAME(c, LOAD_ATTR, e->v.Attribute.attr, names);
break;
case AugStore:
ADDOP(c, ROT_TWO);
#if defined(__GNUC__) && __GNUC__ >= 7
__attribute__ ((fallthrough));
#endif
/* Fall through to save */
case Store:
ADDOP_NAME(c, STORE_ATTR, e->v.Attribute.attr, names);
Expand Down
12 changes: 12 additions & 0 deletions Python/dtoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,9 @@ _Py_dg_strtod(const char *s00, char **se)
switch (c) {
case '-':
sign = 1;
#if defined(__GNUC__) && __GNUC__ >= 7
__attribute__ ((fallthrough));
#endif
/* no break */
case '+':
c = *++s;
Expand Down Expand Up @@ -1596,6 +1599,9 @@ _Py_dg_strtod(const char *s00, char **se)
switch (c) {
case '-':
esign = 1;
#if defined(__GNUC__) && __GNUC__ >= 7
__attribute__ ((fallthrough));
#endif
/* no break */
case '+':
c = *++s;
Expand Down Expand Up @@ -2514,6 +2520,9 @@ _Py_dg_dtoa(double dd, int mode, int ndigits,
break;
case 2:
leftright = 0;
#if defined(__GNUC__) && __GNUC__ >= 7
__attribute__ ((fallthrough));
#endif
/* no break */
case 4:
if (ndigits <= 0)
Expand All @@ -2522,6 +2531,9 @@ _Py_dg_dtoa(double dd, int mode, int ndigits,
break;
case 3:
leftright = 0;
#if defined(__GNUC__) && __GNUC__ >= 7
__attribute__ ((fallthrough));
#endif
/* no break */
case 5:
i = ndigits + k + 1;
Expand Down
3 changes: 3 additions & 0 deletions Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,9 @@ skipitem(const char **p_format, va_list *p_va, int flags)
/* after 'e', only 's' and 't' is allowed */
goto err;
format++;
#if defined(__GNUC__) && __GNUC__ >= 7
__attribute__ ((fallthrough));
#endif
/* explicit fallthrough to string cases */
}

Expand Down

0 comments on commit b323733

Please sign in to comment.