From cb14de58097d97e467dbb97079bebb6ac70038a1 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Wed, 5 Apr 2017 17:38:08 +0200 Subject: [PATCH] finer control over error vs. warnings Currently, once an error is issued, warnings are no more issued, only others errors are. It make sense as once an error is encountered things can be left in an incoherent state and could cause lots of useless warnings because of this incoherence. However, it's also quite annoying as even unrelated warnings are so silenced and potential bugs stay thus hidden. Fix this by: - use a specific flag for this: 'has_error' - make the distinction between the current phase and some previous phases (but for now we only care about parsing vs evaluation) - if an error has been issued in a previous phase (at parsing) warnings are suppressed for the current phase and all future phases - if an error is issued in the current phase (evaluation) the flag is reset after each functions/symbols For example, with this patch, a typing error in function fa() will not suppress warnings for function fb(), while a parsing error will still inhibit all further warnings. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 1 + lib.c | 7 +++++-- lib.h | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/evaluate.c b/evaluate.c index 87e28621..f8ed10f1 100644 --- a/evaluate.c +++ b/evaluate.c @@ -3227,6 +3227,7 @@ void evaluate_symbol_list(struct symbol_list *list) struct symbol *sym; FOR_EACH_PTR(list, sym) { + has_error &= ~ERROR_CURR_PHASE; evaluate_symbol(sym); check_duplicates(sym); } END_FOR_EACH_PTR(sym); diff --git a/lib.c b/lib.c index e1e6a1cb..bb162980 100644 --- a/lib.c +++ b/lib.c @@ -47,6 +47,7 @@ int verbose, optimize, optimize_size, preprocessing; int die_if_error = 0; +int has_error = 0; #ifndef __GNUC__ # define __GNUC__ 2 @@ -133,7 +134,7 @@ static void do_error(struct position pos, const char * fmt, va_list args) die_if_error = 1; show_info = 1; /* Shut up warnings after an error */ - max_warnings = 0; + has_error |= ERROR_CURR_PHASE; if (errors > 100) { static int once = 0; show_info = 0; @@ -158,7 +159,7 @@ void warning(struct position pos, const char * fmt, ...) return; } - if (!max_warnings) { + if (!max_warnings || has_error) { show_info = 0; return; } @@ -1294,6 +1295,8 @@ struct symbol_list * sparse(char *filename) { struct symbol_list *res = __sparse(filename); + if (has_error & ERROR_CURR_PHASE) + has_error = ERROR_PREV_PHASE; /* Evaluate the complete symbol list */ evaluate_symbol_list(res); diff --git a/lib.h b/lib.h index 2c8529f9..3c08f1c3 100644 --- a/lib.h +++ b/lib.h @@ -98,6 +98,10 @@ extern void sparse_error(struct position, const char *, ...) FORMAT_ATTR(2); extern void error_die(struct position, const char *, ...) FORMAT_ATTR(2) NORETURN_ATTR; extern void expression_error(struct expression *, const char *, ...) FORMAT_ATTR(2); +#define ERROR_CURR_PHASE (1 << 0) +#define ERROR_PREV_PHASE (1 << 1) +extern int has_error; + extern void add_pre_buffer(const char *fmt, ...) FORMAT_ATTR(1); extern int preprocess_only; -- 2.11.4.GIT