* [PATCH] sparse/dissect: introduce do_inline(struct symbol *sym)
@ 2025-12-24 11:38 Oleg Nesterov
2025-12-31 16:15 ` Oleg Nesterov
2025-12-31 16:16 ` [PATCH v2] sparse/dissect: don't miss inline functions when !dissect_show_all_symbols Oleg Nesterov
0 siblings, 2 replies; 3+ messages in thread
From: Oleg Nesterov @ 2025-12-24 11:38 UTC (permalink / raw)
To: Chris Li, Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse
parse_function_body() doesn't do add_symbol(decl) if MOD_INLINE, this
means that dissect/semind can't see the definitions of inline functions
in translation_unit_used_list.
Test-case:
$ cat -n INLINE.c
1 static inline void i_func(void)
2 {
3 unknown();
4 }
5
6 void func(void)
7 {
8 i_func();
9 i_func();
10 }
Before this patch:
$ ./test-dissect INLINE.c
6:6 def f func void ( ... )
8:9 func --r f i_func void ( ... )
9:9 func --r f i_func void ( ... )
With this patch:
$ ./test-dissect INLINE.c
6:6 def f func void ( ... )
1:20 def f i_func void ( ... )
3:9 i_func --r f unknown bad type
8:9 func --r f i_func void ( ... )
9:9 func --r f i_func void ( ... )
This change is not really needed if dissect_show_all_symbols == 1, in
this case do_file() uses file_scope/global_scope. do_inline() doesn't
bother to check dissect_show_all_symbols, it relies on sym->visited.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
dissect.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/dissect.c b/dissect.c
index 5fed8e22..62f927c5 100644
--- a/dissect.c
+++ b/dissect.c
@@ -59,6 +59,7 @@ static void do_sym_list(struct symbol_list *list);
static struct symbol
*base_type(struct symbol *sym),
+ *do_symbol(struct symbol *sym),
*do_initializer(struct symbol *type, struct expression *expr),
*do_expression(usage_t mode, struct expression *expr),
*do_statement(usage_t mode, struct statement *stmt);
@@ -331,6 +332,16 @@ static struct expression *peek_preop(struct expression *expr, int op)
return NULL;
}
+static inline void do_inline(struct symbol *sym)
+{
+ if (sym && !sym->visited && (sym->ctype.modifiers & MOD_INLINE)) {
+ struct symbol *dctx = dissect_ctx;
+ dissect_ctx = NULL;
+ do_symbol(sym);
+ dissect_ctx = dctx;
+ }
+}
+
static struct symbol *do_expression(usage_t mode, struct expression *expr)
{
struct symbol *ret = &int_ctype;
@@ -377,8 +388,10 @@ again:
ret = do_expression(mode, expr->cond_false);
break; case EXPR_CALL:
- if (expr->fn->type == EXPR_SYMBOL)
+ if (expr->fn->type == EXPR_SYMBOL) {
expr->fn->op = 'f'; /* for expr_symbol() */
+ do_inline(expr->fn->symbol);
+ }
ret = do_expression(U_R_PTR, expr->fn);
if (is_ptr(ret))
ret = ret->ctype.base_type;
@@ -621,7 +634,7 @@ static inline bool is_typedef(struct symbol *sym)
return (sym->namespace == NS_TYPEDEF);
}
-static inline struct symbol *do_symbol(struct symbol *sym)
+static struct symbol *do_symbol(struct symbol *sym)
{
struct symbol *type = base_type(sym);
struct symbol *dctx = dissect_ctx;
--
2.52.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] sparse/dissect: introduce do_inline(struct symbol *sym)
2025-12-24 11:38 [PATCH] sparse/dissect: introduce do_inline(struct symbol *sym) Oleg Nesterov
@ 2025-12-31 16:15 ` Oleg Nesterov
2025-12-31 16:16 ` [PATCH v2] sparse/dissect: don't miss inline functions when !dissect_show_all_symbols Oleg Nesterov
1 sibling, 0 replies; 3+ messages in thread
From: Oleg Nesterov @ 2025-12-31 16:15 UTC (permalink / raw)
To: Chris Li, Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse
Please ignore this patch. Cough, as if you didn't ;)
I'll send V2 in reply to this version. It is simpler and more correct.
Oleg.
On 12/24, Oleg Nesterov wrote:
>
> parse_function_body() doesn't do add_symbol(decl) if MOD_INLINE, this
> means that dissect/semind can't see the definitions of inline functions
> in translation_unit_used_list.
>
> Test-case:
>
> $ cat -n INLINE.c
> 1 static inline void i_func(void)
> 2 {
> 3 unknown();
> 4 }
> 5
> 6 void func(void)
> 7 {
> 8 i_func();
> 9 i_func();
> 10 }
>
> Before this patch:
>
> $ ./test-dissect INLINE.c
>
> 6:6 def f func void ( ... )
> 8:9 func --r f i_func void ( ... )
> 9:9 func --r f i_func void ( ... )
>
> With this patch:
>
> $ ./test-dissect INLINE.c
>
> 6:6 def f func void ( ... )
> 1:20 def f i_func void ( ... )
> 3:9 i_func --r f unknown bad type
> 8:9 func --r f i_func void ( ... )
> 9:9 func --r f i_func void ( ... )
>
> This change is not really needed if dissect_show_all_symbols == 1, in
> this case do_file() uses file_scope/global_scope. do_inline() doesn't
> bother to check dissect_show_all_symbols, it relies on sym->visited.
>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> ---
> dissect.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/dissect.c b/dissect.c
> index 5fed8e22..62f927c5 100644
> --- a/dissect.c
> +++ b/dissect.c
> @@ -59,6 +59,7 @@ static void do_sym_list(struct symbol_list *list);
>
> static struct symbol
> *base_type(struct symbol *sym),
> + *do_symbol(struct symbol *sym),
> *do_initializer(struct symbol *type, struct expression *expr),
> *do_expression(usage_t mode, struct expression *expr),
> *do_statement(usage_t mode, struct statement *stmt);
> @@ -331,6 +332,16 @@ static struct expression *peek_preop(struct expression *expr, int op)
> return NULL;
> }
>
> +static inline void do_inline(struct symbol *sym)
> +{
> + if (sym && !sym->visited && (sym->ctype.modifiers & MOD_INLINE)) {
> + struct symbol *dctx = dissect_ctx;
> + dissect_ctx = NULL;
> + do_symbol(sym);
> + dissect_ctx = dctx;
> + }
> +}
> +
> static struct symbol *do_expression(usage_t mode, struct expression *expr)
> {
> struct symbol *ret = &int_ctype;
> @@ -377,8 +388,10 @@ again:
> ret = do_expression(mode, expr->cond_false);
>
> break; case EXPR_CALL:
> - if (expr->fn->type == EXPR_SYMBOL)
> + if (expr->fn->type == EXPR_SYMBOL) {
> expr->fn->op = 'f'; /* for expr_symbol() */
> + do_inline(expr->fn->symbol);
> + }
> ret = do_expression(U_R_PTR, expr->fn);
> if (is_ptr(ret))
> ret = ret->ctype.base_type;
> @@ -621,7 +634,7 @@ static inline bool is_typedef(struct symbol *sym)
> return (sym->namespace == NS_TYPEDEF);
> }
>
> -static inline struct symbol *do_symbol(struct symbol *sym)
> +static struct symbol *do_symbol(struct symbol *sym)
> {
> struct symbol *type = base_type(sym);
> struct symbol *dctx = dissect_ctx;
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2] sparse/dissect: don't miss inline functions when !dissect_show_all_symbols
2025-12-24 11:38 [PATCH] sparse/dissect: introduce do_inline(struct symbol *sym) Oleg Nesterov
2025-12-31 16:15 ` Oleg Nesterov
@ 2025-12-31 16:16 ` Oleg Nesterov
1 sibling, 0 replies; 3+ messages in thread
From: Oleg Nesterov @ 2025-12-31 16:16 UTC (permalink / raw)
To: Chris Li, Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse
parse_function_body() doesn't do add_symbol(decl) if MOD_INLINE, this
means that dissect/semind can't see the definitions of inline functions
in translation_unit_used_list.
This change is not really needed if dissect_show_all_symbols == 1, in
this case do_file() inspects file_scope/global_scope.
Test-case:
$ cat -n INLINE.c
1 static inline void i_func1(void)
2 {
3 unkown();
4 }
5 static inline void *i_func2(void)
6 {
7 return i_func1;
8 }
9
10 void func(void)
11 {
12 i_func2();
13 }
Before this patch:
$ ./test-dissect INLINE.c
10:6 def f func void ( ... )
12:9 func --r f i_func2 void *( ... )
With this patch:
$ ./test-dissect INLINE.c
10:6 def f func void ( ... )
5:21 def f i_func2 void *( ... )
1:20 def f i_func1 void ( ... )
3:9 i_func1 --r f unkown bad type
7:16 i_func2 r-- f i_func1 void ( ... )
12:9 func --r f i_func2 void *( ... )
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
dissect.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/dissect.c b/dissect.c
index a825bb30..b9d4adc4 100644
--- a/dissect.c
+++ b/dissect.c
@@ -59,6 +59,7 @@ static void do_sym_list(struct symbol_list *list);
static struct symbol
*base_type(struct symbol *sym),
+ *do_symbol(struct symbol *sym),
*do_initializer(struct symbol *type, struct expression *expr),
*do_expression(usage_t mode, struct expression *expr),
*do_statement(usage_t mode, struct statement *stmt);
@@ -225,6 +226,12 @@ static void examine_sym_node(struct symbol *node, struct symbol *parent)
case SYM_FN:
node->kind = 'f';
+ if (node->ctype.modifiers & MOD_INLINE) {
+ struct symbol *dctx = dissect_ctx;
+ dissect_ctx = NULL;
+ do_symbol(node);
+ dissect_ctx = dctx;
+ }
node = base;
break;
@@ -621,7 +628,7 @@ static inline bool is_typedef(struct symbol *sym)
return (sym->namespace == NS_TYPEDEF);
}
-static inline struct symbol *do_symbol(struct symbol *sym)
+static struct symbol *do_symbol(struct symbol *sym)
{
struct symbol *type = base_type(sym);
struct symbol *dctx = dissect_ctx;
--
2.52.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-31 16:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-24 11:38 [PATCH] sparse/dissect: introduce do_inline(struct symbol *sym) Oleg Nesterov
2025-12-31 16:15 ` Oleg Nesterov
2025-12-31 16:16 ` [PATCH v2] sparse/dissect: don't miss inline functions when !dissect_show_all_symbols Oleg Nesterov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).