* [PATCH 1/2] dissect: don't set ->ident = '?' in no_member()
@ 2020-02-12 10:04 Oleg Nesterov
2020-02-12 10:04 ` [PATCH 2/2] dissect: kill no_member() Oleg Nesterov
0 siblings, 1 reply; 2+ messages in thread
From: Oleg Nesterov @ 2020-02-12 10:04 UTC (permalink / raw)
To: Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse
no_member() sets ->ident = built_in_ident("?") for the case when dissect()
can't figure out the name of initialized member. For example:
struct EMPTY {} var = { 10 };
the output:
1:25 var -w- m EMPTY.? bad type
This is useful, but dissect should not dictate the policy. Let r_member()
decide how this case should be reported.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
dissect.c | 6 +++---
test-dissect.c | 7 ++++---
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/dissect.c b/dissect.c
index 6706690..05bddc8 100644
--- a/dissect.c
+++ b/dissect.c
@@ -123,11 +123,11 @@ static inline struct symbol *no_member(struct ident *name)
{
static struct symbol sym = {
.type = SYM_BAD,
+ .ctype.base_type = &bad_ctype,
.kind = 'm',
};
- sym.ctype.base_type = &bad_ctype;
- sym.ident = name ?: built_in_ident("?");
+ sym.ident = name;
return &sym;
}
@@ -137,7 +137,7 @@ static struct symbol *report_member(usage_t mode, struct position *pos,
{
struct symbol *ret = mem->ctype.base_type;
- if (mem->ident)
+ if (mem->ident || mem->type == SYM_BAD)
reporter->r_member(fix_mode(ret, mode), pos, type, mem);
return ret;
diff --git a/test-dissect.c b/test-dissect.c
index 4b2d3be..58b3e63 100644
--- a/test-dissect.c
+++ b/test-dissect.c
@@ -80,13 +80,14 @@ err:
static void r_member(unsigned mode, struct position *pos, struct symbol *sym, struct symbol *mem)
{
- struct ident *si, *mi;
+ struct ident *ni, *si, *mi;
print_usage(pos, sym, mode);
- si = sym->ident ?: built_in_ident("?");
+ ni = built_in_ident("?");
+ si = sym->ident ?: ni;
/* mem == NULL means entire struct accessed */
- mi = mem ? mem->ident : built_in_ident("*");
+ mi = mem ? (mem->ident ?: ni) : built_in_ident("*");
printf("%c m %.*s.%-*.*s %s\n",
symscope(sym), si->len, si->name,
--
2.5.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] dissect: kill no_member()
2020-02-12 10:04 [PATCH 1/2] dissect: don't set ->ident = '?' in no_member() Oleg Nesterov
@ 2020-02-12 10:04 ` Oleg Nesterov
0 siblings, 0 replies; 2+ messages in thread
From: Oleg Nesterov @ 2020-02-12 10:04 UTC (permalink / raw)
To: Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse
It is trivial and has a single caller, lookup_member().
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
dissect.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/dissect.c b/dissect.c
index 05bddc8..40baf64 100644
--- a/dissect.c
+++ b/dissect.c
@@ -119,19 +119,6 @@ static usage_t fix_mode(struct symbol *type, usage_t mode)
return mode;
}
-static inline struct symbol *no_member(struct ident *name)
-{
- static struct symbol sym = {
- .type = SYM_BAD,
- .ctype.base_type = &bad_ctype,
- .kind = 'm',
- };
-
- sym.ident = name;
-
- return &sym;
-}
-
static struct symbol *report_member(usage_t mode, struct position *pos,
struct symbol *type, struct symbol *mem)
{
@@ -308,8 +295,20 @@ found:
static struct symbol *lookup_member(struct symbol *type, struct ident *name, int *addr)
{
- return __lookup_member(type, name, addr)
- ?: no_member(name);
+ struct symbol *mem = __lookup_member(type, name, addr);
+
+ if (!mem) {
+ static struct symbol bad_member = {
+ .type = SYM_BAD,
+ .ctype.base_type = &bad_ctype,
+ .kind = 'm',
+ };
+
+ mem = &bad_member;
+ mem->ident = name;
+ }
+
+ return mem;
}
static struct expression *peek_preop(struct expression *expr, int op)
--
2.5.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-02-12 10:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-12 10:04 [PATCH 1/2] dissect: don't set ->ident = '?' in no_member() Oleg Nesterov
2020-02-12 10:04 ` [PATCH 2/2] dissect: kill no_member() Oleg Nesterov
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.