Introduce expression_error
Christopher Li
maintainerPATCH 1/1 Introduce expression_error
Adding a new function expression_error, it works just like sparse_error but it also install a bad_ctype on expression.
lib.c +18 -4
@@ -126,10 +126,9 @@ void warning(struct position pos, constva_end (args); } -void sparse_error (struct position pos,const char * fmt, ...) +void do_error (struct position pos,const char * fmt,va_list args) {static int errors =0 ; -va_list args; die_if_error =1 ; show_info =1 ;/* Shut up warnings after an error */
@@ -143,12 +142,27 @@ void sparse_error(struct position pos, c once =1 ; } -va_start (args, fmt);do_warn ("error: " , pos, fmt, args); -va_end (args); errors++; } +void sparse_error (struct position pos,const char * fmt, ...) +{ +va_list args; +va_start (args, fmt); +do_error (pos, fmt, args); +va_end (args); +} + +void expression_error (struct expression *expr,const char *fmt, ...) +{ +va_list args; +va_start (args, fmt); +do_error (expr->pos, fmt, args); +va_end (args); + expr->ctype = &bad_ctype; +} +void error_die (struct position pos,const char * fmt, ...) {va_list args;
evaluate.c +41 -41
309 lines not on this page · raw message
expand.c +5 -5
@@ -765,7 +765,7 @@ static int expand_call(struct expression cost =expand_arguments (expr->args); sym = fn->ctype;if (!sym) { -sparse_error (expr->pos,"function has no type" ); +expression_error (expr,"function has no type" );return SIDE_EFFECTS ; }if (sym->type ==SYM_NODE )
@@ -964,7 +964,7 @@ static int expand_expression(struct exprcase EXPR_SIZEOF :case EXPR_PTRSIZEOF :case EXPR_ALIGNOF : -sparse_error (expr->pos,"internal front-end error: sizeof in expansion?" ); +expression_error (expr,"internal front-end error: sizeof in expansion?" );return UNSAFE ; }return SIDE_EFFECTS ;
@@ -975,7 +975,7 @@ static void expand_const_expression(struif (expr) {expand_expression (expr);if (expr->type !=EXPR_VALUE ) -sparse_error (expr->pos,"Expected constant expression in %s" , where); +expression_error (expr,"Expected constant expression in %s" , where); } }
@@ -1148,12 +1148,12 @@ long long get_expression_value(struct exreturn 0 ; ctype =evaluate_expression (expr);if (!ctype) { -sparse_error (expr->pos,"bad constant expression type" ); +expression_error (expr,"bad constant expression type" );return 0 ; }expand_expression (expr);if (expr->type !=EXPR_VALUE ) { -sparse_error (expr->pos,"bad constant expression" ); +expression_error (expr,"bad constant expression" );return 0 ; }
lib.h +1 -0
@@ -76,6 +76,7 @@ extern void info(struct position, const extern void warning(struct position, const char *, ...) FORMAT_ATTR(2); extern void sparse_error(struct position, const char *, ...) FORMAT_ATTR(2); extern void error_die(struct position, const char *, ...) FORMAT_ATTR(2); +extern void expression_error(struct expression *, const char *, ...) FORMAT_ATTR(2);#undef FORMAT_ATTRextern char **handle_switch (char *arg,char **next);
Quoted 4 lines · Christopher Li
Adding a new function
expression_error, it works just likesparse_errorbut it also install abad_ctypeon expression.Signed-off-by Christopher Li <[email protected]>
This patch makes "sparse -Wall validation/badtype4.c" segfault.
- Josh Triplett
Christopher Li
maintainerQuoted 2 lines · Josh Triplett
Christopher Li wrote:
This patch makes "sparse -Wallvalidation/badtype4.c" segfault.
This version should fix it. But I am still not brave enough to remove the test for !expr->ctype yet.
Chris
Adding a new function expression_error, it works just like sparse_error but it also install a bad_ctype on expression.
lib.c +18 -4
@@ -126,10 +126,9 @@ void warning(struct position pos, constva_end (args); } -void sparse_error (struct position pos,const char * fmt, ...) +void do_error (struct position pos,const char * fmt,va_list args) {static int errors =0 ; -va_list args; die_if_error =1 ; show_info =1 ;/* Shut up warnings after an error */
@@ -143,12 +142,27 @@ void sparse_error(struct position pos, c once =1 ; } -va_start (args, fmt);do_warn ("error: " , pos, fmt, args); -va_end (args); errors++; } +void sparse_error (struct position pos,const char * fmt, ...) +{ +va_list args; +va_start (args, fmt); +do_error (pos, fmt, args); +va_end (args); +} + +void expression_error (struct expression *expr,const char *fmt, ...) +{ +va_list args; +va_start (args, fmt); +do_error (expr->pos, fmt, args); +va_end (args); + expr->ctype = &bad_ctype; +} +void error_die (struct position pos,const char * fmt, ...) {va_list args;
evaluate.c +41 -41
309 lines not on this page · raw message
expand.c +7 -7
@@ -765,7 +765,7 @@ static int expand_call(struct expression cost =expand_arguments (expr->args); sym = fn->ctype;if (!sym) { -sparse_error (expr->pos,"function has no type" ); +expression_error (expr,"function has no type" );return SIDE_EFFECTS ; }if (sym->type ==SYM_NODE )
@@ -885,7 +885,7 @@ static int expand_expression(struct expr {if (!expr)return 0 ; -if (!expr->ctype) +if (!expr->ctype || expr->ctype == &bad_ctype)return UNSAFE ;switch (expr->type) {
@@ -964,7 +964,7 @@ static int expand_expression(struct exprcase EXPR_SIZEOF :case EXPR_PTRSIZEOF :case EXPR_ALIGNOF : -sparse_error (expr->pos,"internal front-end error: sizeof in expansion?" ); +expression_error (expr,"internal front-end error: sizeof in expansion?" );return UNSAFE ; }return SIDE_EFFECTS ;
@@ -975,7 +975,7 @@ static void expand_const_expression(struif (expr) {expand_expression (expr);if (expr->type !=EXPR_VALUE ) -sparse_error (expr->pos,"Expected constant expression in %s" , where); +expression_error (expr,"Expected constant expression in %s" , where); } }
@@ -1008,7 +1008,7 @@ static int expand_if_statement(struct st {struct expression *expr = stmt->if_conditional; -if (!expr || !expr->ctype) +if (!expr || !expr->ctype || expr->ctype == &bad_ctype)return UNSAFE ;expand_expression (expr);
@@ -1148,12 +1148,12 @@ long long get_expression_value(struct exreturn 0 ; ctype =evaluate_expression (expr);if (!ctype) { -sparse_error (expr->pos,"bad constant expression type" ); +expression_error (expr,"bad constant expression type" );return 0 ; }expand_expression (expr);if (expr->type !=EXPR_VALUE ) { -sparse_error (expr->pos,"bad constant expression" ); +expression_error (expr,"bad constant expression" );return 0 ; }
lib.h +1 -0
@@ -76,6 +76,7 @@ extern void info(struct position, const extern void warning(struct position, const char *, ...) FORMAT_ATTR(2); extern void sparse_error(struct position, const char *, ...) FORMAT_ATTR(2); extern void error_die(struct position, const char *, ...) FORMAT_ATTR(2); +extern void expression_error(struct expression *, const char *, ...) FORMAT_ATTR(2);#undef FORMAT_ATTRextern char **handle_switch (char *arg,char **next);
Josh Triplett
AppliedQuoted 7 lines · Christopher Li
Quoted 2 lines · Josh Triplett
Christopher Li wrote:
This patch makes "sparse -Wallvalidation/badtype4.c" segfault.This version should fix it. But I am still not brave enough to remove the test for !expr->ctype yet.
Quoted 6 lines
Chris
Adding a new function
expression_error, it works just likesparse_errorbut it also install abad_ctypeon expression.Signed-off-by Christopher Li <[email protected]>
Applied.
- Josh Triplett