4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
15 #include "smatch_slist.h"
16 #include "smatch_extra.h"
19 static sqlite3
*mem_db
;
21 #define sql_insert(table, values...) \
25 char *err, *p = buf; \
28 p += snprintf(p, buf + sizeof(buf) - p, \
29 "insert into %s values (", #table); \
30 p += snprintf(p, buf + sizeof(buf) - p, values); \
31 p += snprintf(p, buf + sizeof(buf) - p, ");"); \
32 rc = sqlite3_exec(mem_db, buf, NULL, 0, &err); \
33 if (rc != SQLITE_OK) { \
34 fprintf(stderr, "SQL error #2: %s\n", err); \
35 fprintf(stderr, "SQL: '%s'\n", buf); \
41 sm_printf("SQL: insert into " #table " values (" values); \
48 void (*callback
)(const char *name
, struct symbol
*sym
, char *key
, char *value
);
50 ALLOCATOR(def_callback
, "definition db hook callbacks");
51 DECLARE_PTR_LIST(callback_list
, struct def_callback
);
52 static struct callback_list
*callbacks
;
54 struct member_info_callback
{
56 void (*callback
)(struct expression
*call
, int param
, char *printed_name
, struct smatch_state
*state
);
58 ALLOCATOR(member_info_callback
, "caller_info callbacks");
59 DECLARE_PTR_LIST(member_info_cb_list
, struct member_info_callback
);
60 static struct member_info_cb_list
*member_callbacks
;
62 struct returned_state_callback
{
63 void (*callback
)(int return_id
, char *return_ranges
, struct expression
*return_expr
, struct state_list
*slist
);
65 ALLOCATOR(returned_state_callback
, "returned state callbacks");
66 DECLARE_PTR_LIST(returned_state_cb_list
, struct returned_state_callback
);
67 static struct returned_state_cb_list
*returned_state_callbacks
;
69 struct returned_member_callback
{
71 void (*callback
)(int return_id
, char *return_ranges
, char *printed_name
, struct smatch_state
*state
);
73 ALLOCATOR(returned_member_callback
, "returned member callbacks");
74 DECLARE_PTR_LIST(returned_member_cb_list
, struct returned_member_callback
);
75 static struct returned_member_cb_list
*returned_member_callbacks
;
77 struct call_implies_callback
{
79 void (*callback
)(struct expression
*arg
, char *value
);
81 ALLOCATOR(call_implies_callback
, "call_implies callbacks");
82 DECLARE_PTR_LIST(call_implies_cb_list
, struct call_implies_callback
);
83 static struct call_implies_cb_list
*call_implies_cb_list
;
85 void sql_exec(int (*callback
)(void*, int, char**, char**), const char *sql
)
90 if (option_no_db
|| !db
)
93 rc
= sqlite3_exec(db
, sql
, callback
, 0, &err
);
94 if (rc
!= SQLITE_OK
) {
95 fprintf(stderr
, "SQL error #2: %s\n", err
);
96 fprintf(stderr
, "SQL: '%s'\n", sql
);
100 void sql_insert_return_states(int return_id
, const char *return_ranges
,
101 int type
, int param
, const char *key
, const char *value
)
103 sql_insert(return_states
, "'%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s'",
104 get_filename(), get_function(), return_id
, return_ranges
,
105 fn_static(), type
, param
, key
, value
);
108 void sql_insert_caller_info(struct expression
*call
, int type
,
109 int param
, const char *key
, const char *value
)
113 if (!option_info
&& !__inline_call
)
116 fn
= get_fnptr_name(call
->fn
);
125 snprintf(buf
, sizeof(buf
), "insert into caller_info values ("
126 "'%s', '%s', '%s', %lu, %d, %d, %d, '%s', '%s');",
127 get_filename(), get_function(), fn
,
128 (unsigned long)call
, is_static(call
->fn
), type
, param
,
130 rc
= sqlite3_exec(mem_db
, buf
, NULL
, 0, &err
);
131 if (rc
!= SQLITE_OK
) {
132 fprintf(stderr
, "SQL error #2: %s\n", err
);
133 fprintf(stderr
, "SQL: '%s'\n", buf
);
138 sm_msg("SQL_caller_info: insert into caller_info values ("
139 "'%s', '%s', '%s', %%FUNC_ID%%, %d, %d, %d, '%s', '%s');",
140 get_filename(), get_function(), fn
, is_static(call
->fn
),
141 type
, param
, key
, value
);
146 void sql_insert_function_ptr(const char *fn
, const char *struct_name
)
148 sql_insert(function_ptr
, "'%s', '%s', '%s'", get_filename(), fn
,
152 void sql_insert_return_values(const char *return_values
)
154 sql_insert(return_values
, "'%s', '%s', %d, '%s'", get_filename(),
155 get_function(), fn_static(), return_values
);
158 void sql_insert_call_implies(int type
, int param
, int value
)
160 sql_insert(call_implies
, "'%s', '%s', %d, %d, %d, %d", get_filename(),
161 get_function(), fn_static(), type
, param
, value
);
164 void sql_insert_type_size(const char *member
, int size
)
166 sql_insert(type_size
, "'%s', '%s', %d", get_filename(), member
, size
);
169 void add_definition_db_callback(void (*callback
)(const char *name
, struct symbol
*sym
, char *key
, char *value
), int type
)
171 struct def_callback
*def_callback
= __alloc_def_callback(0);
173 def_callback
->hook_type
= type
;
174 def_callback
->callback
= callback
;
175 add_ptr_list(&callbacks
, def_callback
);
179 * These call backs are used when the --info option is turned on to print struct
180 * member information. For example foo->bar could have a state in
181 * smatch_extra.c and also check_user.c.
183 void add_member_info_callback(int owner
, void (*callback
)(struct expression
*call
, int param
, char *printed_name
, struct smatch_state
*state
))
185 struct member_info_callback
*member_callback
= __alloc_member_info_callback(0);
187 member_callback
->owner
= owner
;
188 member_callback
->callback
= callback
;
189 add_ptr_list(&member_callbacks
, member_callback
);
192 void add_returned_state_callback(void (*fn
)(int return_id
, char *return_ranges
, struct expression
*returned_expr
, struct state_list
*slist
))
194 struct returned_state_callback
*callback
= __alloc_returned_state_callback(0);
196 callback
->callback
= fn
;
197 add_ptr_list(&returned_state_callbacks
, callback
);
200 void add_returned_member_callback(int owner
, void (*callback
)(int return_id
, char *return_ranges
, char *printed_name
, struct smatch_state
*state
))
202 struct returned_member_callback
*member_callback
= __alloc_returned_member_callback(0);
204 member_callback
->owner
= owner
;
205 member_callback
->callback
= callback
;
206 add_ptr_list(&returned_member_callbacks
, member_callback
);
209 void add_db_fn_call_callback(int type
, void (*callback
)(struct expression
*arg
, char *value
))
211 struct call_implies_callback
*cb
= __alloc_call_implies_callback(0);
214 cb
->callback
= callback
;
215 add_ptr_list(&call_implies_cb_list
, cb
);
218 static struct symbol
*return_type
;
219 static struct range_list
*return_range_list
;
220 static int db_return_callback(void *unused
, int argc
, char **argv
, char **azColName
)
225 sm_msg("return type %d", type_positive_bits(return_type
));
226 str_to_rl(return_type
, argv
[0], &return_range_list
);
230 struct range_list
*db_return_vals(struct expression
*expr
)
233 static char sql_filter
[1024];
235 if (expr
->type
!= EXPR_CALL
)
237 if (expr
->fn
->type
!= EXPR_SYMBOL
)
239 return_type
= get_type(expr
);
242 sym
= expr
->fn
->symbol
;
246 if (sym
->ctype
.modifiers
& MOD_STATIC
) {
247 snprintf(sql_filter
, 1024, "file = '%s' and function = '%s';",
248 get_filename(), sym
->ident
->name
);
250 snprintf(sql_filter
, 1024, "function = '%s' and static = 0;",
254 return_range_list
= NULL
;
255 run_sql(db_return_callback
, "select return from return_values where %s",
257 return return_range_list
;
260 static void match_call_marker(struct expression
*expr
)
263 * we just want to record something in the database so that if we have
264 * two calls like: frob(4); frob(some_unkown); then on the receiving
265 * side we know that sometimes frob is called with unknown parameters.
268 sql_insert_caller_info(expr
, INTERNAL
, -1, "%call_marker%", "");
271 static void print_struct_members(struct expression
*call
, struct expression
*expr
, int param
, struct state_list
*slist
,
272 void (*callback
)(struct expression
*call
, int param
, char *printed_name
, struct smatch_state
*state
))
278 char printed_name
[256];
281 expr
= strip_expr(expr
);
282 if (expr
->type
== EXPR_PREOP
&& expr
->op
== '&') {
283 expr
= strip_expr(expr
->unop
);
287 name
= expr_to_var_sym(expr
, &sym
);
292 FOR_EACH_PTR(slist
, sm
) {
295 if (strncmp(name
, sm
->name
, len
) || sm
->name
[len
] == '\0')
298 snprintf(printed_name
, sizeof(printed_name
), "$$->%s", sm
->name
+ len
+ 1);
300 snprintf(printed_name
, sizeof(printed_name
), "$$%s", sm
->name
+ len
);
301 callback(call
, param
, printed_name
, sm
->state
);
302 } END_FOR_EACH_PTR(sm
);
307 static void match_call_info(struct expression
*call
)
309 struct member_info_callback
*cb
;
310 struct expression
*arg
;
311 struct state_list
*slist
;
315 name
= get_fnptr_name(call
->fn
);
319 FOR_EACH_PTR(member_callbacks
, cb
) {
320 slist
= get_all_states(cb
->owner
);
322 FOR_EACH_PTR(call
->args
, arg
) {
323 print_struct_members(call
, arg
, i
, slist
, cb
->callback
);
325 } END_FOR_EACH_PTR(arg
);
327 } END_FOR_EACH_PTR(cb
);
332 static int get_param(int param
, char **name
, struct symbol
**sym
)
338 FOR_EACH_PTR(cur_func_sym
->ctype
.base_type
->arguments
, arg
) {
340 * this is a temporary hack to work around a bug (I think in sparse?)
341 * 2.6.37-rc1:fs/reiserfs/journal.o
342 * If there is a function definition without parameter name found
343 * after a function implementation then it causes a crash.
347 if (arg
->ident
->name
< (char *)100)
349 if (i
== param
&& arg
->ident
->name
) {
350 *name
= arg
->ident
->name
;
355 } END_FOR_EACH_PTR(arg
);
360 static struct state_list
*final_states
;
361 static int prev_func_id
= -1;
362 static int db_callback(void *unused
, int argc
, char **argv
, char **azColName
)
368 struct symbol
*sym
= NULL
;
369 struct def_callback
*def_callback
;
374 func_id
= atoi(argv
[0]);
376 type
= strtol(argv
[1], NULL
, 10);
377 param
= strtol(argv
[2], NULL
, 10);
381 if (prev_func_id
== -1)
382 prev_func_id
= func_id
;
383 if (func_id
!= prev_func_id
) {
384 merge_slist(&final_states
, __pop_fake_cur_slist());
385 __push_fake_cur_slist();
387 prev_func_id
= func_id
;
390 if (type
== INTERNAL
)
392 if (param
>= 0 && !get_param(param
, &name
, &sym
))
395 FOR_EACH_PTR(callbacks
, def_callback
) {
396 if (def_callback
->hook_type
== type
)
397 def_callback
->callback(name
, sym
, argv
[3], argv
[4]);
398 } END_FOR_EACH_PTR(def_callback
);
403 static void get_direct_callers(struct symbol
*sym
)
405 char sql_filter
[1024];
407 if (sym
->ctype
.modifiers
& MOD_STATIC
) {
408 snprintf(sql_filter
, 1024,
409 "file = '%s' and function = '%s' order by function_id;",
410 get_filename(), sym
->ident
->name
);
412 snprintf(sql_filter
, 1024,
413 "function = '%s' and static = 0 order by function_id;",
417 run_sql(db_callback
, "select function_id, type, parameter, key, value from caller_info"
418 " where %s", sql_filter
);
421 static char *ptr_name
;
422 static int get_ptr_name(void *unused
, int argc
, char **argv
, char **azColName
)
425 ptr_name
= alloc_string(argv
[0]);
429 static void get_function_pointer_callers(struct symbol
*sym
)
431 char sql_filter
[1024];
433 if (sym
->ctype
.modifiers
& MOD_STATIC
) {
434 snprintf(sql_filter
, 1024, "file = '%s' and function = '%s';",
435 get_filename(), sym
->ident
->name
);
437 snprintf(sql_filter
, 1024, "function = '%s';",
442 run_sql(get_ptr_name
, "select ptr from function_ptr where %s", sql_filter
);
446 run_sql(db_callback
, "select function_id, type, parameter, key, value from caller_info"
447 " where function = '%s' order by function_id", ptr_name
);
449 free_string(ptr_name
);
452 static void match_data_from_db(struct symbol
*sym
)
456 if (!sym
|| !sym
->ident
|| !sym
->ident
->name
)
459 __push_fake_cur_slist();
463 get_direct_callers(sym
);
464 get_function_pointer_callers(sym
);
466 merge_slist(&final_states
, __pop_fake_cur_slist());
468 FOR_EACH_PTR(final_states
, sm
) {
470 } END_FOR_EACH_PTR(sm
);
472 free_slist(&final_states
);
475 static void match_function_assign(struct expression
*expr
)
477 struct expression
*right
= expr
->right
;
482 if (right
->type
== EXPR_PREOP
&& right
->op
== '&')
483 right
= strip_expr(right
->unop
);
484 if (right
->type
!= EXPR_SYMBOL
)
486 sym
= get_type(right
);
487 if (!sym
|| sym
->type
!= SYM_FN
)
490 fn_name
= expr_to_var(right
);
491 ptr_name
= get_fnptr_name(expr
->left
);
492 if (!fn_name
|| !ptr_name
)
495 sql_insert_function_ptr(fn_name
, ptr_name
);
498 free_string(fn_name
);
499 free_string(ptr_name
);
502 static struct expression
*call_implies_call_expr
;
503 static int call_implies_callbacks(void *unused
, int argc
, char **argv
, char **azColName
)
505 struct call_implies_callback
*cb
;
506 struct expression
*arg
= NULL
;
513 type
= atoi(argv
[1]);
514 param
= atoi(argv
[2]);
516 FOR_EACH_PTR(call_implies_cb_list
, cb
) {
517 if (cb
->type
!= type
)
520 arg
= get_argument_from_call_expr(call_implies_call_expr
->args
, param
);
524 cb
->callback(arg
, argv
[3]);
525 } END_FOR_EACH_PTR(cb
);
530 static void match_call_implies(struct expression
*expr
)
533 static char sql_filter
[1024];
535 if (expr
->fn
->type
!= EXPR_SYMBOL
)
537 sym
= expr
->fn
->symbol
;
541 if (sym
->ctype
.modifiers
& MOD_STATIC
) {
542 snprintf(sql_filter
, 1024, "file = '%s' and function = '%s';",
543 get_filename(), sym
->ident
->name
);
545 snprintf(sql_filter
, 1024, "function = '%s' and static = 0;",
549 call_implies_call_expr
= expr
;
550 run_sql(call_implies_callbacks
,
551 "select function, type, parameter, value from call_implies where %s",
556 static void print_initializer_list(struct expression_list
*expr_list
,
557 struct symbol
*struct_type
)
559 struct expression
*expr
;
560 struct symbol
*base_type
;
561 char struct_name
[256];
563 FOR_EACH_PTR(expr_list
, expr
) {
564 if (expr
->type
== EXPR_INDEX
&& expr
->idx_expression
&& expr
->idx_expression
->type
== EXPR_INITIALIZER
) {
565 print_initializer_list(expr
->idx_expression
->expr_list
, struct_type
);
568 if (expr
->type
!= EXPR_IDENTIFIER
)
570 if (!expr
->expr_ident
)
572 if (!expr
->ident_expression
|| !expr
->ident_expression
->symbol_name
)
574 base_type
= get_type(expr
->ident_expression
);
575 if (!base_type
|| base_type
->type
!= SYM_FN
)
577 snprintf(struct_name
, sizeof(struct_name
), "(struct %s)->%s",
578 struct_type
->ident
->name
, expr
->expr_ident
->name
);
579 sql_insert_function_ptr(expr
->ident_expression
->symbol_name
->name
,
581 } END_FOR_EACH_PTR(expr
);
584 static void global_variable(struct symbol
*sym
)
586 struct symbol
*struct_type
;
590 if (!sym
->initializer
|| sym
->initializer
->type
!= EXPR_INITIALIZER
)
592 struct_type
= get_base_type(sym
);
595 if (struct_type
->type
== SYM_ARRAY
) {
596 struct_type
= get_base_type(struct_type
);
600 if (struct_type
->type
!= SYM_STRUCT
|| !struct_type
->ident
)
602 print_initializer_list(sym
->initializer
->expr_list
, struct_type
);
605 static void match_return_info(int return_id
, char *return_ranges
, struct expression
*expr
, struct state_list
*slist
)
607 sql_insert_return_states(return_id
, return_ranges
, INTERNAL
, -1, "", "");
610 static int return_id
;
611 static void match_function_def(struct symbol
*sym
)
616 static void call_return_state_hooks_compare(struct expression
*expr
)
618 struct returned_state_callback
*cb
;
619 struct state_list
*slist
;
621 int final_pass_orig
= final_pass
;
623 __push_fake_cur_slist();
626 __split_whole_condition(expr
);
627 final_pass
= final_pass_orig
;
629 return_ranges
= alloc_sname("1");
632 slist
= __get_cur_slist();
633 FOR_EACH_PTR(returned_state_callbacks
, cb
) {
634 cb
->callback(return_id
, return_ranges
, expr
, slist
);
635 } END_FOR_EACH_PTR(cb
);
637 __push_true_states();
638 __use_false_states();
640 return_ranges
= alloc_sname("0");;
642 slist
= __get_cur_slist();
643 FOR_EACH_PTR(returned_state_callbacks
, cb
) {
644 cb
->callback(return_id
, return_ranges
, expr
, slist
);
645 } END_FOR_EACH_PTR(cb
);
647 __merge_true_states();
648 __pop_fake_cur_slist();
651 static int call_return_state_hooks_split_possible(struct expression
*expr
)
653 struct returned_state_callback
*cb
;
654 struct state_list
*slist
;
655 struct range_list
*rl
;
658 struct sm_state
*tmp
;
660 int nr_possible
, nr_states
;
662 sm
= get_sm_state_expr(SMATCH_EXTRA
, expr
);
663 if (!sm
|| !sm
->merged
)
666 /* bail if it gets too complicated */
667 nr_possible
= ptr_list_size((struct ptr_list
*)sm
->possible
);
668 nr_states
= ptr_list_size((struct ptr_list
*)__get_cur_slist());
669 if (nr_possible
>= 100)
671 if (nr_states
* nr_possible
>= 1000)
674 FOR_EACH_PTR(sm
->possible
, tmp
) {
679 __push_fake_cur_slist();
681 overwrite_states_using_pool(tmp
);
683 rl
= cast_rl(cur_func_return_type(), estate_rl(tmp
->state
));
684 return_ranges
= show_rl(rl
);
687 slist
= __get_cur_slist();
688 FOR_EACH_PTR(returned_state_callbacks
, cb
) {
689 cb
->callback(return_id
, return_ranges
, expr
, slist
);
690 } END_FOR_EACH_PTR(cb
);
692 __pop_fake_cur_slist();
693 } END_FOR_EACH_PTR(tmp
);
698 static void call_return_state_hooks(struct expression
*expr
)
700 struct returned_state_callback
*cb
;
701 struct state_list
*slist
;
702 struct range_list
*rl
;
706 expr
= strip_expr(expr
);
709 return_ranges
= alloc_sname("");
710 } else if (is_condition(expr
)) {
711 call_return_state_hooks_compare(expr
);
713 } else if (call_return_state_hooks_split_possible(expr
)) {
715 } else if (get_implied_rl(expr
, &rl
)) {
716 rl
= cast_rl(cur_func_return_type(), rl
);
717 return_ranges
= show_rl(rl
);
719 rl
= alloc_whole_rl(cur_func_return_type());
720 return_ranges
= show_rl(rl
);
724 slist
= __get_cur_slist();
725 nr_states
= ptr_list_size((struct ptr_list
*)__get_cur_slist());
726 FOR_EACH_PTR(returned_state_callbacks
, cb
) {
727 if (nr_states
< 10000)
728 cb
->callback(return_id
, return_ranges
, expr
, slist
);
730 cb
->callback(return_id
, return_ranges
, expr
, NULL
);
731 } END_FOR_EACH_PTR(cb
);
734 static void print_returned_struct_members(int return_id
, char *return_ranges
, struct expression
*expr
, struct state_list
*slist
)
736 struct returned_member_callback
*cb
;
737 struct state_list
*my_slist
;
741 char member_name
[256];
744 type
= get_type(expr
);
745 if (!type
|| type
->type
!= SYM_PTR
)
747 type
= get_real_base_type(type
);
748 if (!type
|| type
->type
!= SYM_STRUCT
)
750 name
= expr_to_var(expr
);
754 member_name
[sizeof(member_name
) - 1] = '\0';
755 strcpy(member_name
, "$$");
758 FOR_EACH_PTR(returned_member_callbacks
, cb
) {
759 my_slist
= get_all_states_slist(cb
->owner
, slist
);
760 FOR_EACH_PTR(my_slist
, sm
) {
761 if (strncmp(sm
->name
, name
, len
) != 0)
763 if (strncmp(sm
->name
+ len
, "->", 2) != 0)
765 strncpy(member_name
+ 2, sm
->name
+ len
, sizeof(member_name
) - 2);
766 cb
->callback(return_id
, return_ranges
, member_name
, sm
->state
);
767 } END_FOR_EACH_PTR(sm
);
768 free_slist(&my_slist
);
769 } END_FOR_EACH_PTR(cb
);
774 static void match_end_func_info(struct symbol
*sym
)
776 if (__path_is_null())
778 call_return_state_hooks(NULL
);
781 static void init_memdb(void)
785 const char *schema_files
[] = {
787 "db/caller_info.schema",
788 "db/return_states.schema",
789 "db/type_size.schema",
790 "db/call_implies.schema",
791 "db/function_ptr.schema",
792 "db/return_values.schema",
794 static char buf
[4096];
799 rc
= sqlite3_open(":memory:", &mem_db
);
800 if (rc
!= SQLITE_OK
) {
801 printf("Error starting In-Memory database.");
805 for (i
= 0; i
< ARRAY_SIZE(schema_files
); i
++) {
806 fd
= open_data_file(schema_files
[i
]);
809 ret
= read(fd
, buf
, sizeof(buf
));
810 if (ret
== sizeof(buf
)) {
811 printf("Schema file too large: %s (limit %ld bytes)",
812 schema_files
[i
], sizeof(buf
));
815 rc
= sqlite3_exec(mem_db
, buf
, NULL
, 0, &err
);
816 if (rc
!= SQLITE_OK
) {
817 fprintf(stderr
, "SQL error #2: %s\n", err
);
818 fprintf(stderr
, "%s\n", buf
);
823 void open_smatch_db(void)
832 rc
= sqlite3_open_v2("smatch_db.sqlite", &db
, SQLITE_OPEN_READONLY
, NULL
);
833 if (rc
!= SQLITE_OK
) {
840 void register_definition_db_callbacks(int id
)
842 add_hook(&match_function_def
, FUNC_DEF_HOOK
);
844 add_hook(&match_call_info
, FUNCTION_CALL_HOOK
);
845 add_hook(&match_function_assign
, ASSIGNMENT_HOOK
);
846 add_hook(&match_function_assign
, GLOBAL_ASSIGNMENT_HOOK
);
847 add_hook(&global_variable
, BASE_HOOK
);
848 add_hook(&global_variable
, DECLARATION_HOOK
);
849 add_returned_state_callback(match_return_info
);
850 add_returned_state_callback(print_returned_struct_members
);
851 add_hook(&call_return_state_hooks
, RETURN_HOOK
);
852 add_hook(&match_end_func_info
, END_FUNC_HOOK
);
857 add_hook(&match_data_from_db
, FUNC_DEF_HOOK
);
858 add_hook(&match_call_implies
, FUNCTION_CALL_HOOK
);
861 void register_db_call_marker(int id
)
863 add_hook(&match_call_marker
, FUNCTION_CALL_HOOK
);
866 char *get_variable_from_key(struct expression
*arg
, char *key
, struct symbol
**sym
)
871 if (strcmp(key
, "$$") == 0)
872 return expr_to_var_sym(arg
, sym
);
874 if (strcmp(key
, "*$$") == 0) {
875 if (arg
->type
== EXPR_PREOP
&& arg
->op
== '&') {
876 arg
= strip_expr(arg
->unop
);
877 return expr_to_var_sym(arg
, sym
);
879 tmp
= expr_to_var_sym(arg
, sym
);
882 snprintf(buf
, sizeof(buf
), "*%s", tmp
);
884 return alloc_string(buf
);
888 if (arg
->type
== EXPR_PREOP
&& arg
->op
== '&') {
889 arg
= strip_expr(arg
->unop
);
890 tmp
= expr_to_var_sym(arg
, sym
);
893 snprintf(buf
, sizeof(buf
), "%s.%s", tmp
, key
+ 4);
894 return alloc_string(buf
);
897 tmp
= expr_to_var_sym(arg
, sym
);
900 snprintf(buf
, sizeof(buf
), "%s%s", tmp
, key
+ 2);
902 return alloc_string(buf
);