aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-05-23 21:44:00 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-05-26 17:04:29 +0200
commit8e9e4da4790a071c6fa0dd5bf99036c36b5d5fbd (patch)
tree1804895e272f55546e4ab514a222ab26c1377deb /validation
parent6b6daa5c58388e758b51dee97aeacb9944daf9d2 (diff)
downloadsparse-dev-8e9e4da4790a071c6fa0dd5bf99036c36b5d5fbd.tar.gz
context: fix parsing of attribute 'context'
Currently the parsing of the attribute 'context' is rather complex and uses a loop which allows 1, 2, 3 or more arguments. But the the real syntax is only correct for 2 or 3 arguments. Furthermore the parsing mixes calls to expect() with its own error reporting. This is a problem because if the error has first been reported by expect(), the returned token is 'bad_token' which has no position so you can have error logs like: test.c:1:43: error: Expected ( after context attribute test.c:1:43: error: got ) builtin:0:0: error: expected context input/output values But the 'builtin:0.0' should really be 'test.c:1.43' or, even better, there shouldn't be a double error reporting. Fix this by simplifying the parsing and only support 2 or 3 args. Also, make the error messages slightly more explicit about the nature of the error. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
-rw-r--r--validation/attr-context.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/validation/attr-context.c b/validation/attr-context.c
new file mode 100644
index 00000000..00e54c66
--- /dev/null
+++ b/validation/attr-context.c
@@ -0,0 +1,40 @@
+static void a(void) __attribute__((context)); // KO
+static void b(void) __attribute__((context())); // KO
+static void c(void) __attribute__((context 1)); // KO
+static void d(void) __attribute__((context 1,2)); // KO
+static void e(void) __attribute__((context (1))); // !!!!
+static void f(void) __attribute__((context(0))); // !!!!
+static void g(void) __attribute__((context(0,1,2,3))); // KO
+
+static void h(void) __attribute__((context (1,2))); // OK
+static void i(void) __attribute__((context(0,1))); // OK
+static void j(void) __attribute__((context(0,1,2))); // OK
+
+extern int u, v;
+static void x(void) __attribute__((context(0,1,v)));
+static void y(void) __attribute__((context(0,u,1)));
+static void z(void) __attribute__((context(0,u)));
+
+/*
+ * check-name: attr-context
+ *
+ * check-error-start
+attr-context.c:1:43: error: Expected ( after context attribute
+attr-context.c:1:43: error: got )
+attr-context.c:2:44: error: Expected , after context 1st argument
+attr-context.c:2:44: error: got )
+attr-context.c:3:44: error: Expected ( after context attribute
+attr-context.c:3:44: error: got 1
+attr-context.c:4:44: error: Expected ( after context attribute
+attr-context.c:4:44: error: got 1
+attr-context.c:5:46: error: Expected , after context 1st argument
+attr-context.c:5:46: error: got )
+attr-context.c:6:45: error: Expected , after context 1st argument
+attr-context.c:6:45: error: got )
+attr-context.c:7:49: error: Expected ) after context 3rd argument
+attr-context.c:7:49: error: got ,
+attr-context.c:14:48: error: bad constant expression
+attr-context.c:15:46: error: bad constant expression
+attr-context.c:16:46: error: bad constant expression
+ * check-error-end
+ */