Skip to contentSkip to conversation

dissect: teach do_expression() to handle EXPR_OFFSETOF

PATCH In review Oleg Nesterov 3 participants 3 messages Feb 8, 2016 – Nov 2, 2016 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dissect: teach do_expression() to handle EXPR_OFFSETOF

Starting from a194f3e0 "implement __builtin_offsetof()" sparse handles offsetof() internally but dissect.c wasn't updated.

Test case:

	struct S { int m; };

	void func(void)
	{
		__builtin_offsetof(struct S, m);
	}

before this patch:

	3:6   g def  func                             void ( ... )
	T.c:5:38: warning: bad expr->type: 30

after:

	3:6   g def  func                             void ( ... )
	1:8   s def  S
	5:38  s ---  S.m                              int

While at it, update my email.

---
 dissect.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
dissect.c +15 -1
index d211bca..19f3276 100644
@@ -1,7 +1,7 @@
 /*
  * sparse/dissect.c
  *
- * Started by Oleg Nesterov <[email protected]>
+ * Started by Oleg Nesterov <[email protected]>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -429,6 +429,20 @@ again:
 			lookup_member(p_type, expr->member, NULL));
 	}
 
+	break; case EXPR_OFFSETOF: {
+		struct symbol *in = base_type(expr->in);
+
+		do {
+			if (expr->op == '.') {
+				in = report_member(U_VOID, &expr->pos, in,
+					lookup_member(in, expr->ident, NULL));
+			} else {
+				do_expression(U_R_VAL, expr->index);
+				in = in->ctype.base_type;
+			}
+		} while ((expr = expr->down));
+	}
+
 	break; case EXPR_SYMBOL:
 		ret = report_symbol(mode, expr);
 	}
Signature · 1 line
2.5.0
Acked-by on v1 1/1
#1 lore raw

+++ Oleg Nesterov [08/02/16 14:26 +0100]:

Quoted 19 lines

Starting from a194f3e0 "implement __builtin_offsetof()" sparse handles offsetof() internally but dissect.c wasn't updated.

Test case:

	struct S { int m; };

	void func(void)
	{
		__builtin_offsetof(struct S, m);
	}

before this patch:

	3:6   g def  func                             void ( ... )
	T.c:5:38: warning: bad expr->type: 30

after:

Quoted 7 lines
	3:6   g def  func                             void ( ... )
	1:8   s def  S
	5:38  s ---  S.m                              int

While at it, update my email.

LGTM, builds and test case works as expected.