diff options
author | Josh Triplett <josht@us.ibm.com> | 2006-08-30 10:14:53 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-08-30 16:07:55 -0700 |
commit | 37475a6c1c3e66219e68d912d5eb833f4098fd72 (patch) | |
tree | d4b87d24a087663e44c900929f3f7cd5b8cc9914 /linearize.c | |
parent | [PATCH] Add -Wno-cast-truncate (diff) | |
download | sparse-37475a6c1c3e66219e68d912d5eb833f4098fd72.tar.gz sparse-37475a6c1c3e66219e68d912d5eb833f4098fd72.tar.bz2 sparse-37475a6c1c3e66219e68d912d5eb833f4098fd72.zip |
[PATCH] Parse and track multiple contexts by expression
sparse currently only tracks one global context for __context__ and
__attribute__((context)).
This adds support for parsing an additional argument to each of these
which gives a context expression. For __attribute__((context)), store
each context attribute as a separate context structure containing the
expression, the entry context, and the exit context, and keep a list of
these structures in the ctype. For __context__, store the context
expression in the context instruction. Modify the various frontends to
adapt to this change, without changing functionality.
This change should not affect parsing of programs which worked with
previous versions of sparse, unless those programs use comma expressions
as arguments to __context__ or __attribute__((context)), which seems
highly dubious and unlikely. sparse with -Wcontext generates identical
output with or without this change on Linux 2.6.18-rc4.
Signed-off-by: Josh Triplett <josh@freedesktop.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'linearize.c')
-rw-r--r-- | linearize.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/linearize.c b/linearize.c index f47bad9..8a8a2d3 100644 --- a/linearize.c +++ b/linearize.c @@ -1183,7 +1183,8 @@ static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expressi struct expression *arg, *fn; struct instruction *insn = alloc_typed_instruction(OP_CALL, expr->ctype); pseudo_t retval, call; - int context_diff, check; + struct ctype *ctype = NULL; + struct context *context; if (!expr->ctype) { warning(expr->pos, "call with no type!"); @@ -1197,21 +1198,8 @@ static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expressi fn = expr->fn; - check = 0; - context_diff = 0; - if (fn->ctype) { - int in = fn->ctype->ctype.in_context; - int out = fn->ctype->ctype.out_context; - if (in < 0) { - check = 1; - in = 0; - } - if (out < 0) { - check = 0; - out = 0; - } - context_diff = out - in; - } + if (fn->ctype) + ctype = &fn->ctype->ctype; if (fn->type == EXPR_PREOP) { if (fn->unop->type == EXPR_SYMBOL) { @@ -1232,11 +1220,29 @@ static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expressi insn->target = retval; add_one_insn(ep, insn); - if (check || context_diff) { - insn = alloc_instruction(OP_CONTEXT, 0); - insn->increment = context_diff; - insn->check = check; - add_one_insn(ep, insn); + if (ctype) { + FOR_EACH_PTR(ctype->contexts, context) { + int in = context->in; + int out = context->out; + int check = 0; + int context_diff; + if (in < 0) { + check = 1; + in = 0; + } + if (out < 0) { + check = 0; + out = 0; + } + context_diff = out - in; + if (check || context_diff) { + insn = alloc_instruction(OP_CONTEXT, 0); + insn->increment = context_diff; + insn->check = check; + insn->context_expr = context->context; + add_one_insn(ep, insn); + } + } END_FOR_EACH_PTR(context); } return retval; @@ -1637,6 +1643,7 @@ static pseudo_t linearize_context(struct entrypoint *ep, struct statement *stmt) value = expr->value; insn->increment = value; + insn->context_expr = stmt->context; add_one_insn(ep, insn); return VOID; } |