From 8ab6d645704ecc183dfb73f73ca12e7e4f86906f Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 18 Mar 2009 14:20:05 +0300 Subject: [PATCH] Make --known-conditions an option. Ignoring known untraveled code paths is a good idea. The problem is that smatch_extra still isn't aware enough when data is modified. Also we it would be better to go through and evaluate loops twice. Handling static variables might be an issue as well. Signed-off-by: Dan Carpenter --- smatch.c | 3 +++ smatch.h | 1 + smatch_flow.c | 7 +++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/smatch.c b/smatch.c index a323fe98..574bad96 100644 --- a/smatch.c +++ b/smatch.c @@ -45,6 +45,7 @@ void help() 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"); + printf("--known-conditions: don't branch for known conditions."); exit(1); } @@ -68,6 +69,8 @@ int main(int argc, char **argv) option_no_implied = 1; } else if (!strcmp(argv[1], "--assume-loops")) { option_assume_loops = 1; + } else if (!strcmp(argv[1], "--known-conditions")) { + option_known_conditions = 1; } else if (!strcmp(argv[1], "--help")) { help(); } else { diff --git a/smatch.h b/smatch.h index a8a52120..f2413180 100644 --- a/smatch.h +++ b/smatch.h @@ -146,6 +146,7 @@ void smatch (int argc, char **argv); void __split_expr(struct expression *expr); void __split_statements(struct statement *stmt); extern int option_assume_loops; +extern int option_known_conditions; /* smatch_conditions */ void __split_whole_condition(struct expression *expr); diff --git a/smatch_flow.c b/smatch_flow.c index 8072c246..9d09fd2f 100644 --- a/smatch_flow.c +++ b/smatch_flow.c @@ -28,6 +28,7 @@ static void split_expr_list(struct expression_list *expr_list); unsigned int __get_allocations(); int option_assume_loops = 0; +int option_known_conditions = 0; void __split_expr(struct expression *expr) { @@ -266,12 +267,14 @@ void __split_statements(struct statement *stmt) return; } case STMT_IF: - if (known_condition_true(stmt->if_conditional)) { + if (option_known_conditions && + known_condition_true(stmt->if_conditional)) { smatch_msg("info: this condition is true."); __split_statements(stmt->if_true); return; } - if (known_condition_false(stmt->if_conditional)) { + if (option_known_conditions && + known_condition_false(stmt->if_conditional)) { smatch_msg("info: this condition is false."); __split_statements(stmt->if_false); return; -- 2.11.4.GIT