Skip to contentSkip to conversation

dissect: introduce reporter->r_memdef()

PATCH New Oleg Nesterov 1 participant 1 message Feb 5, 2020 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dissect: introduce reporter->r_memdef()

To report where is the member of struct/union defined.

---
 dissect.c      | 12 +++++++++++-
 dissect.h      |  1 +
 test-dissect.c |  6 ++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
dissect.c +11 -1
index 88eaab1..60fccbd 100644
@@ -203,6 +203,12 @@ static bool deanon(struct symbol *base, struct ident *node, struct symbol *paren
 	return true;
 }
 
+static void report_memdef(struct symbol *sym, struct symbol *mem)
+{
+	if (sym && mem->ident)
+		reporter->r_memdef(sym, mem);
+}
+
 static void examine_sym_node(struct symbol *node, struct symbol *parent)
 {
 	struct symbol *base;
@@ -236,8 +242,12 @@ static void examine_sym_node(struct symbol *node, struct symbol *parent)
 
 			if (base->ident || deanon(base, name, parent))
 				reporter->r_symdef(base);
+
+			if (base->ident)
+				parent = base;
 			DO_LIST(base->symbol_list, mem,
-				examine_sym_node(mem, base->ident ? base : parent));
+				examine_sym_node(mem, parent);
+				report_memdef(parent, mem));
 		default:
 			return;
 		}
dissect.h +1 -0
index 664736c..1f5b1d9 100644
@@ -19,6 +19,7 @@
 struct reporter
 {
 	void (*r_symdef)(struct symbol *);
+	void (*r_memdef)(struct symbol *, struct symbol *);
 
 	void (*r_symbol)(unsigned, struct position *, struct symbol *);
 	void (*r_member)(unsigned, struct position *, struct symbol *, struct symbol *);
test-dissect.c +6 -0
index af1212a..e725eec 100644
@@ -75,10 +75,16 @@ static void r_symdef(struct symbol *sym)
 	r_symbol(-1, &sym->pos, sym);
 }
 
+static void r_memdef(struct symbol *sym, struct symbol *mem)
+{
+	r_member(-1, &mem->pos, sym, mem);
+}
+
 int main(int argc, char **argv)
 {
 	static struct reporter reporter = {
 		.r_symdef = r_symdef,
+		.r_memdef = r_memdef,
 		.r_symbol = r_symbol,
 		.r_member = r_member,
 	};
Signature · 1 line
2.5.0