1
2#define __kernel __attribute__((address_space(0)))
3#define __user   __attribute__((address_space(__user)))
4#define __iomem  __attribute__((address_space(__iomem)))
5#define __percpu __attribute__((address_space(__percpu)))
6#define __rcu    __attribute__((address_space(__rcu)))
7
8
9typedef struct s obj_t;
10
11static void expl(obj_t __kernel *k, obj_t __iomem *o,
12		 obj_t __user *p, obj_t __percpu *pc,
13		 obj_t __rcu *r)
14{
15	(__UINTPTR_TYPE__)(k);	// OK
16	(unsigned long)(k);	// OK
17	(void *)(k);		// OK
18	(obj_t*)(k);		// OK
19	(obj_t __kernel*)(k);	// OK
20
21	(__UINTPTR_TYPE__)(o);	// OK
22	(unsigned long)(o);	// OK
23	(void *)(o);
24	(obj_t*)(o);
25	(obj_t __iomem*)(o);	// OK
26
27	(__UINTPTR_TYPE__)(p);	// OK
28	(unsigned long)(p);	// OK
29	(void *)(p);
30	(obj_t*)(p);
31	(obj_t __user*)(p);	// OK
32
33	(__UINTPTR_TYPE__)(pc);	// OK
34	(unsigned long)(pc);	// OK
35	(void *)(pc);
36	(obj_t*)(pc);
37	(obj_t __percpu*)(pc);	// OK
38
39	(__UINTPTR_TYPE__)(r);	// OK
40	(unsigned long)(r);	// OK
41	(void *)(r);
42	(obj_t*)(r);
43	(obj_t __rcu*)(r);	// OK
44}
45
46/*
47 * check-name: Waddress-space-from
48 * check-command: sparse -Wno-cast-from-as $file
49 * check-description: Test the removal of AS from a pointer but only
50 *	in the non-strict variant where casts to ulong (or uintptr_t)
51 *	are allowed.
52 *
53 * check-error-start
54Waddress-space-from.c:23:10: warning: cast removes address space '__iomem' of expression
55Waddress-space-from.c:24:10: warning: cast removes address space '__iomem' of expression
56Waddress-space-from.c:29:10: warning: cast removes address space '__user' of expression
57Waddress-space-from.c:30:10: warning: cast removes address space '__user' of expression
58Waddress-space-from.c:35:10: warning: cast removes address space '__percpu' of expression
59Waddress-space-from.c:36:10: warning: cast removes address space '__percpu' of expression
60Waddress-space-from.c:41:10: warning: cast removes address space '__rcu' of expression
61Waddress-space-from.c:42:10: warning: cast removes address space '__rcu' of expression
62 * check-error-end
63 */
64