diff options
author | Vincenzo Frascino <vincenzo.frascino@arm.com> | 2018-08-15 10:55:44 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-09-26 03:34:04 +0200 |
commit | 220d83b94922e67ec912931c94e6346e742c5b8f (patch) | |
tree | 24d010bc0b3cfca9fdfd35893f69a33593549c10 | |
parent | e5cbdb62b0e3dc49244dfbcbe90f5fe5ea370a05 (diff) | |
download | sparse-220d83b94922e67ec912931c94e6346e742c5b8f.tar.gz |
print address space number for cast-from-AS warnings
This patch prints the address space number when a warning
"cast removes address space of expression" is triggered.
This makes easier to discriminate in between different address
spaces.
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | evaluate.c | 2 | ||||
-rw-r--r-- | validation/Waddress-space-all-attr.c | 60 | ||||
-rw-r--r-- | validation/Waddress-space-strict.c | 6 |
3 files changed, 64 insertions, 4 deletions
@@ -3018,7 +3018,7 @@ static struct symbol *evaluate_cast(struct expression *expr) } if (!tas && sas > 0) - warning(expr->pos, "cast removes address space of expression"); + warning(expr->pos, "cast removes address space of expression (<asn:%d>)", sas); if (tas > 0 && sas > 0 && tas != sas) warning(expr->pos, "cast between address spaces (<asn:%d>-><asn:%d>)", sas, tas); if (tas > 0 && !sas && diff --git a/validation/Waddress-space-all-attr.c b/validation/Waddress-space-all-attr.c new file mode 100644 index 00000000..46b70953 --- /dev/null +++ b/validation/Waddress-space-all-attr.c @@ -0,0 +1,60 @@ +/* Resembles include/linux/compiler_types.h */ +#define __kernel __attribute__((address_space(0))) +#define __user __attribute__((address_space(1))) +#define __iomem __attribute__((address_space(2))) +#define __percpu __attribute__((address_space(3))) +#define __rcu __attribute__((address_space(4))) + + +typedef unsigned long ulong; +typedef struct s obj_t; + +static void expl(obj_t __kernel *k, obj_t __iomem *o, + obj_t __user *p, obj_t __percpu *pc, + obj_t __rcu *r) +{ + (ulong)(k); + (void *)(k); + (obj_t*)(k); + (obj_t __kernel*)(k); + + (ulong)(o); + (void *)(o); + (obj_t*)(o); + (obj_t __iomem*)(o); + + (ulong)(p); + (void *)(p); + (obj_t*)(p); + (obj_t __user*)(p); + + (ulong)(pc); + (void *)(pc); + (obj_t*)(pc); + (obj_t __percpu*)(pc); + + (ulong)(r); + (void *)(r); + (obj_t*)(r); + (obj_t __rcu*)(r); +} + +/* + * check-name: Waddress-space-all-attr + * check-command: sparse -Wcast-from-as -Wcast-to-as $file + * + * check-error-start +Waddress-space-all-attr.c:21:10: warning: cast removes address space of expression (<asn:2>) +Waddress-space-all-attr.c:22:10: warning: cast removes address space of expression (<asn:2>) +Waddress-space-all-attr.c:23:10: warning: cast removes address space of expression (<asn:2>) +Waddress-space-all-attr.c:26:10: warning: cast removes address space of expression (<asn:1>) +Waddress-space-all-attr.c:27:10: warning: cast removes address space of expression (<asn:1>) +Waddress-space-all-attr.c:28:10: warning: cast removes address space of expression (<asn:1>) +Waddress-space-all-attr.c:31:10: warning: cast removes address space of expression (<asn:3>) +Waddress-space-all-attr.c:32:10: warning: cast removes address space of expression (<asn:3>) +Waddress-space-all-attr.c:33:10: warning: cast removes address space of expression (<asn:3>) +Waddress-space-all-attr.c:36:10: warning: cast removes address space of expression (<asn:4>) +Waddress-space-all-attr.c:37:10: warning: cast removes address space of expression (<asn:4>) +Waddress-space-all-attr.c:38:10: warning: cast removes address space of expression (<asn:4>) + * check-error-end + */ diff --git a/validation/Waddress-space-strict.c b/validation/Waddress-space-strict.c index 871da282..807965f6 100644 --- a/validation/Waddress-space-strict.c +++ b/validation/Waddress-space-strict.c @@ -30,8 +30,8 @@ static void expl(ulong u, void *v, obj_t *o, obj_t __user *p) Waddress-space-strict.c:9:10: warning: cast adds address space to expression (<asn:1>) Waddress-space-strict.c:12:10: warning: cast adds address space to expression (<asn:1>) Waddress-space-strict.c:17:10: warning: cast adds address space to expression (<asn:1>) -Waddress-space-strict.c:19:10: warning: cast removes address space of expression -Waddress-space-strict.c:20:10: warning: cast removes address space of expression -Waddress-space-strict.c:21:10: warning: cast removes address space of expression +Waddress-space-strict.c:19:10: warning: cast removes address space of expression (<asn:1>) +Waddress-space-strict.c:20:10: warning: cast removes address space of expression (<asn:1>) +Waddress-space-strict.c:21:10: warning: cast removes address space of expression (<asn:1>) * check-error-end */ |