Skip to content

Commit 23a8ac5

Browse files
committed
silence implicit fallthrough gcc warnings
All changes in this patch tries to address implicit fallthrough warnings on the newer gcc compiler. Signed-off-by: Ani Sinha <[email protected]>
1 parent 3c77f38 commit 23a8ac5

File tree

9 files changed

+46
-0
lines changed

9 files changed

+46
-0
lines changed

Modules/_ctypes/_ctypes.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3704,6 +3704,9 @@ _build_callargs(PyCFuncPtrObject *self, PyObject *argtypes,
37043704
*pinoutmask |= (1 << i); /* mark as inout arg */
37053705
(*pnumretvals)++;
37063706
/* fall through to PARAMFLAG_FIN... */
3707+
#if defined(__GNUC__) && __GNUC__ >= 7
3708+
__attribute__ ((fallthrough));
3709+
#endif
37073710
case 0:
37083711
case PARAMFLAG_FIN:
37093712
/* 'in' parameter. Copy it from inargs. */

Modules/zlib/inflate.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
#include "inflate.h"
8686
#include "inffast.h"
8787

88+
#if defined(__GNUC__) && __GNUC__ >= 7
89+
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
90+
#endif
91+
8892
#ifdef MAKEFIXED
8993
# ifndef BUILDFIXED
9094
# define BUILDFIXED

Objects/stringobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ string_dealloc(PyObject *op)
590590

591591
case SSTATE_INTERNED_IMMORTAL:
592592
Py_FatalError("Immortal interned string died.");
593+
// fall through
593594

594595
default:
595596
Py_FatalError("Inconsistent interned string state.");

Objects/unicodeobject.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,9 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
796796
#endif
797797
/* fall through... */
798798
}
799+
#if defined(__GNUC__) && __GNUC__ >= 7
800+
__attribute__ ((fallthrough));
801+
#endif
799802
case '%':
800803
n++;
801804
break;

Python/ast.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ ast_for_comp_op(struct compiling *c, const node *n)
549549
return In;
550550
if (strcmp(STR(n), "is") == 0)
551551
return Is;
552+
break;
552553
default:
553554
PyErr_Format(PyExc_SystemError, "invalid comp_op: %s",
554555
STR(n));
@@ -563,6 +564,7 @@ ast_for_comp_op(struct compiling *c, const node *n)
563564
return NotIn;
564565
if (strcmp(STR(CHILD(n, 0)), "is") == 0)
565566
return IsNot;
567+
break;
566568
default:
567569
PyErr_Format(PyExc_SystemError, "invalid comp_op: %s %s",
568570
STR(CHILD(n, 0)), STR(CHILD(n, 1)));
@@ -2417,6 +2419,7 @@ ast_for_flow_stmt(struct compiling *c, const node *n)
24172419
return Raise(expr1, expr2, expr3, LINENO(n), n->n_col_offset,
24182420
c->c_arena);
24192421
}
2422+
break;
24202423
default:
24212424
PyErr_Format(PyExc_SystemError,
24222425
"unexpected flow_stmt: %d", TYPE(ch));

Python/ceval.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919

2020
#include <ctype.h>
2121

22+
#if defined(__GNUC__) && __GNUC__ >= 7
23+
#define fallthrough __attribute__((fallthrough));
24+
#else
25+
#define fallthrough ;
26+
#endif
27+
2228
#ifndef WITH_TSC
2329

2430
#define READ_TIMESTAMP(var)
@@ -724,12 +730,14 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
724730
#define TARGET_NOARG(op) \
725731
TARGET_##op: \
726732
opcode = op; \
733+
fallthrough; \
727734
case op:\
728735

729736
#define TARGET(op) \
730737
TARGET_##op: \
731738
opcode = op; \
732739
oparg = NEXTARG(); \
740+
fallthrough; \
733741
case op:\
734742

735743

@@ -2057,6 +2065,9 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
20572065
/* Fallthrough */
20582066
case 1:
20592067
w = POP(); /* exc */
2068+
#if defined(__GNUC__) && __GNUC__ >= 7
2069+
__attribute__ ((fallthrough));
2070+
#endif
20602071
case 0: /* Fallthrough */
20612072
why = do_raise(w, v, u);
20622073
break;

Python/compile.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,12 +3079,18 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
30793079
switch (e->v.Attribute.ctx) {
30803080
case AugLoad:
30813081
ADDOP(c, DUP_TOP);
3082+
#if defined(__GNUC__) && __GNUC__ >= 7
3083+
__attribute__ ((fallthrough));
3084+
#endif
30823085
/* Fall through to load */
30833086
case Load:
30843087
ADDOP_NAME(c, LOAD_ATTR, e->v.Attribute.attr, names);
30853088
break;
30863089
case AugStore:
30873090
ADDOP(c, ROT_TWO);
3091+
#if defined(__GNUC__) && __GNUC__ >= 7
3092+
__attribute__ ((fallthrough));
3093+
#endif
30883094
/* Fall through to save */
30893095
case Store:
30903096
ADDOP_NAME(c, STORE_ATTR, e->v.Attribute.attr, names);

Python/dtoa.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,9 @@ _Py_dg_strtod(const char *s00, char **se)
15271527
switch (c) {
15281528
case '-':
15291529
sign = 1;
1530+
#if defined(__GNUC__) && __GNUC__ >= 7
1531+
__attribute__ ((fallthrough));
1532+
#endif
15301533
/* no break */
15311534
case '+':
15321535
c = *++s;
@@ -1596,6 +1599,9 @@ _Py_dg_strtod(const char *s00, char **se)
15961599
switch (c) {
15971600
case '-':
15981601
esign = 1;
1602+
#if defined(__GNUC__) && __GNUC__ >= 7
1603+
__attribute__ ((fallthrough));
1604+
#endif
15991605
/* no break */
16001606
case '+':
16011607
c = *++s;
@@ -2514,6 +2520,9 @@ _Py_dg_dtoa(double dd, int mode, int ndigits,
25142520
break;
25152521
case 2:
25162522
leftright = 0;
2523+
#if defined(__GNUC__) && __GNUC__ >= 7
2524+
__attribute__ ((fallthrough));
2525+
#endif
25172526
/* no break */
25182527
case 4:
25192528
if (ndigits <= 0)
@@ -2522,6 +2531,9 @@ _Py_dg_dtoa(double dd, int mode, int ndigits,
25222531
break;
25232532
case 3:
25242533
leftright = 0;
2534+
#if defined(__GNUC__) && __GNUC__ >= 7
2535+
__attribute__ ((fallthrough));
2536+
#endif
25252537
/* no break */
25262538
case 5:
25272539
i = ndigits + k + 1;

Python/getargs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,9 @@ skipitem(const char **p_format, va_list *p_va, int flags)
17361736
/* after 'e', only 's' and 't' is allowed */
17371737
goto err;
17381738
format++;
1739+
#if defined(__GNUC__) && __GNUC__ >= 7
1740+
__attribute__ ((fallthrough));
1741+
#endif
17391742
/* explicit fallthrough to string cases */
17401743
}
17411744

0 commit comments

Comments
 (0)