From: Vincenzo Frascino <vincenzo.frascino@xxxxxxx> 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@xxxxxxx> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- evaluate.c | 2 +- validation/Waddress-space-all-attr.c | 84 ++++++++++++++++++++++++++++ validation/Waddress-space-strict.c | 10 ++-- 3 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 validation/Waddress-space-all-attr.c diff --git a/evaluate.c b/evaluate.c index 6d5d4793f..9c2304a7e 100644 --- a/evaluate.c +++ b/evaluate.c @@ -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 000000000..be60451a1 --- /dev/null +++ b/validation/Waddress-space-all-attr.c @@ -0,0 +1,84 @@ +/* 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 long long llong; +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) +{ + (int)(k); + (ulong)(k); + (llong)(k); + (void *)(k); + (obj_t*)(k); + (obj_t __kernel*)(k); + + (int)(o); + (ulong)(o); + (llong)(o); + (void *)(o); + (obj_t*)(o); + (obj_t __iomem*)(o); + + (int)(p); + (ulong)(p); + (llong)(p); + (void *)(p); + (obj_t*)(p); + (obj_t __user*)(p); + + (int)(pc); + (ulong)(pc); + (llong)(pc); + (void *)(pc); + (obj_t*)(pc); + (obj_t __percpu*)(pc); + + (int)(r); + (ulong)(r); + (llong)(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:24:10: warning: cast removes address space of expression (<asn:2>) +Waddress-space-all-attr.c:25: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:2>) +Waddress-space-all-attr.c:27:10: warning: cast removes address space of expression (<asn:2>) +Waddress-space-all-attr.c:28:10: warning: cast removes address space of expression (<asn:2>) +Waddress-space-all-attr.c:31:10: warning: cast removes address space of expression (<asn:1>) +Waddress-space-all-attr.c:32:10: warning: cast removes address space of expression (<asn:1>) +Waddress-space-all-attr.c:33:10: warning: cast removes address space of expression (<asn:1>) +Waddress-space-all-attr.c:34:10: warning: cast removes address space of expression (<asn:1>) +Waddress-space-all-attr.c:35:10: warning: cast removes address space of expression (<asn:1>) +Waddress-space-all-attr.c:38:10: warning: cast removes address space of expression (<asn:3>) +Waddress-space-all-attr.c:39:10: warning: cast removes address space of expression (<asn:3>) +Waddress-space-all-attr.c:40:10: warning: cast removes address space of expression (<asn:3>) +Waddress-space-all-attr.c:41:10: warning: cast removes address space of expression (<asn:3>) +Waddress-space-all-attr.c:42:10: warning: cast removes address space of expression (<asn:3>) +Waddress-space-all-attr.c:45:10: warning: cast removes address space of expression (<asn:4>) +Waddress-space-all-attr.c:46:10: warning: cast removes address space of expression (<asn:4>) +Waddress-space-all-attr.c:47:10: warning: cast removes address space of expression (<asn:4>) +Waddress-space-all-attr.c:48:10: warning: cast removes address space of expression (<asn:4>) +Waddress-space-all-attr.c:49:10: warning: cast removes address space of expression (<asn:4>) +Waddress-space-all-attr.c:17:15: warning: non size-preserving pointer to integer cast +Waddress-space-all-attr.c:24:15: warning: non size-preserving pointer to integer cast +Waddress-space-all-attr.c:31:15: warning: non size-preserving pointer to integer cast +Waddress-space-all-attr.c:38:15: warning: non size-preserving pointer to integer cast +Waddress-space-all-attr.c:45:15: warning: non size-preserving pointer to integer cast + * check-error-end + */ diff --git a/validation/Waddress-space-strict.c b/validation/Waddress-space-strict.c index 5071aab26..4ea20fae6 100644 --- a/validation/Waddress-space-strict.c +++ b/validation/Waddress-space-strict.c @@ -43,11 +43,11 @@ Waddress-space-strict.c:13:10: warning: cast adds address space to expression (< Waddress-space-strict.c:16:10: warning: cast adds address space to expression (<asn:1>) Waddress-space-strict.c:19:10: warning: cast adds address space to expression (<asn:1>) Waddress-space-strict.c:26:10: warning: cast adds address space to expression (<asn:1>) -Waddress-space-strict.c:28:10: warning: cast removes address space of expression -Waddress-space-strict.c:29:10: warning: cast removes address space of expression -Waddress-space-strict.c:30:10: warning: cast removes address space of expression -Waddress-space-strict.c:31:10: warning: cast removes address space of expression -Waddress-space-strict.c:32:10: warning: cast removes address space of expression +Waddress-space-strict.c:28:10: warning: cast removes address space of expression (<asn:1>) +Waddress-space-strict.c:29:10: warning: cast removes address space of expression (<asn:1>) +Waddress-space-strict.c:30:10: warning: cast removes address space of expression (<asn:1>) +Waddress-space-strict.c:31:10: warning: cast removes address space of expression (<asn:1>) +Waddress-space-strict.c:32:10: warning: cast removes address space of expression (<asn:1>) Waddress-space-strict.c:9:18: warning: non size-preserving integer to pointer cast Waddress-space-strict.c:10:25: warning: non size-preserving integer to pointer cast Waddress-space-strict.c:21:15: warning: non size-preserving pointer to integer cast -- 2.18.0