- implemented -Wsign-compare
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sat, 15 Dec 2007 18:56:02 +0000 (18:56 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sat, 15 Dec 2007 18:56:02 +0000 (18:56 +0000)
- recognize -Wshadow (semantic not implemented yet)

[r18772]

parser.c
warning.c
warning.h

index 7048168..28db0fe 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -4378,6 +4378,13 @@ static void semantic_comparison(binary_expression_t *expression)
 
        /* TODO non-arithmetic types */
        if(is_type_arithmetic(type_left) && is_type_arithmetic(type_right)) {
+               if (warning.sign_compare &&
+                   (expression->expression.kind != EXPR_BINARY_EQUAL &&
+                    expression->expression.kind != EXPR_BINARY_NOTEQUAL) &&
+                   (is_type_signed(type_left) != is_type_signed(type_right))) {
+                       warningf(expression->expression.source_position,
+                               "comparison between signed and unsigned");
+               }
                type_t *arithmetic_type = semantic_arithmetic(type_left, type_right);
                expression->left  = create_implicit_cast(left, arithmetic_type);
                expression->right = create_implicit_cast(right, arithmetic_type);
index 58d6730..345b62a 100644 (file)
--- a/warning.c
+++ b/warning.c
@@ -15,6 +15,8 @@ warning_t warning = {
        .missing_prototypes            = false,
        .redundant_decls               = true,
        .s_are_errors                  = false,
+       .shadow                        = false,
+       .sign_compare                  = false,
        .strict_prototypes             = true,
        .switch_default                = false,
        .unknown_pragmas               = true,
@@ -42,6 +44,7 @@ void set_warning_opt(const char *const opt)
 #define SET(y)    warning.y = state;
 #define OPT(x, y) OPTX(x) SET(y)
        OPTX("all") {
+               /* Note: this switched on a lot of more warnings than gcc's -Wall */
                SET(char_subscripts)
                SET(check_format)
                SET(empty_statement)
@@ -49,6 +52,8 @@ void set_warning_opt(const char *const opt)
                SET(implicit_int)
                SET(main)
                SET(redundant_decls)
+               SET(shadow)
+               SET(sign_compare)
                SET(strict_prototypes)
                SET(switch_default)
                SET(unknown_pragmas)
@@ -84,6 +89,8 @@ void set_warning_opt(const char *const opt)
        OPT("missing-declarations",          missing_declarations)
        OPT("missing-prototypes",            missing_prototypes)
        OPT("redundant-decls",               redundant_decls)
+       OPT("shadow",                        shadow)
+       OPT("sign-compare",                  sign_compare)
        OPT("strict-prototypes",             strict_prototypes)
        OPT("switch-default",                switch_default)
        OPT("unknown-pragmas",               unknown_pragmas)
index d45c460..71d9a88 100644 (file)
--- a/warning.h
+++ b/warning.h
@@ -57,8 +57,10 @@ typedef struct warning_t {
        bool s_are_errors:1;                  /**< Treat warnings as errors */
 #if 0 // TODO
        bool sequence_point:1;                /**< Warn about code that may have undefined semantics because of violations of sequence point rules */
+#endif
        bool shadow:1;                        /**< Warn whenever a local variable shadows another local variable, parameter or global variable or whenever a built-in function is shadowed */
        bool sign_compare:1;                  /**< Warn when a comparison between signed and unsigned values could produce an incorrect result when the signed value is converted to unsigned */
+#if 0 // TODO
        bool strict_aliasing:1;               /**< Warn about code which might break the strict aliasing rules that the compiler is using for optimization. */
 #endif
        bool strict_prototypes:1;             /**< Warn if a function declaration has an unspecified parameter list */