Use a function to display the address spaces. This will allow to display a real name instead of '<asn:1>'. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- evaluate.c | 6 +++--- show-parse.c | 13 ++++++++++++- symbol.h | 1 + tokenize.c | 4 ++-- validation/Waddress-space-all-attr.c | 24 ++++++++++++------------ validation/Waddress-space-strict.c | 12 ++++++------ validation/address_space.c | 2 +- validation/ptr-inherit.c | 2 +- 8 files changed, 38 insertions(+), 26 deletions(-) diff --git a/evaluate.c b/evaluate.c index 9c2304a7e..05ea76401 100644 --- a/evaluate.c +++ b/evaluate.c @@ -3018,13 +3018,13 @@ static struct symbol *evaluate_cast(struct expression *expr) } if (!tas && sas > 0) - warning(expr->pos, "cast removes address space of expression (<asn:%d>)", sas); + warning(expr->pos, "cast removes address space '%s' of expression", show_as(sas)); if (tas > 0 && sas > 0 && tas != sas) - warning(expr->pos, "cast between address spaces (<asn:%d>-><asn:%d>)", sas, tas); + warning(expr->pos, "cast between address spaces (%s -> %s)", show_as(sas), show_as(tas)); if (tas > 0 && !sas && !is_null_pointer_constant(source) && Wcast_to_as) warning(expr->pos, - "cast adds address space to expression (<asn:%d>)", tas); + "cast adds address space '%s' to expression", show_as(tas)); if (!(ttype->ctype.modifiers & MOD_PTRINHERIT) && tclass == TYPE_PTR && !tas && (source->flags & CEF_ICE)) { diff --git a/show-parse.c b/show-parse.c index 6328439c9..ae098c285 100644 --- a/show-parse.c +++ b/show-parse.c @@ -182,6 +182,17 @@ void show_symbol_list(struct symbol_list *list, const char *sep) } END_FOR_EACH_PTR(sym); } +const char *show_as(unsigned int as) +{ + static char buffer[4][32]; + static int n; + char *buff; + + buff = buffer[3 & ++n]; + sprintf(buff, "<asn:%u>", as); + return buff; +} + struct type_name { char *start; char *end; @@ -288,7 +299,7 @@ deeper: size_t len; if (as) - prepend(name, "<asn:%d>", as); + prepend(name, "%s ", show_as(as)); s = modifier_string(mod); len = strlen(s); diff --git a/symbol.h b/symbol.h index 5a3d7cef5..b8e0cac82 100644 --- a/symbol.h +++ b/symbol.h @@ -315,6 +315,7 @@ extern void bind_symbol(struct symbol *, struct ident *, enum namespace); extern struct symbol *examine_symbol_type(struct symbol *); extern struct symbol *examine_pointer_target(struct symbol *); +extern const char *show_as(unsigned int as); extern const char *show_typename(struct symbol *sym); extern const char *builtin_typename(struct symbol *sym); extern const char *builtin_ctypename(struct ctype *ctype); diff --git a/tokenize.c b/tokenize.c index 01fbb9b35..95fbc2a06 100644 --- a/tokenize.c +++ b/tokenize.c @@ -88,13 +88,13 @@ const char *show_special(int val) const char *show_ident(const struct ident *ident) { - static char buff[2][256]; + static char buff[4][256]; static int n; char *buffer; if (!ident) return "<noident>"; - buffer = buff[2 & ++n]; + buffer = buff[3 & ++n]; sprintf(buffer, "%.*s", ident->len, ident->name); return buffer; } diff --git a/validation/Waddress-space-all-attr.c b/validation/Waddress-space-all-attr.c index 46b709532..5b2d0f92f 100644 --- a/validation/Waddress-space-all-attr.c +++ b/validation/Waddress-space-all-attr.c @@ -44,17 +44,17 @@ static void expl(obj_t __kernel *k, obj_t __iomem *o, * 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>) +Waddress-space-all-attr.c:21:10: warning: cast removes address space '<asn:2>' of expression +Waddress-space-all-attr.c:22:10: warning: cast removes address space '<asn:2>' of expression +Waddress-space-all-attr.c:23:10: warning: cast removes address space '<asn:2>' of expression +Waddress-space-all-attr.c:26:10: warning: cast removes address space '<asn:1>' of expression +Waddress-space-all-attr.c:27:10: warning: cast removes address space '<asn:1>' of expression +Waddress-space-all-attr.c:28:10: warning: cast removes address space '<asn:1>' of expression +Waddress-space-all-attr.c:31:10: warning: cast removes address space '<asn:3>' of expression +Waddress-space-all-attr.c:32:10: warning: cast removes address space '<asn:3>' of expression +Waddress-space-all-attr.c:33:10: warning: cast removes address space '<asn:3>' of expression +Waddress-space-all-attr.c:36:10: warning: cast removes address space '<asn:4>' of expression +Waddress-space-all-attr.c:37:10: warning: cast removes address space '<asn:4>' of expression +Waddress-space-all-attr.c:38:10: warning: cast removes address space '<asn:4>' of expression * check-error-end */ diff --git a/validation/Waddress-space-strict.c b/validation/Waddress-space-strict.c index 807965f6e..7987eb1db 100644 --- a/validation/Waddress-space-strict.c +++ b/validation/Waddress-space-strict.c @@ -27,11 +27,11 @@ static void expl(ulong u, void *v, obj_t *o, obj_t __user *p) * check-command: sparse -Wcast-from-as -Wcast-to-as $file * * check-error-start -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 (<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>) +Waddress-space-strict.c:9:10: warning: cast adds address space '<asn:1>' to expression +Waddress-space-strict.c:12:10: warning: cast adds address space '<asn:1>' to expression +Waddress-space-strict.c:17:10: warning: cast adds address space '<asn:1>' to expression +Waddress-space-strict.c:19:10: warning: cast removes address space '<asn:1>' of expression +Waddress-space-strict.c:20:10: warning: cast removes address space '<asn:1>' of expression +Waddress-space-strict.c:21:10: warning: cast removes address space '<asn:1>' of expression * check-error-end */ diff --git a/validation/address_space.c b/validation/address_space.c index c55b78df0..a0c8bf5d1 100644 --- a/validation/address_space.c +++ b/validation/address_space.c @@ -12,6 +12,6 @@ static int sys_do_stuff(void __user *user_addr) * check-error-start address_space.c:7:28: warning: incorrect type in argument 1 (different address spaces) address_space.c:7:28: expected void *addr -address_space.c:7:28: got void <asn:1>*user_addr +address_space.c:7:28: got void <asn:1> *user_addr * check-error-end */ diff --git a/validation/ptr-inherit.c b/validation/ptr-inherit.c index 58524a717..873305676 100644 --- a/validation/ptr-inherit.c +++ b/validation/ptr-inherit.c @@ -75,6 +75,6 @@ ptr-inherit.c:30:19: expected int *p ptr-inherit.c:30:19: got restricted int *<noident> ptr-inherit.c:36:19: warning: incorrect type in initializer (different address spaces) ptr-inherit.c:36:19: expected int *p -ptr-inherit.c:36:19: got int <asn:1>*<noident> +ptr-inherit.c:36:19: got int <asn:1> *<noident> * check-error-end */ -- 2.19.0