* [PATCH] Fix type checking of variadic functions
@ 2016-11-02 17:13 Luc Van Oostenryck
2016-11-17 0:06 ` Christopher Li
0 siblings, 1 reply; 3+ messages in thread
From: Luc Van Oostenryck @ 2016-11-02 17:13 UTC (permalink / raw)
To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck, Al Viro
When doing a type comparison between functions, in the varidicity part,
the base type of these functions (= their return type) is
wrongly used intead of their own type.
Fix this and add some tests showing this and others cases are
now OK
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
CC: Al Viro <viro@zeniv.linux.org.uk>
---
evaluate.c | 2 +-
validation/function-redecl.c | 62 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+), 1 deletion(-)
create mode 100644 validation/function-redecl.c
diff --git a/evaluate.c b/evaluate.c
index e350c0c0..012fa861 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -729,7 +729,7 @@ const char *type_difference(struct ctype *c1, struct ctype *c2,
mod2 = t2->ctype.modifiers;
as2 = t2->ctype.as;
- if (base1->variadic != base2->variadic)
+ if (t1->variadic != t2->variadic)
return "incompatible variadic arguments";
examine_fn_arguments(t1);
examine_fn_arguments(t2);
diff --git a/validation/function-redecl.c b/validation/function-redecl.c
new file mode 100644
index 00000000..7fbceb43
--- /dev/null
+++ b/validation/function-redecl.c
@@ -0,0 +1,62 @@
+#define __user __attribute__((address_space(1)))
+
+
+int ret_type(void);
+void ret_type(void) { } /* check-should-fail */
+
+
+int ret_const(void);
+int const ret_const(void) { return 0; } /* check-should-fail */
+
+
+void *ret_as(void);
+void __user *ret_as(void) { return 0; } /* check-should-fail */
+
+
+void *ret_mod(void);
+void const *ret_mod(void) { return 0; } /* check-should-fail */
+
+
+void arg_type(int a);
+void arg_type(void *a) { } /* check-should-fail */
+
+
+void arg_const(int a);
+void arg_const(const int a) { } /* OK */
+
+
+void arg_as(void *a);
+void arg_as(void __user *a) { } /* check-should-fail */
+
+
+void arg_mod(void *);
+void arg_mod(void const *a) { } /* check-should-fail */
+
+
+void arg_more_arg(int a);
+void arg_more_arg(int a, int b) { } /* check-should-fail */
+
+
+void arg_less_arg(int a, int b);
+void arg_less_arg(int a) { } /* check-should-fail */
+
+
+void arg_vararg(int a);
+void arg_vararg(int a, ...) { } /* check-should-fail */
+
+/*
+ * check-name: function-redecl
+ *
+ * check-error-start
+function-redecl.c:5:6: error: symbol 'ret_type' redeclared with different type (originally declared at function-redecl.c:4) - different base types
+function-redecl.c:9:11: error: symbol 'ret_const' redeclared with different type (originally declared at function-redecl.c:8) - different modifiers
+function-redecl.c:13:13: error: symbol 'ret_as' redeclared with different type (originally declared at function-redecl.c:12) - different address spaces
+function-redecl.c:17:12: error: symbol 'ret_mod' redeclared with different type (originally declared at function-redecl.c:16) - different modifiers
+function-redecl.c:21:6: error: symbol 'arg_type' redeclared with different type (originally declared at function-redecl.c:20) - incompatible argument 1 (different base types)
+function-redecl.c:29:6: error: symbol 'arg_as' redeclared with different type (originally declared at function-redecl.c:28) - incompatible argument 1 (different address spaces)
+function-redecl.c:33:6: error: symbol 'arg_mod' redeclared with different type (originally declared at function-redecl.c:32) - incompatible argument 1 (different modifiers)
+function-redecl.c:37:6: error: symbol 'arg_more_arg' redeclared with different type (originally declared at function-redecl.c:36) - different argument counts
+function-redecl.c:41:6: error: symbol 'arg_less_arg' redeclared with different type (originally declared at function-redecl.c:40) - different argument counts
+function-redecl.c:45:6: error: symbol 'arg_vararg' redeclared with different type (originally declared at function-redecl.c:44) - incompatible variadic arguments
+ * check-error-end
+ */
--
2.10.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix type checking of variadic functions
2016-11-02 17:13 [PATCH] Fix type checking of variadic functions Luc Van Oostenryck
@ 2016-11-17 0:06 ` Christopher Li
2016-11-18 12:30 ` Luc Van Oostenryck
0 siblings, 1 reply; 3+ messages in thread
From: Christopher Li @ 2016-11-17 0:06 UTC (permalink / raw)
To: Luc Van Oostenryck; +Cc: Linux-Sparse, Al Viro
On Thu, Nov 3, 2016 at 1:13 AM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> When doing a type comparison between functions, in the varidicity part,
> the base type of these functions (= their return type) is
> wrongly used intead of their own type.
>
> Fix this and add some tests showing this and others cases are
> now OK
This looks correct to me. The function return type can't be a function.
So the base type of the functions will never have the variadic bit set.
Speaking of the test case, there are two case can be added:
void arg_incomplete();
void arg_incomplete(int a) {} /* check-should-pass */
void arg_incomplete_vararg();
void arg_incomplete_vararg(int a, ...) {} /* check-should-fail */
Sparse handle the first one incorrectly. But that is a separate issue,
we can address it in a different patch.
Will apply.
Chris
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix type checking of variadic functions
2016-11-17 0:06 ` Christopher Li
@ 2016-11-18 12:30 ` Luc Van Oostenryck
0 siblings, 0 replies; 3+ messages in thread
From: Luc Van Oostenryck @ 2016-11-18 12:30 UTC (permalink / raw)
To: Christopher Li; +Cc: Linux-Sparse, Al Viro
On Thu, Nov 17, 2016 at 08:06:41AM +0800, Christopher Li wrote:
> Speaking of the test case, there are two case can be added:
>
> void arg_incomplete();
> void arg_incomplete(int a) {} /* check-should-pass */
>
> void arg_incomplete_vararg();
> void arg_incomplete_vararg(int a, ...) {} /* check-should-fail */
>
> Sparse handle the first one incorrectly. But that is a separate issue,
> we can address it in a different patch.
>
> Will apply.
>
> Chris
> --
Yes. I'll look at this later.
Luc
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-11-18 12:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-02 17:13 [PATCH] Fix type checking of variadic functions Luc Van Oostenryck
2016-11-17 0:06 ` Christopher Li
2016-11-18 12:30 ` Luc Van Oostenryck
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).