1 /* This plugin recursively dumps the source-code location ranges of
2 expressions, at the pre-gimplification tree stage. */
3 /* { dg-options "-O" } */
5 #include "gcc-plugin.h"
11 #include "stringpool.h"
13 #include "basic-block.h"
14 #include "hash-table.h"
17 #include "basic-block.h"
18 #include "tree-ssa-alias.h"
19 #include "internal-fn.h"
20 #include "gimple-fold.h"
22 #include "gimple-expr.h"
25 #include "gimple-iterator.h"
27 #include "tree-pass.h"
29 #include "plugin-version.h"
30 #include "diagnostic.h"
32 #include "gcc-rich-location.h"
33 #include "print-tree.h"
35 int plugin_is_GPL_compatible
;
40 if (!CAN_HAVE_RANGE_P (node
))
43 gcc_rich_location
richloc (EXPR_LOCATION (node
));
44 richloc
.add_expr (node
);
46 if (richloc
.get_num_locations () < 2)
48 error_at_rich_loc (&richloc
, "range not found");
52 enum tree_code code
= TREE_CODE (node
);
54 location_range
*range
= richloc
.get_range (1);
55 inform_at_rich_loc (&richloc
, "%s", get_tree_code_name (code
));
59 int max_idx
= TREE_OPERAND_LENGTH (node
);
70 for (int i
= min_idx
; i
< max_idx
; i
++)
71 show_tree (TREE_OPERAND (node
, i
));
75 cb_walk_tree_fn (tree
* tp
, int * walk_subtrees
,
76 void * data ATTRIBUTE_UNUSED
)
78 if (TREE_CODE (*tp
) != CALL_EXPR
)
82 tree fn
= CALL_EXPR_FN (call_expr
);
83 if (TREE_CODE (fn
) != ADDR_EXPR
)
85 fn
= TREE_OPERAND (fn
, 0);
86 if (TREE_CODE (fn
) != FUNCTION_DECL
)
88 if (strcmp (IDENTIFIER_POINTER (DECL_NAME (fn
)), "__show_tree"))
91 /* Get arg 1; print it! */
92 tree arg
= CALL_EXPR_ARG (call_expr
, 1);
100 callback (void *gcc_data
, void *user_data
)
102 tree fndecl
= (tree
)gcc_data
;
103 walk_tree (&DECL_SAVED_TREE (fndecl
), cb_walk_tree_fn
, NULL
, NULL
);
107 plugin_init (struct plugin_name_args
*plugin_info
,
108 struct plugin_gcc_version
*version
)
110 struct register_pass_info pass_info
;
111 const char *plugin_name
= plugin_info
->base_name
;
112 int argc
= plugin_info
->argc
;
113 struct plugin_argument
*argv
= plugin_info
->argv
;
115 if (!plugin_default_version_check (version
, &gcc_version
))
118 register_callback (plugin_name
,
119 PLUGIN_PRE_GENERICIZE
,