* [PATCH 0/4] dissect: minor fixes/cleanups
@ 2020-02-04 16:51 Oleg Nesterov
2020-02-04 16:51 ` [PATCH 1/4] dissect: don't report anonymous members in initializers Oleg Nesterov
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Oleg Nesterov @ 2020-02-04 16:51 UTC (permalink / raw)
To: Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse
Hello,
Preparations for the new functionality.
Oleg.
---
dissect.c | 42 +++++++++++++++++++-----------------------
test-dissect.c | 7 +++----
2 files changed, 22 insertions(+), 27 deletions(-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/4] dissect: don't report anonymous members in initializers
2020-02-04 16:51 [PATCH 0/4] dissect: minor fixes/cleanups Oleg Nesterov
@ 2020-02-04 16:51 ` Oleg Nesterov
2020-02-04 16:51 ` [PATCH 2/4] dissect: turn mk_name() into deanon() Oleg Nesterov
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Oleg Nesterov @ 2020-02-04 16:51 UTC (permalink / raw)
To: Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse
Change report_member() to not call ->r_member(mem) if !mem->ident.
This can only happen in initializer, the output gives no useful info
but looks like a bug. Test-case:
struct {
union {
int x;
};
} var = {
{}
};
before this patch:
1:8 s def :var
5:3 g def var struct :var
5:3 g -w- var struct :var
6:9 s -w- :var.? union <noident>
after:
1:8 s def :var
5:3 g def var struct :var
5:3 g -w- var struct :var
We also need to change no_member() to ensure we still report the bad
initializers, this will be cleanuped later.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
dissect.c | 4 ++--
test-dissect.c | 7 +++----
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/dissect.c b/dissect.c
index 14d57bf..ff3a313 100644
--- a/dissect.c
+++ b/dissect.c
@@ -125,7 +125,7 @@ static inline struct symbol *no_member(struct ident *name)
};
sym.ctype.base_type = &bad_ctype;
- sym.ident = name;
+ sym.ident = name ?: built_in_ident("?");
return &sym;
}
@@ -135,7 +135,7 @@ static struct symbol *report_member(usage_t mode, struct position *pos,
{
struct symbol *ret = mem->ctype.base_type;
- if (reporter->r_member)
+ if (mem->ident && reporter->r_member)
reporter->r_member(fix_mode(ret, mode), pos, type, mem);
return ret;
diff --git a/test-dissect.c b/test-dissect.c
index 266148b..af1212a 100644
--- a/test-dissect.c
+++ b/test-dissect.c
@@ -56,14 +56,13 @@ static void r_symbol(unsigned mode, struct position *pos, struct symbol *sym)
static void r_member(unsigned mode, struct position *pos, struct symbol *sym, struct symbol *mem)
{
- struct ident *ni, *si, *mi;
+ struct ident *si, *mi;
print_usage(pos, sym, mode);
- ni = built_in_ident("?");
- si = sym->ident ?: ni;
+ si = sym->ident ?: built_in_ident("?");
/* mem == NULL means entire struct accessed */
- mi = mem ? (mem->ident ?: ni) : built_in_ident("*");
+ mi = mem ? mem->ident : built_in_ident("*");
printf("%.*s.%-*.*s %s\n",
si->len, si->name,
--
2.5.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] dissect: turn mk_name() into deanon()
2020-02-04 16:51 [PATCH 0/4] dissect: minor fixes/cleanups Oleg Nesterov
2020-02-04 16:51 ` [PATCH 1/4] dissect: don't report anonymous members in initializers Oleg Nesterov
@ 2020-02-04 16:51 ` Oleg Nesterov
2020-02-04 16:51 ` [PATCH 3/4] dissect: change deanon() to handle the !node case Oleg Nesterov
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Oleg Nesterov @ 2020-02-04 16:51 UTC (permalink / raw)
To: Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse
Preparation. Change mk_name() to initialize base->ident itself, simplify it,
and rename to deanon().
Also change examine_sym_node() to accept "struct symbol *parent" rather than
"struct ident *root". Currently it is only used as ->ident holder, but this
will be changed.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
dissect.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/dissect.c b/dissect.c
index ff3a313..d34b38a 100644
--- a/dissect.c
+++ b/dissect.c
@@ -190,18 +190,22 @@ static struct symbol *report_symbol(usage_t mode, struct expression *expr)
return ret;
}
-static inline struct ident *mk_name(struct ident *root, struct ident *node)
+static bool deanon(struct symbol *base, struct ident *node, struct symbol *parent)
{
+ struct ident *pi = parent ? parent->ident : NULL;
char name[256];
+ if (!node)
+ return false;
+
snprintf(name, sizeof(name), "%.*s:%.*s",
- root ? root->len : 0, root ? root->name : "",
- node ? node->len : 0, node ? node->name : "");
+ pi ? pi->len : 0, pi ? pi->name : NULL, node->len, node->name);
- return built_in_ident(name);
+ base->ident = built_in_ident(name);
+ return true;
}
-static void examine_sym_node(struct symbol *node, struct ident *root)
+static void examine_sym_node(struct symbol *node, struct symbol *parent)
{
struct symbol *base;
struct ident *name;
@@ -232,12 +236,12 @@ static void examine_sym_node(struct symbol *node, struct ident *root)
return;
base->evaluated = 1;
- if (!base->ident && name)
- base->ident = mk_name(root, name);
- if (base->ident && reporter->r_symdef)
- reporter->r_symdef(base);
+ if (base->ident || deanon(base, name, parent)) {
+ if (reporter->r_symdef)
+ reporter->r_symdef(base);
+ }
DO_LIST(base->symbol_list, mem,
- examine_sym_node(mem, base->ident ?: root));
+ examine_sym_node(mem, base->ident ? base : parent));
default:
return;
}
--
2.5.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] dissect: change deanon() to handle the !node case
2020-02-04 16:51 [PATCH 0/4] dissect: minor fixes/cleanups Oleg Nesterov
2020-02-04 16:51 ` [PATCH 1/4] dissect: don't report anonymous members in initializers Oleg Nesterov
2020-02-04 16:51 ` [PATCH 2/4] dissect: turn mk_name() into deanon() Oleg Nesterov
@ 2020-02-04 16:51 ` Oleg Nesterov
2020-02-04 16:51 ` [PATCH 4/4] dissect: disallow NULL pointers in struct reporter Oleg Nesterov
2020-02-06 3:08 ` [PATCH 0/4] dissect: minor fixes/cleanups Luc Van Oostenryck
4 siblings, 0 replies; 6+ messages in thread
From: Oleg Nesterov @ 2020-02-04 16:51 UTC (permalink / raw)
To: Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse
Change deanon() to always initialize base->ident when parent != NULL
but still return false to avoid the pointless ->r_symdef().
Test-case:
struct {
union {
int x;
};
} var = {
{ .x = 0 },
};
before this patch:
1:8 s def :var
5:3 g def var struct :var
5:3 g -w- var struct :var
6:12 s -w- ?.x int
after:
1:8 s def :var
5:3 g def var struct :var
5:3 g -w- var struct :var
6:12 s -w- :var.x int
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
dissect.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/dissect.c b/dissect.c
index d34b38a..57dcdb2 100644
--- a/dissect.c
+++ b/dissect.c
@@ -195,8 +195,10 @@ static bool deanon(struct symbol *base, struct ident *node, struct symbol *paren
struct ident *pi = parent ? parent->ident : NULL;
char name[256];
- if (!node)
+ if (!node) {
+ base->ident = pi;
return false;
+ }
snprintf(name, sizeof(name), "%.*s:%.*s",
pi ? pi->len : 0, pi ? pi->name : NULL, node->len, node->name);
--
2.5.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] dissect: disallow NULL pointers in struct reporter
2020-02-04 16:51 [PATCH 0/4] dissect: minor fixes/cleanups Oleg Nesterov
` (2 preceding siblings ...)
2020-02-04 16:51 ` [PATCH 3/4] dissect: change deanon() to handle the !node case Oleg Nesterov
@ 2020-02-04 16:51 ` Oleg Nesterov
2020-02-06 3:08 ` [PATCH 0/4] dissect: minor fixes/cleanups Luc Van Oostenryck
4 siblings, 0 replies; 6+ messages in thread
From: Oleg Nesterov @ 2020-02-04 16:51 UTC (permalink / raw)
To: Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse
This makes dissect.c a bit more readable.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
dissect.c | 24 +++++++-----------------
1 file changed, 7 insertions(+), 17 deletions(-)
diff --git a/dissect.c b/dissect.c
index 57dcdb2..88eaab1 100644
--- a/dissect.c
+++ b/dissect.c
@@ -135,7 +135,7 @@ static struct symbol *report_member(usage_t mode, struct position *pos,
{
struct symbol *ret = mem->ctype.base_type;
- if (mem->ident && reporter->r_member)
+ if (mem->ident)
reporter->r_member(fix_mode(ret, mode), pos, type, mem);
return ret;
@@ -146,9 +146,6 @@ static void report_implicit(usage_t mode, struct position *pos, struct symbol *t
if (type->type != SYM_STRUCT && type->type != SYM_UNION)
return;
- if (!reporter->r_member)
- return;
-
if (type->ident != NULL)
reporter->r_member(mode, pos, type, NULL);
@@ -184,8 +181,7 @@ static struct symbol *report_symbol(usage_t mode, struct expression *expr)
if (0 && ret->type == SYM_ENUM)
return report_member(mode, &expr->pos, ret, expr->symbol);
- if (reporter->r_symbol)
- reporter->r_symbol(fix_mode(ret, mode), &expr->pos, sym);
+ reporter->r_symbol(fix_mode(ret, mode), &expr->pos, sym);
return ret;
}
@@ -238,10 +234,8 @@ static void examine_sym_node(struct symbol *node, struct symbol *parent)
return;
base->evaluated = 1;
- if (base->ident || deanon(base, name, parent)) {
- if (reporter->r_symdef)
- reporter->r_symdef(base);
- }
+ if (base->ident || deanon(base, name, parent))
+ reporter->r_symdef(base);
DO_LIST(base->symbol_list, mem,
examine_sym_node(mem, base->ident ? base : parent));
default:
@@ -577,19 +571,15 @@ static struct symbol *do_initializer(struct symbol *type, struct expression *exp
static inline struct symbol *do_symbol(struct symbol *sym)
{
- struct symbol *type;
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/4] dissect: minor fixes/cleanups
2020-02-04 16:51 [PATCH 0/4] dissect: minor fixes/cleanups Oleg Nesterov
` (3 preceding siblings ...)
2020-02-04 16:51 ` [PATCH 4/4] dissect: disallow NULL pointers in struct reporter Oleg Nesterov
@ 2020-02-06 3:08 ` Luc Van Oostenryck
4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2020-02-06 3:08 UTC (permalink / raw)
To: Oleg Nesterov; +Cc: Alexey Gladkov, linux-sparse
On Tue, Feb 04, 2020 at 05:51:19PM +0100, Oleg Nesterov wrote:
Thanks for theses patches and the following one.
-- Luc
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-02-06 3:08 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-04 16:51 [PATCH 0/4] dissect: minor fixes/cleanups Oleg Nesterov
2020-02-04 16:51 ` [PATCH 1/4] dissect: don't report anonymous members in initializers Oleg Nesterov
2020-02-04 16:51 ` [PATCH 2/4] dissect: turn mk_name() into deanon() Oleg Nesterov
2020-02-04 16:51 ` [PATCH 3/4] dissect: change deanon() to handle the !node case Oleg Nesterov
2020-02-04 16:51 ` [PATCH 4/4] dissect: disallow NULL pointers in struct reporter Oleg Nesterov
2020-02-06 3:08 ` [PATCH 0/4] dissect: minor fixes/cleanups Luc Van Oostenryck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.