aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Olien <dmo@osdl.org>2003-09-01 18:59:42 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:01:03 -0700
commit4622a094643f24e6723ffe82c58469f65363f042 (patch)
treefdd1ddf88fcc9d5c36e9a6ffcfe523c75c38e27e /show-parse.c
parent[PATCH] print out the function which causes errors (diff)
downloadsparse-4622a094643f24e6723ffe82c58469f65363f042.tar.gz
sparse-4622a094643f24e6723ffe82c58469f65363f042.tar.bz2
sparse-4622a094643f24e6723ffe82c58469f65363f042.zip
[PATCH] Make sparse understand complex initializers inside expressions
This patch makes a cast expression followed by an initializer list into a postfix expression that can be dereferenced as a structure or an array. There are approximately 7 instances of these expressions in the Linux kernel, that give warnings about "expected lvalue for member dereference". The approach involved introducing a new "stack-based temporary" symbol of the same type as the cast expression, and using this as the target of the initialization expression. The subsequent array or structure member dereferences are made to that temporary symbol. show-parse.c need modification to display a symbol expression with an initializer list that is NOT in a symbol declaration list. An example of this form with structure member dereference is: typedef struct { long t1; long t2; long t3; } longstruct_t; long test; int main(void) { int a, b, c; test = (longstruct_t){a, b, c}.t3; return 0; } An example of this form with array member dereference is: typedef int iarray[2]; int pgp; main(void) { int index; int a, b; pgp = (iarray){a,b}[index]; }
Diffstat (limited to 'show-parse.c')
-rw-r--r--show-parse.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/show-parse.c b/show-parse.c
index 0d7084b..14b06bb 100644
--- a/show-parse.c
+++ b/show-parse.c
@@ -913,6 +913,15 @@ static int show_initializer_expr(struct expression *expr, struct symbol *ctype)
return 0;
}
+int show_symbol_expr_init(struct symbol *sym)
+{
+ struct expression *expr = sym->initializer;
+
+ if (expr)
+ show_initializer_expr(expr, expr->ctype);
+ return show_symbol_expr(sym);
+}
+
/*
* Print out an expression. Return the pseudo that contains the
* variable.
@@ -947,7 +956,7 @@ int show_expression(struct expression *expr)
case EXPR_POSTOP:
return show_postop(expr);
case EXPR_SYMBOL:
- return show_symbol_expr(expr->symbol);
+ return show_symbol_expr_init(expr->symbol);
case EXPR_DEREF:
case EXPR_SIZEOF:
warn(expr->pos, "invalid expression after evaluation");