Skip to contentSkip to conversation

dissect: fix multidimensional array initializer

PATCH Applied Oleg Nesterov 3 participants 4 messages Dec 14, 2006 – Feb 23, 2007 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dissect: fix multidimensional array initializer

dissect can't parse initializers like

	struct T { int i; } a[2][3] = { [0][0] = {123} };

, output is:

	   1:8   s def  T
	   1:21  g def  a                                struct T [3][2]
	   1:21  g -w-  a                                struct T [3][2]
	T.c:1:37: warning: bad expr->type: 25

with this patch applied:

	   1:8   s def  T
	   1:21  g def  a                                struct T [3][2]
	   1:21  g -w-  a                                struct T [3][2]
	   1:43  s -w-  T.i                              int
dissect.c renamed from dissect.c~ +4 -1
@@ -507,10 +507,13 @@ static struct symbol *do_initializer(str
 	default:
 		do_expression(u_lval(type), expr);
 
+	break; case EXPR_INDEX:
+		do_initializer(base_type(type), expr->idx_expression);
+
 	break; case EXPR_INITIALIZER:
 		m_addr = 0;
 		FOR_EACH_PTR(expr->expr_list, m_expr)
-			if(type->type == SYM_ARRAY) {
+			if (type->type == SYM_ARRAY) {
 				m_type = base_type(type);
 				if (m_expr->type == EXPR_INDEX)
 					m_expr = m_expr->idx_expression;
maintainer
#1 lore raw

I did not test it myself, but it looks seasonable to me.

BTW, did you look at the show-parse series of function? It is a good example of how to traverse the symbol tree. I would love to see dissect using similar structure.

Chris

Quoted 37 lines · Oleg Nesterov

dissect can't parse initializers like

	struct T { int i; } a[2][3] = { [0][0] = {123} };

, output is:

	   1:8   s def  T
	   1:21  g def  a                                struct T [3][2]
	   1:21  g -w-  a                                struct T [3][2]
	T.c:1:37: warning: bad expr->type: 25

with this patch applied:

	   1:8   s def  T
	   1:21  g def  a                                struct T [3][2]
	   1:21  g -w-  a                                struct T [3][2]
	   1:43  s -w-  T.i                              int
dissect.c renamed from dissect.c~ +4 -1
@@ -507,10 +507,13 @@ static struct symbol *do_initializer(str
 	default:
 		do_expression(u_lval(type), expr);
 
+	break; case EXPR_INDEX:
+		do_initializer(base_type(type), expr->idx_expression);
+
 	break; case EXPR_INITIALIZER:
 		m_addr = 0;
 		FOR_EACH_PTR(expr->expr_list, m_expr)
-			if(type->type == SYM_ARRAY) {
+			if (type->type == SYM_ARRAY) {
 				m_type = base_type(type);
 				if (m_expr->type == EXPR_INDEX)
 					m_expr = m_expr->idx_expression;
#2 lore raw
Quoted 2 lines · Christopher Li

I did not test it myself, but it looks seasonable to me.

Thanks.

Quoted 3 lines

BTW, did you look at the show-parse series of function? It is a good example of how to traverse the symbol tree. I would love to see dissect using similar structure.

dissect is quite different, please look at

	http://marc.theaimsgroup.com/?l=linux-sparse&m=112585110531119

And it is (I hope) complete. Note also it doesn't use evaluate.c, it calls __sparse(). I am still waiting somebody will implement sparse based cscope using dissect :)

What exactly you don't like in how it traverses the tree? Actually, the structure is similar, but diisect has to track "usage_t mode".

Oleg.

#3 lore raw
In reply to Oleg Nesterov
Quoted 11 lines · Oleg Nesterov

dissect can't parse initializers like

	struct T { int i; } a[2][3] = { [0][0] = {123} };

, output is:

	   1:8   s def  T
	   1:21  g def  a                                struct T [3][2]
	   1:21  g -w-  a                                struct T [3][2]
	T.c:1:37: warning: bad expr->type: 25
Quoted 8 lines

with this patch applied:

	   1:8   s def  T
	   1:21  g def  a                                struct T [3][2]
	   1:21  g -w-  a                                struct T [3][2]
	   1:43  s -w-  T.i                              int

Applied.

- Josh Triplett