From a382514b48c5bd1c137112e9ad72a2be311f9bb8 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Fri, 12 Aug 2011 10:19:37 +0200 Subject: [PATCH] implement -Wempty-body and -Wignored-qualifiers and ignore some more gcc warnings --- main.c | 21 ++++++++++++++++++--- parser.c | 12 +++++++++++- warning.c | 2 ++ warning.h | 2 ++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index b52afd8..2fd2f4c 100644 --- a/main.c +++ b/main.c @@ -635,7 +635,13 @@ static void print_help_warnings(void) put_help("-w", "Disable all warnings"); put_help("-Wno-trigraphs", "Warn if input contains trigraphs"); put_help("-Wundef", "Warn if an undefined macro is used in an #if"); + put_help("-Wmissing-include-dirs", "Warn about missing user-specified include directories"); + put_help("-Wendif-labels", "Warn about stray text after #elif and #endif"); put_help("-Winit-self", "Ignored (gcc compatibility)"); + put_help("-Wformat-y2k", "Ignored (gcc compatibility)"); + put_help("-Wformat-security", "Ignored (gcc compatibility)"); + put_help("-Wold-style-declaration", "Ignored (gcc compatibility)"); + put_help("-Wtype-limits", "Ignored (gcc compatibility)"); print_warning_opt_help(); } @@ -1254,7 +1260,9 @@ int main(int argc, char **argv) streq(opt, "align-loops") || streq(opt, "align-jumps") || streq(opt, "align-functions") || - streq(opt, "PIC")) { + streq(opt, "PIC") || + streq(opt, "stack-protector") || + streq(opt, "stack-protector-all")) { fprintf(stderr, "ignoring gcc option '-f%s'\n", orig_opt); } else { int res = firm_option(orig_opt); @@ -1295,10 +1303,17 @@ int main(int argc, char **argv) GET_ARG_AFTER(opt, "-Wl,"); add_flag(&ldflags_obst, "-Wl,%s", opt); } else if (streq(option + 1, "no-trigraphs") - || streq(option + 1, "undef")) { + || streq(option + 1, "undef") + || streq(option + 1, "missing-include-dirs") + || streq(option + 1, "endif-labels")) { add_flag(&cppflags_obst, "%s", arg); } else if (streq(option+1, "init-self")) { - /* ignored (gcc compatibility) */ + /* ignored (asme as gcc does) */ + } else if (streq(option+1, "format-y2k") + || streq(option+1, "format-security") + || streq(option+1, "old-style-declaration") + || streq(option+1, "type-limits")) { + /* ignore (gcc compatibility) */ } else { set_warning_opt(&option[1]); } diff --git a/parser.c b/parser.c index 6803e98..0cc4257 100644 --- a/parser.c +++ b/parser.c @@ -3649,7 +3649,7 @@ static type_t *construct_declarator_type(construct_type_t *construct_list, errorf(pos, "function returning array is not allowed"); } else { if (skipped_return_type->base.qualifiers != 0) { - warningf(WARN_OTHER, pos, "type qualifiers in return type of function type are meaningless"); + warningf(WARN_IGNORED_QUALIFIERS, pos, "type qualifiers in return type of function type are meaningless"); } } @@ -9273,8 +9273,18 @@ end_error: statement->ifs.true_statement = true_stmt; rem_anchor_token(T_else); + if (true_stmt->kind == STATEMENT_EMPTY) { + warningf(WARN_EMPTY_BODY, HERE, + "suggest braces around empty body in an ‘if’ statement"); + } + if (next_if(T_else)) { statement->ifs.false_statement = parse_inner_statement(); + + if (statement->ifs.false_statement->kind == STATEMENT_EMPTY) { + warningf(WARN_EMPTY_BODY, HERE, + "suggest braces around empty body in an ‘if’ statement"); + } } else if (true_stmt->kind == STATEMENT_IF && true_stmt->ifs.false_statement != NULL) { source_position_t const *const pos = &true_stmt->base.source_position; diff --git a/warning.c b/warning.c index 45b0025..5713d8c 100644 --- a/warning.c +++ b/warning.c @@ -36,11 +36,13 @@ static warning_switch_t warning[] = { [WARN_DECLARATION_AFTER_STATEMENT] = { WARN_STATE_NONE, "declaration-after-statement", }, [WARN_DEPRECATED_DECLARATIONS] = { WARN_STATE_ON, "deprecated-declarations", }, [WARN_DIV_BY_ZERO] = { WARN_STATE_ON, "div-by-zero", }, + [WARN_EMPTY_BODY] = { WARN_STATE_NONE, "empty-body", }, [WARN_EMPTY_STATEMENT] = { WARN_STATE_NONE, "empty-statement", }, [WARN_ERROR] = { WARN_STATE_NONE, "error" }, [WARN_FATAL_ERRORS] = { WARN_STATE_NONE, "fatal-errors" }, [WARN_FLOAT_EQUAL] = { WARN_STATE_NONE, "float-equal", }, [WARN_FORMAT] = { WARN_STATE_ON, "format" }, + [WARN_IGNORED_QUALIFIERS] = { WARN_STATE_ON, "ignored-qualifiers" }, [WARN_IMPLICIT_FUNCTION_DECLARATION] = { WARN_STATE_ON, "implicit-function-declaration" }, [WARN_IMPLICIT_INT] = { WARN_STATE_ON, "implicit-int" }, [WARN_LONG_LONG] = { WARN_STATE_NONE, "long-long" }, diff --git a/warning.h b/warning.h index 74bfd10..5aede20 100644 --- a/warning.h +++ b/warning.h @@ -46,6 +46,7 @@ typedef enum warning_t { WARN_DECLARATION_AFTER_STATEMENT, /**< Warn when a declaration is found after a statement in a block */ WARN_DEPRECATED_DECLARATIONS, /* TODO implement for types */ /**< Warn about uses of functions, variables and types marked as deprecated by using the 'deprecated' attribute */ WARN_DIV_BY_ZERO, /**< Warn about compile-time integer division by zero */ + WARN_EMPTY_BODY, /**< Warn about an empty body of an if or else statement */ WARN_EMPTY_STATEMENT, /**< Warn about empty statements, i.e. lone ';' */ #if 0 // TODO WARN_ENDIF_LABELS, /**< Warn whenever an '#else' or an '#endif' are followed by text */ @@ -54,6 +55,7 @@ typedef enum warning_t { WARN_FATAL_ERRORS, /**< First error stops the compilation */ WARN_FLOAT_EQUAL, /**< Warn if floating point values are used in equality comparisons */ WARN_FORMAT, /**< Check printf-style format strings */ + WARN_IGNORED_QUALIFIERS, /**< Warn when type qualifiers are meaningless */ WARN_IMPLICIT_FUNCTION_DECLARATION, /**< Warn whenever a function is used before being declared */ WARN_IMPLICIT_INT, /**< Warn when a declaration does not specify a type */ #if 0 // TODO -- 2.20.1