sparse: treat function pointers as pointers to const data
This code snippet:
static void bar(void const *arg)
{
int (*foo)(void) = arg;
}
produces the following warning:
test.c:4:28: warning: incorrect type in initializer (different modifiers)
test.c:4:28: expected int ( *foo )( ... )
test.c:4:28: got void const *arg
which is caused by the fact that the function pointer 'foo' is not annotated
as being a pointer to const data. However, dereferencing a function pointer
does not produce an lvalue, so a function pointer points to const data by
definition, and we should treat it accordingly.
To avoid producing a warning on the inverse case, i.e.,
static void bar(void)
{
void *foo = bar;
}
we only address the case where the function pointer is the target of
an assignment.
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Christopher Li <sparse@chrisli.org>
1 file changed