aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-02-17 10:37:24 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-05-06 16:38:35 +0200
commit1f5c32f43fb1e52fe6a81512b71a539b96ee8c31 (patch)
tree9a6a1c890ef319531b51c590b394314920641e95
parent551b85c8a241bd45b267db152eca4cb01eddce39 (diff)
downloadsparse-dev-1f5c32f43fb1e52fe6a81512b71a539b96ee8c31.tar.gz
use function-like syntax for __range__
One of sparse's extension to the C language is an operator to check ranges. This operator takes 3 operands: the expression to be checked and the bounds. The syntax for this operator is such that the operands need to be a 3-items comma separated expression. This is a bit weird and doesn't play along very well with macros, for example. Change the syntax to a 3-arguments function-like operator. NB. Of course, this will break all existing uses of this extension not using parenthesis around the comma expression but there doesn't seems to be any. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--parse.c5
-rw-r--r--validation/linear/range-op.c31
-rw-r--r--validation/range-syntax.c23
3 files changed, 58 insertions, 1 deletions
diff --git a/parse.c b/parse.c
index bb504d21..4ecf9763 100644
--- a/parse.c
+++ b/parse.c
@@ -2367,11 +2367,14 @@ static struct token *parse_context_statement(struct token *token, struct stateme
static struct token *parse_range_statement(struct token *token, struct statement *stmt)
{
stmt->type = STMT_RANGE;
- token = assignment_expression(token->next, &stmt->range_expression);
+ token = token->next;
+ token = expect(token, '(', "after __range__ statement");
+ token = assignment_expression(token, &stmt->range_expression);
token = expect(token, ',', "after range expression");
token = assignment_expression(token, &stmt->range_low);
token = expect(token, ',', "after low range");
token = assignment_expression(token, &stmt->range_high);
+ token = expect(token, ')', "after range statement");
return expect(token, ';', "after range statement");
}
diff --git a/validation/linear/range-op.c b/validation/linear/range-op.c
new file mode 100644
index 00000000..4472bb33
--- /dev/null
+++ b/validation/linear/range-op.c
@@ -0,0 +1,31 @@
+static void foo(int a)
+{
+ __range__(a, 0, 8);
+}
+
+static void bar(int a, int b, int c)
+{
+ __range__(a, b, c);
+}
+
+/*
+ * check-name: range-op
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+foo:
+.L0:
+ <entry-point>
+ range-check %arg1 between $0..$8
+ ret
+
+
+bar:
+.L2:
+ <entry-point>
+ range-check %arg1 between %arg2..%arg3
+ ret
+
+
+ * check-output-end
+ */
diff --git a/validation/range-syntax.c b/validation/range-syntax.c
new file mode 100644
index 00000000..c43fff0e
--- /dev/null
+++ b/validation/range-syntax.c
@@ -0,0 +1,23 @@
+
+static void ok(int a, int b, int c)
+{
+ __range__(a, 0, 8);
+ __range__(a, b, c);
+}
+
+static void ko(int a, int b, int c)
+{
+ __range__ a, 0, 8;
+ __range__ a, b, c;
+}
+
+/*
+ * check-name: range syntax
+ *
+ * check-error-start
+range-syntax.c:10:19: error: Expected ( after __range__ statement
+range-syntax.c:10:19: error: got a
+range-syntax.c:11:19: error: Expected ( after __range__ statement
+range-syntax.c:11:19: error: got a
+ * check-error-end
+ */