bogus_address_param: warn about passing a bogus address
[smatch.git] / test-dissect.c
blob65b205f841c979e9cc7976a2a7c59fc1b65e5edf
1 #include "dissect.h"
3 static inline const char *show_mode(unsigned mode)
5 static char str[3];
7 if (mode == -1)
8 return "def";
10 #define U(u_r) "-rwm"[(mode / u_r) & 3]
11 str[0] = U(U_R_AOF);
12 str[1] = U(U_R_VAL);
13 str[2] = U(U_R_PTR);
14 #undef U
16 return str;
19 static void print_usage(struct position *pos, struct symbol *sym, unsigned mode)
21 static unsigned curr_stream = -1;
22 static struct ident null;
23 struct ident *ctx = &null;
25 if (curr_stream != pos->stream) {
26 curr_stream = pos->stream;
27 printf("\nFILE: %s\n\n", stream_name(curr_stream));
30 if (dissect_ctx)
31 ctx = dissect_ctx->ident;
33 printf("%4d:%-3d %-16.*s %s ",
34 pos->line, pos->pos, ctx->len, ctx->name, show_mode(mode));
38 static char symscope(struct symbol *sym)
40 if (sym_is_local(sym)) {
41 if (!dissect_ctx)
42 warning(sym->pos, "no context");
43 return '.';
45 return ' ';
48 static void r_symbol(unsigned mode, struct position *pos, struct symbol *sym)
50 print_usage(pos, sym, mode);
52 if (!sym->ident)
53 sym->ident = built_in_ident("__asm__");
55 printf("%c %c %-32.*s %s\n",
56 symscope(sym), sym->kind, sym->ident->len, sym->ident->name,
57 show_typename(sym->ctype.base_type));
59 switch (sym->kind) {
60 case 'd':
61 break;
62 case 's':
63 if (sym->type == SYM_STRUCT || sym->type == SYM_UNION)
64 break;
65 goto err;
66 case 't':
67 break;
68 case 'f':
69 if (sym->type != SYM_BAD && sym->ctype.base_type->type != SYM_FN)
70 goto err;
71 case 'v':
72 if (sym->type == SYM_NODE || sym->type == SYM_BAD)
73 break;
74 goto err;
75 default:
76 goto err;
79 return;
80 err:
81 warning(*pos, "r_symbol bad sym type=%d kind=%d", sym->type, sym->kind);
84 static void r_member(unsigned mode, struct position *pos, struct symbol *sym, struct symbol *mem)
86 struct ident *ni, *si, *mi;
88 print_usage(pos, sym, mode);
90 ni = built_in_ident("?");
91 si = sym->ident ?: ni;
92 /* mem == NULL means entire struct accessed */
93 mi = mem ? (mem->ident ?: ni) : built_in_ident("*");
95 printf("%c m %.*s.%-*.*s %s\n",
96 symscope(sym), si->len, si->name,
97 32-1 - si->len, mi->len, mi->name,
98 show_typename(mem ? mem->ctype.base_type : sym));
100 if (sym->ident && sym->kind != 's')
101 warning(*pos, "r_member bad sym type=%d kind=%d", sym->type, sym->kind);
102 if (mem && mem->kind != 'm')
103 warning(*pos, "r_member bad mem->kind = %d", mem->kind);
106 static void r_symdef(struct symbol *sym)
108 r_symbol(-1, &sym->pos, sym);
111 static void r_memdef(struct symbol *sym, struct symbol *mem)
113 r_member(-1, &mem->pos, sym, mem);
116 int main(int argc, char **argv)
118 static struct reporter reporter = {
119 .r_symdef = r_symdef,
120 .r_memdef = r_memdef,
121 .r_symbol = r_symbol,
122 .r_member = r_member,
125 struct string_list *filelist = NULL;
126 sparse_initialize(argc, argv, &filelist);
127 dissect(&reporter, filelist);
129 return 0;