From 49029290e982ca6c4ed164b4a89b8bc921897a35 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Sun, 8 Mar 2009 14:33:42 +0300 Subject: [PATCH] Add option --assume-loops. It seems like a lot of false positives are caused because programmers know that certain loops always loop at least once. That certain lists are never empty. Add an option to ignore errors caused by empty lists etc. Signed-off-by: Dan Carpenter --- smatch.c | 8 ++++++-- smatch.h | 1 + smatch_flow.c | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/smatch.c b/smatch.c index 5a6f9ab5..d7882f2e 100644 --- a/smatch.c +++ b/smatch.c @@ -39,8 +39,10 @@ const reg_func reg_funcs[] = { void help() { - printf("Usage: smatch [--debug][--debug-implied][sparse arguments]" - " file.c\n"); + printf("Usage: smatch [smatch arguments][sparse arguments] file.c\n"); + printf("--debug: print lots of debug output.\n"); + printf("--debug-implied: print debug output about implications.\n"); + printf("--assume-loops: assume loops always go through at least once.\n"); exit(1); } @@ -62,6 +64,8 @@ int main(int argc, char **argv) debug_implied_states = 1; } else if (!strcmp(argv[1], "--no-implied")) { option_no_implied = 1; + } else if (!strcmp(argv[1], "--assume-loops")) { + option_assume_loops = 1; } else if (!strcmp(argv[1], "--help")) { help(); } else { diff --git a/smatch.h b/smatch.h index 24eea2fe..234ae250 100644 --- a/smatch.h +++ b/smatch.h @@ -144,6 +144,7 @@ int in_condition(); void smatch (int argc, char **argv); void __split_expr(struct expression *expr); void __split_statements(struct statement *stmt); +extern int option_assume_loops; /* smatch_conditions */ void __split_whole_condition(struct expression *expr); diff --git a/smatch_flow.c b/smatch_flow.c index b5620ba8..1edaf210 100644 --- a/smatch_flow.c +++ b/smatch_flow.c @@ -27,6 +27,8 @@ static void split_expr_list(struct expression_list *expr_list); unsigned int __get_allocations(); +int option_assume_loops = 0; + void __split_expr(struct expression *expr) { if (!expr) @@ -148,6 +150,8 @@ static void handle_pre_loop(struct statement *stmt) __split_statements(stmt->iterator_pre_statement); once_through = known_condition_true(stmt->iterator_pre_condition); + if (option_assume_loops) + once_through = 1; __push_continues(); __push_breaks(); -- 2.11.4.GIT