From 1f8269c0e256cbbea3a70e0e903a19f67cad734c Mon Sep 17 00:00:00 2001 From: Jack Culhane Date: Fri, 17 May 2019 17:00:48 +0100 Subject: [PATCH 1/3] Comment fallthrough case statements so compilation succeeds with GCC 7. GCC 7 Added a warning for implicit fallthroughs in switch cases. It's enabled by -Wextra, and treated as an error due to -Werror so compilation fails on GCC 7 and higher. See -Wimplicit-fallthrough in the GCC manual. --- codegen.c | 8 ++++++-- config.c | 10 ++++++++++ file.c | 1 + opcodes.c | 3 ++- qio.c | 1 + token.c | 1 + 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/codegen.c b/codegen.c index b78ecd8..dc20620 100644 --- a/codegen.c +++ b/codegen.c @@ -1021,7 +1021,7 @@ getstatement(LABEL *contlabel, LABEL *breaklabel, return; } reread(); - /* fall into default case */ + /* fall through */ default: rescantoken(); @@ -1384,6 +1384,7 @@ creatematrix(void) switch (gettoken()) { case T_RIGHTBRACKET: rescantoken(); + /* fall through */ case T_COMMA: addop(OP_ONE); addop(OP_SUB); @@ -1394,6 +1395,7 @@ creatematrix(void) switch(gettoken()) { case T_RIGHTBRACKET: rescantoken(); + /* fall through */ case T_COMMA: continue; } @@ -2211,6 +2213,7 @@ getterm(void) scanerror(T_NULL, "Function calls not allowed " "as expressions"); + /* fall through */ default: rescantoken(); return type; @@ -2248,7 +2251,7 @@ getidexpr(BOOL okmat, int autodef) if (autodef != T_GLOBAL && autodef != T_LOCAL && autodef != T_STATIC) autodef = 1; - /* fall into default case */ + /* fall through */ default: rescantoken(); usesymbol(name, autodef); @@ -2277,6 +2280,7 @@ getidexpr(BOOL okmat, int autodef) scanerror(T_NULL, "Function calls not allowed " "as expressions"); + /* fall through */ default: rescantoken(); return type; diff --git a/config.c b/config.c index 3ff0969..6642e2d 100644 --- a/config.c +++ b/config.c @@ -909,34 +909,42 @@ setconfig(int type, VALUE *vp) case CONFIG_PROGRAM: math_error("The program config parameter is read-only"); /*NOTREACHED*/ + abort(); case CONFIG_BASENAME: math_error("The basename config parameter is read-only"); /*NOTREACHED*/ + abort(); case CONFIG_WINDOWS: math_error("The windows config parameter is read-only"); /*NOTREACHED*/ + abort(); case CONFIG_CYGWIN: math_error("The cygwin config parameter is read-only"); /*NOTREACHED*/ + abort(); case CONFIG_COMPILE_CUSTOM: math_error("The custom config parameter is read-only"); /*NOTREACHED*/ + abort(); case CONFIG_ALLOW_CUSTOM: math_error("The allow_custom config parameter is read-only"); /*NOTREACHED*/ + abort(); case CONFIG_VERSION: math_error("The version config parameter is read-only"); /*NOTREACHED*/ + abort(); case CONFIG_BASEB: math_error("The baseb config parameter is read-only"); /*NOTREACHED*/ + abort(); case CONFIG_REDECL_WARN: if (vp->v_type == V_NUM) { @@ -971,10 +979,12 @@ setconfig(int type, VALUE *vp) case CONFIG_HZ: math_error("The clock tick rate config parameter is read-only"); /*NOTREACHED*/ + abort(); default: math_error("Setting illegal config parameter"); /*NOTREACHED*/ + abort(); } } diff --git a/file.c b/file.c index a3c2b1b..9d31cd4 100644 --- a/file.c +++ b/file.c @@ -1021,6 +1021,7 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals) switch (ch) { case 's': printstring = TRUE; + /* fall through */ case 'c': printchar = TRUE; case 'd': diff --git a/opcodes.c b/opcodes.c index 9fefad4..feefb62 100644 --- a/opcodes.c +++ b/opcodes.c @@ -4104,8 +4104,9 @@ freenumbers(FUNC *fp) case OP_QUIT: freestringconstant( (long)fp->f_opcodes[pc]); + break; } - /*FALLTHRU*/ + /* FALLTHRU */ case OPLOC: case OPPAR: case OPJMP: diff --git a/qio.c b/qio.c index ea1832e..46bd299 100644 --- a/qio.c +++ b/qio.c @@ -144,6 +144,7 @@ qprintf(char *fmt, ...) case '-': sign = -1; ch = *fmt++; + /* fall through */ default: if (('0' <= ch && ch <= '9') || ch == '.' || ch == '*') { diff --git a/token.c b/token.c index 3f0032f..e8f7af6 100644 --- a/token.c +++ b/token.c @@ -447,6 +447,7 @@ eatstring(int quotechar) case '\n': if (!newlines) break; + /* fall through */ case EOF: reread(); scanerror(T_NULL, From fa173cd9aa6b2b139aed3b02b25dae127c863d6a Mon Sep 17 00:00:00 2001 From: Jack Culhane Date: Fri, 17 May 2019 17:18:07 +0100 Subject: [PATCH 2/3] Fix spaces vs tabs and use FALLTHRU as it's used elsewhere --- codegen.c | 12 ++++++------ config.c | 20 ++++++++++---------- file.c | 2 +- opcodes.c | 2 +- qio.c | 2 +- token.c | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/codegen.c b/codegen.c index dc20620..d9da13f 100644 --- a/codegen.c +++ b/codegen.c @@ -1021,7 +1021,7 @@ getstatement(LABEL *contlabel, LABEL *breaklabel, return; } reread(); - /* fall through */ + /*FALLTHRU*/ default: rescantoken(); @@ -1384,7 +1384,7 @@ creatematrix(void) switch (gettoken()) { case T_RIGHTBRACKET: rescantoken(); - /* fall through */ + /*FALLTHRU*/ case T_COMMA: addop(OP_ONE); addop(OP_SUB); @@ -1395,7 +1395,7 @@ creatematrix(void) switch(gettoken()) { case T_RIGHTBRACKET: rescantoken(); - /* fall through */ + /*FALLTHRU*/ case T_COMMA: continue; } @@ -2213,7 +2213,7 @@ getterm(void) scanerror(T_NULL, "Function calls not allowed " "as expressions"); - /* fall through */ + /*FALLTHRU*/ default: rescantoken(); return type; @@ -2251,7 +2251,7 @@ getidexpr(BOOL okmat, int autodef) if (autodef != T_GLOBAL && autodef != T_LOCAL && autodef != T_STATIC) autodef = 1; - /* fall through */ + /*FALLTHRU*/ default: rescantoken(); usesymbol(name, autodef); @@ -2280,7 +2280,7 @@ getidexpr(BOOL okmat, int autodef) scanerror(T_NULL, "Function calls not allowed " "as expressions"); - /* fall through */ + /*FALLTHRU*/ default: rescantoken(); return type; diff --git a/config.c b/config.c index 6642e2d..1bf1975 100644 --- a/config.c +++ b/config.c @@ -909,42 +909,42 @@ setconfig(int type, VALUE *vp) case CONFIG_PROGRAM: math_error("The program config parameter is read-only"); /*NOTREACHED*/ - abort(); + abort(); case CONFIG_BASENAME: math_error("The basename config parameter is read-only"); /*NOTREACHED*/ - abort(); + abort(); case CONFIG_WINDOWS: math_error("The windows config parameter is read-only"); /*NOTREACHED*/ - abort(); + abort(); case CONFIG_CYGWIN: math_error("The cygwin config parameter is read-only"); /*NOTREACHED*/ - abort(); + abort(); case CONFIG_COMPILE_CUSTOM: math_error("The custom config parameter is read-only"); /*NOTREACHED*/ - abort(); + abort(); case CONFIG_ALLOW_CUSTOM: math_error("The allow_custom config parameter is read-only"); /*NOTREACHED*/ - abort(); + abort(); case CONFIG_VERSION: math_error("The version config parameter is read-only"); /*NOTREACHED*/ - abort(); + abort(); case CONFIG_BASEB: math_error("The baseb config parameter is read-only"); /*NOTREACHED*/ - abort(); + abort(); case CONFIG_REDECL_WARN: if (vp->v_type == V_NUM) { @@ -979,12 +979,12 @@ setconfig(int type, VALUE *vp) case CONFIG_HZ: math_error("The clock tick rate config parameter is read-only"); /*NOTREACHED*/ - abort(); + abort(); default: math_error("Setting illegal config parameter"); /*NOTREACHED*/ - abort(); + abort(); } } diff --git a/file.c b/file.c index 9d31cd4..1996f4b 100644 --- a/file.c +++ b/file.c @@ -1021,7 +1021,7 @@ idprintf(FILEID id, char *fmt, int count, VALUE **vals) switch (ch) { case 's': printstring = TRUE; - /* fall through */ + /*FALLTHRU*/ case 'c': printchar = TRUE; case 'd': diff --git a/opcodes.c b/opcodes.c index feefb62..e971333 100644 --- a/opcodes.c +++ b/opcodes.c @@ -4104,7 +4104,7 @@ freenumbers(FUNC *fp) case OP_QUIT: freestringconstant( (long)fp->f_opcodes[pc]); - break; + break; } /* FALLTHRU */ case OPLOC: diff --git a/qio.c b/qio.c index 46bd299..9541cd8 100644 --- a/qio.c +++ b/qio.c @@ -144,7 +144,7 @@ qprintf(char *fmt, ...) case '-': sign = -1; ch = *fmt++; - /* fall through */ + /*FALLTHRU*/ default: if (('0' <= ch && ch <= '9') || ch == '.' || ch == '*') { diff --git a/token.c b/token.c index e8f7af6..97472b7 100644 --- a/token.c +++ b/token.c @@ -447,7 +447,7 @@ eatstring(int quotechar) case '\n': if (!newlines) break; - /* fall through */ + /*FALLTHRU*/ case EOF: reread(); scanerror(T_NULL, From af59b9dab2ae3de8cb3e30e821cc6a6851b4bd4d Mon Sep 17 00:00:00 2001 From: Jack Culhane Date: Fri, 17 May 2019 17:31:02 +0100 Subject: [PATCH 3/3] One FALLTHRU comment was inconsistent with others --- opcodes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opcodes.c b/opcodes.c index e971333..adce0d1 100644 --- a/opcodes.c +++ b/opcodes.c @@ -4106,7 +4106,7 @@ freenumbers(FUNC *fp) (long)fp->f_opcodes[pc]); break; } - /* FALLTHRU */ + /*FALLTHRU*/ case OPLOC: case OPPAR: case OPJMP: