From b11c9d562a2aa89e7feb97f95eb9e6da7bbf56d4 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 20 Apr 2017 12:42:37 +0300 Subject: [PATCH] flow: add init_fake_env()/end_fake_env() This is new infrastructure to use __split_expr() in a fake environment. Just using __push_fake_cur_stree() means that we would have unwanted messages from the checks and the line number gets screwed up. Signed-off-by: Dan Carpenter --- smatch.h | 2 ++ smatch_flow.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/smatch.h b/smatch.h index d592a313..4e5c448b 100644 --- a/smatch.h +++ b/smatch.h @@ -439,6 +439,8 @@ extern int __bail_on_rest_of_function; extern struct statement *__prev_stmt; extern struct statement *__cur_stmt; extern struct statement *__next_stmt; +void init_fake_env(void); +void end_fake_env(void); /* smatch_struct_assignment.c */ struct expression *get_faked_expression(void); diff --git a/smatch_flow.c b/smatch_flow.c index efdce266..d3bcc79d 100644 --- a/smatch_flow.c +++ b/smatch_flow.c @@ -26,6 +26,7 @@ #include "smatch_slist.h" int __in_fake_assign; +static int in_fake_env; int final_pass; int __inline_call; struct expression *__inline_fn; @@ -115,6 +116,9 @@ static void set_position(struct position pos) int len; static int prev_stream = -1; + if (in_fake_env) + return; + if (pos.stream == 0 && pos.line == 0) return; @@ -1681,6 +1685,24 @@ static void split_functions(struct symbol_list *sym_list) __pass_to_client(sym_list, END_FILE_HOOK); } +static int final_before_fake; +void init_fake_env(void) +{ + if (!in_fake_env) + final_before_fake = final_pass; + in_fake_env++; + __push_fake_cur_stree(); + final_pass = 0; +} + +void end_fake_env(void) +{ + __push_fake_cur_stree(); + in_fake_env--; + if (!in_fake_env) + final_pass = final_before_fake; +} + void smatch(int argc, char **argv) { struct string_list *filelist = NULL; -- 2.11.4.GIT