Do not drop 'nocast' modifier when taking the address.
With the following code:
typedef unsigned long __nocast cputime_t;
void task_cputime_adjusted(cputime_t *);
sparse emits the following message:
x.c:16:32: warning: incorrect type in argument 1 (different modifiers)
x.c:16:32: expected unsigned long [nocast] [usertype] *<noident>
x.c:16:32: got unsigned long *<noident>
x.c:16:32: warning: implicit cast to nocast type
In other words, when taking the address of 'utime', sparse drops the 'nocast'
modifier and then complains that task_cputime_adjusted() is not given a
'nocast' pointer as expected ...
This feels wrong to me.
The proposed fix is to simply not dropping the 'nocast' modifier when
taking the address, like done for a normal type qualifier.
This gives very reasonable behaviour for all the test cases I could
- taking the address or dereferencing doesn't drop the nocast
- arithmetic operations on nocast give a nocast result.
- implicit to/from cast is OK only if the base type are the same
- implicit to/from pointer cast is OK only if the base type are the same
This still gives a "leaky" semantic: the nocast modifier can be lost via
an implicit cast to a non-qualified value.
Explicit cast to or from nocast values doesn't give any warning, maybe
it's OK, maybe it's not but it's orthogonal to the current issue.
Is this the wanted semantic for the nocast modifier?
Reported-by: Roman Kagan <firstname.lastname@example.org>
Signed-off-by: Luc Van Oostenryck <email@example.com>
Signed-off-by: Christopher Li <firstname.lastname@example.org>
2 files changed