From 93fb61858410c5749777811b5405a65fb2f6e169 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Fri, 9 Jan 2015 14:15:23 +0300 Subject: [PATCH] flow: don't inline functions which are over 20 lines long Smatch tries not to inline long functions but it counts huge switch statements as just one statement here. Use the line number as well/instead to limit function complexity. Signed-off-by: Dan Carpenter --- smatch_flow.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/smatch_flow.c b/smatch_flow.c index 39bf57ac..fe39d4c5 100644 --- a/smatch_flow.c +++ b/smatch_flow.c @@ -170,6 +170,7 @@ static int is_noreturn_func(struct expression *expr) int inlinable(struct expression *expr) { struct symbol *sym; + struct statement *last_stmt = NULL; if (__inline_fn) /* don't nest */ return 0; @@ -180,16 +181,28 @@ int inlinable(struct expression *expr) return 0; sym = get_base_type(expr->symbol); if (sym->stmt && sym->stmt->type == STMT_COMPOUND) { - if (ptr_list_size((struct ptr_list *)sym->stmt->stmts) <= 10) - return 1; - return 0; + if (ptr_list_size((struct ptr_list *)sym->stmt->stmts) > 10) + return 0; + if (sym->stmt->type != STMT_COMPOUND) + return 0; + last_stmt = last_ptr_list((struct ptr_list *)sym->stmt->stmts); } if (sym->inline_stmt && sym->inline_stmt->type == STMT_COMPOUND) { - if (ptr_list_size((struct ptr_list *)sym->inline_stmt->stmts) <= 10) - return 1; - return 0; + if (ptr_list_size((struct ptr_list *)sym->inline_stmt->stmts) > 10) + return 0; + if (sym->inline_stmt->type != STMT_COMPOUND) + return 0; + last_stmt = last_ptr_list((struct ptr_list *)sym->inline_stmt->stmts); } - return 0; + + if (!last_stmt) + return 0; + + /* the magic numbers in this function are pulled out of my bum. */ + if (last_stmt->pos.line > sym->pos.line + 20) + return 0; + + return 1; } void __process_post_op_stack(void) -- 2.11.4.GIT