* [PATCH] evaluate/expand context expressions
@ 2008-04-25 11:24 Johannes Berg
0 siblings, 0 replies; only message in thread
From: Johannes Berg @ 2008-04-25 11:24 UTC (permalink / raw)
To: Josh Triplett; +Cc: Philipp Reisner, linux-sparse
But still allow having a standalone symbol as the context
expression, also evaluate the context change/requirement
directly in the parser and pass them up as integers. Also
fixes a number of bugs e.g. in the expression copier and
a segfault when the default context is used as such:
__context__(1,1);
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
---
evaluate.c | 9 ++++++++-
expand.c | 2 +-
inline.c | 19 ++++++++++++-------
linearize.c | 17 +++--------------
parse.c | 22 +++++++++++++---------
parse.h | 7 +++++--
validation/context.c | 28 ++++++++++++++++++++++++++++
7 files changed, 70 insertions(+), 34 deletions(-)
--- sparse.orig/evaluate.c 2008-04-25 02:15:15.000000000 +0200
+++ sparse/evaluate.c 2008-04-25 12:50:43.000000000 +0200
@@ -3356,7 +3356,14 @@ struct symbol *evaluate_statement(struct
evaluate_asm_statement(stmt);
return NULL;
case STMT_CONTEXT:
- evaluate_expression(stmt->expression);
+ /*
+ * If this is an unknown symbol accept it as-is
+ * as a context name.
+ */
+ if (stmt->context &&
+ (stmt->context->type != EXPR_SYMBOL ||
+ stmt->context->symbol))
+ evaluate_expression(stmt->context);
return NULL;
case STMT_RANGE:
evaluate_expression(stmt->range_expression);
--- sparse.orig/expand.c 2008-04-25 02:15:34.000000000 +0200
+++ sparse/expand.c 2008-04-25 12:50:43.000000000 +0200
@@ -1169,7 +1169,7 @@ static int expand_statement(struct state
/* FIXME! Do the asm parameter evaluation! */
break;
case STMT_CONTEXT:
- expand_expression(stmt->expression);
+ expand_expression(stmt->context);
break;
case STMT_RANGE:
expand_expression(stmt->range_expression);
--- sparse.orig/inline.c 2008-04-25 12:50:08.000000000 +0200
+++ sparse/inline.c 2008-04-25 12:51:35.000000000 +0200
@@ -328,7 +328,18 @@ static struct statement *copy_one_statem
stmt = newstmt;
break;
}
- case STMT_CONTEXT:
+ case STMT_CONTEXT: {
+ struct expression *expr = copy_expression(stmt->context);
+ struct statement *newstmt;
+ if (expr == stmt->context)
+ break;
+ newstmt = dup_statement(stmt);
+ newstmt->context = expr;
+ newstmt->change = stmt->change;
+ newstmt->required = stmt->required;
+ stmt = newstmt;
+ break;
+ }
case STMT_EXPRESSION: {
struct expression *expr = copy_expression(stmt->expression);
struct statement *newstmt;
@@ -336,12 +347,6 @@ static struct statement *copy_one_statem
break;
newstmt = dup_statement(stmt);
newstmt->expression = expr;
- if (stmt->required) {
- expr = copy_expression(stmt->required);
- if (expr == stmt->required)
- break;
- newstmt->required = expr;
- }
stmt = newstmt;
break;
}
--- sparse.orig/linearize.c 2008-04-25 12:50:09.000000000 +0200
+++ sparse/linearize.c 2008-04-25 12:56:35.000000000 +0200
@@ -1735,22 +1735,11 @@ static pseudo_t linearize_inlined_call(s
static pseudo_t linearize_context(struct entrypoint *ep, struct statement *stmt)
{
struct instruction *insn = alloc_instruction(OP_CONTEXT, 0);
- struct expression *expr = stmt->expression;
- int value = 0;
- if (expr->type == EXPR_VALUE)
- value = expr->value;
+ insn->increment = stmt->change;
+ insn->inc_false = stmt->change;
- insn->increment = value;
- insn->inc_false = value;
-
- expr = stmt->required;
- value = 0;
-
- if (expr && expr->type == EXPR_VALUE)
- value = expr->value;
-
- insn->required = value;
+ insn->required = stmt->required;
insn->exact = stmt->exact;
insn->context_expr = stmt->context;
--- sparse.orig/parse.c 2008-04-25 12:50:12.000000000 +0200
+++ sparse/parse.c 2008-04-25 13:09:27.000000000 +0200
@@ -1838,9 +1838,7 @@ static struct token *_parse_context_stat
token = token->next;
}
- stmt->expression = args[0];
stmt->context = NULL;
-
stmt->exact = exact;
switch (argc) {
@@ -1848,21 +1846,27 @@ static struct token *_parse_context_stat
sparse_error(token->pos, "__context__ statement needs argument(s)");
return token;
case 1:
- /* already done */
+ stmt->change = get_expression_value(args[0]);
break;
case 2:
- if (args[0]->type != STMT_EXPRESSION) {
+ /*
+ * We should actually check whether we can evalulate
+ * it as a constant expression and if so use as the
+ * 'change' value. I hope nobody gives a calculation
+ * for the number.
+ */
+ if (args[0]->type != EXPR_VALUE) {
stmt->context = args[0];
- stmt->expression = args[1];
+ stmt->change = get_expression_value(args[1]);
} else {
- stmt->expression = args[0];
- stmt->required = args[1];
+ stmt->change = get_expression_value(args[0]);
+ stmt->required = get_expression_value(args[1]);
}
break;
case 3:
stmt->context = args[0];
- stmt->expression = args[1];
- stmt->required = args[2];
+ stmt->change = get_expression_value(args[1]);
+ stmt->required = get_expression_value(args[2]);
break;
default:
sparse_error(token->pos, "too many arguments for __context__ statement");
--- sparse.orig/parse.h 2008-04-25 12:50:09.000000000 +0200
+++ sparse/parse.h 2008-04-25 12:50:43.000000000 +0200
@@ -39,10 +39,13 @@ struct statement {
struct symbol *label;
struct statement *label_statement;
};
- struct { /* __context__ */
+ struct { /* expression */
struct expression *expression;
+ };
+ struct { /* __context__ */
struct expression *context;
- struct expression *required;
+ int change, required;
+ int exact;
};
struct /* return_statement */ {
struct expression *ret_value;
--- sparse.orig/validation/context.c 2008-04-25 12:50:12.000000000 +0200
+++ sparse/validation/context.c 2008-04-25 13:10:09.000000000 +0200
@@ -380,6 +380,32 @@ static int warn_conditional(void)
return 0;
}
+static void areq(void) __attribute__((context(1,2)))
+{
+ __context__(1,1);
+}
+
+static void good_reqlock(void)
+{
+ a();
+ areq();
+ r();
+ r();
+}
+
+static void warn_reqlock(void)
+{
+ areq();
+ r();
+}
+
+
+static void dummy1(void) __attribute__((context(p,0,1)))
+{
+ void *p;
+ __context__(p,1);
+}
+
/*
* check-name: Check -Wcontext
*
@@ -418,5 +444,7 @@ context.c:360:10: warning: context probl
context.c:360:10: default context: wanted >= 1, got 0
context.c:380:12: warning: context imbalance in 'warn_conditional': wrong count at exit
context.c:380:12: default context: wanted 0, got 1
+context.c:398:6: warning: context problem in 'warn_reqlock': 'areq' expected different context
+context.c:398:6: default context: wanted >= 1, got 0
* check-error-end
*/
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-04-26 15:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-25 11:24 [PATCH] evaluate/expand context expressions Johannes Berg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).