diff options
author | Thomas Graf <tgraf@suug.ch> | 2014-09-25 10:11:17 +0200 |
---|---|---|
committer | Christopher Li <sparse@chrisli.org> | 2014-09-28 08:58:55 +0800 |
commit | 4d8811879a1cc48c1cdd0b0466dc6865c715d149 (patch) | |
tree | 641f812c23f7cc7838d898c5c02db449679b63af | |
parent | a5bdeee9e145cc4313526f9722f80674321ab491 (diff) | |
download | sparse-4d8811879a1cc48c1cdd0b0466dc6865c715d149.tar.gz |
sparse: Make -Werror turn warnigns into errors
Make sparse fail and return an error code if a warning is encountered
and -Werror is specified or a hard error is found. This allows to use
sparse in automated build systems to more easily catch new sparse
warnings.
The validation script is extended to parse the expected output message
for an error message and validate the a non zero return value if such
a error message is found.
Also changes cgcc to die if the checker fails.
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: Christopher Li <sparse@chrisli.org>
-rwxr-xr-x | cgcc | 2 | ||||
-rw-r--r-- | lib.c | 49 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | sparse.1 | 3 | ||||
-rw-r--r-- | sparse.c | 3 | ||||
-rwxr-xr-x | validation/test-suite | 18 |
6 files changed, 49 insertions, 27 deletions
@@ -70,7 +70,7 @@ if ($do_check) { print "$check\n" if $verbose; if ($do_compile) { - system ($check); + system ($check) == 0 or die; } else { exec ($check); } @@ -126,25 +126,6 @@ void info(struct position pos, const char * fmt, ...) va_end(args); } -void warning(struct position pos, const char * fmt, ...) -{ - va_list args; - - if (!max_warnings) { - show_info = 0; - return; - } - - if (!--max_warnings) { - show_info = 0; - fmt = "too many warnings"; - } - - va_start(args, fmt); - do_warn("warning: ", pos, fmt, args); - va_end(args); -} - static void do_error(struct position pos, const char * fmt, va_list args) { static int errors = 0; @@ -165,6 +146,32 @@ static void do_error(struct position pos, const char * fmt, va_list args) errors++; } +void warning(struct position pos, const char * fmt, ...) +{ + va_list args; + + if (Werror) { + va_start(args, fmt); + do_error(pos, fmt, args); + va_end(args); + return; + } + + if (!max_warnings) { + show_info = 0; + return; + } + + if (!--max_warnings) { + show_info = 0; + fmt = "too many warnings"; + } + + va_start(args, fmt); + do_warn("warning: ", pos, fmt, args); + va_end(args); +} + void sparse_error(struct position pos, const char * fmt, ...) { va_list args; @@ -219,6 +226,7 @@ int Wdesignated_init = 1; int Wdo_while = 0; int Winit_cstring = 0; int Wenum_mismatch = 1; +int Werror = 0; int Wnon_pointer_null = 1; int Wold_initializer = 1; int Wone_bit_signed_bitfield = 1; @@ -431,6 +439,7 @@ static const struct warning { { "designated-init", &Wdesignated_init }, { "do-while", &Wdo_while }, { "enum-mismatch", &Wenum_mismatch }, + { "error", &Werror }, { "init-cstring", &Winit_cstring }, { "non-pointer-null", &Wnon_pointer_null }, { "old-initializer", &Wold_initializer }, @@ -462,7 +471,7 @@ static char **handle_onoff_switch(char *arg, char **next, const struct warning w if (!strcmp(p, "sparse-all")) { for (i = 0; i < n; i++) { - if (*warnings[i].flag != WARNING_FORCE_OFF) + if (*warnings[i].flag != WARNING_FORCE_OFF && warnings[i].flag != &Werror) *warnings[i].flag = WARNING_ON; } } @@ -112,6 +112,7 @@ extern int Wdefault_bitfield_sign; extern int Wdesignated_init; extern int Wdo_while; extern int Wenum_mismatch; +extern int Werror; extern int Winit_cstring; extern int Wnon_pointer_null; extern int Wold_initializer; @@ -24,6 +24,9 @@ off those warnings, pass the negation of the associated warning option, Turn on all sparse warnings, except for those explicitly disabled via \fB\-Wno\-something\fR. .TP +.B \-Werror +Turn all sparse warnings into errors. +.TP .B \-Waddress\-space Warn about code which mixes pointers to different address spaces. @@ -287,6 +287,9 @@ static void check_symbols(struct symbol_list *list) check_context(ep); } } END_FOR_EACH_PTR(sym); + + if (die_if_error) + exit(1); } int main(int argc, char **argv) diff --git a/validation/test-suite b/validation/test-suite index 3c011c6a..61667a56 100755 --- a/validation/test-suite +++ b/validation/test-suite @@ -106,20 +106,26 @@ do_test() fi verbose "Using command : $cmd" + # grab the expected output + sed -n '/check-output-start/,/check-output-end/p' $file \ + | grep -v check-output > "$file".output.expected + sed -n '/check-error-start/,/check-error-end/p' $file \ + | grep -v check-error > "$file".error.expected + # grab the expected exit value get_value "check-exit-value" $file if [ "$?" -eq "0" ]; then expected_exit_value=`echo $last_result | tr -d ' '` else - expected_exit_value=0 + grep -q -E "^[^:]+:[[:digit:]]+:[[:digit:]]+: error:" "$file".error.expected + if [ "$?" -eq "0" ]; then + expected_exit_value=1 + else + expected_exit_value=0 + fi fi verbose "Expecting exit value: $expected_exit_value" - # grab the expected output - sed -n '/check-output-start/,/check-output-end/p' $file \ - | grep -v check-output > "$file".output.expected - sed -n '/check-error-start/,/check-error-end/p' $file \ - | grep -v check-error > "$file".error.expected # grab the actual output & exit value $cmd 1> $file.output.got 2> $file.error.got |