1 /* This plugin verifies 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 "print-tree.h"
34 int plugin_is_GPL_compatible
;
37 emit_warning (location_t loc
)
39 source_range src_range
= get_range_from_loc (line_table
, loc
);
41 "tree range %i:%i-%i:%i",
42 LOCATION_LINE (src_range
.m_start
),
43 LOCATION_COLUMN (src_range
.m_start
),
44 LOCATION_LINE (src_range
.m_finish
),
45 LOCATION_COLUMN (src_range
.m_finish
));
49 cb_walk_tree_fn (tree
* tp
, int * walk_subtrees
,
50 void * data ATTRIBUTE_UNUSED
)
52 if (TREE_CODE (*tp
) != CALL_EXPR
)
56 tree fn
= CALL_EXPR_FN (call_expr
);
57 if (TREE_CODE (fn
) != ADDR_EXPR
)
59 fn
= TREE_OPERAND (fn
, 0);
60 if (TREE_CODE (fn
) != FUNCTION_DECL
)
62 if (strcmp (IDENTIFIER_POINTER (DECL_NAME (fn
)), "__emit_expression_range"))
65 /* Get arg 1; print it! */
66 tree arg
= CALL_EXPR_ARG (call_expr
, 1);
68 emit_warning (EXPR_LOCATION (arg
));
74 callback (void *gcc_data
, void *user_data
)
76 tree fndecl
= (tree
)gcc_data
;
77 walk_tree (&DECL_SAVED_TREE (fndecl
), cb_walk_tree_fn
, NULL
, NULL
);
81 plugin_init (struct plugin_name_args
*plugin_info
,
82 struct plugin_gcc_version
*version
)
84 struct register_pass_info pass_info
;
85 const char *plugin_name
= plugin_info
->base_name
;
86 int argc
= plugin_info
->argc
;
87 struct plugin_argument
*argv
= plugin_info
->argv
;
89 if (!plugin_default_version_check (version
, &gcc_version
))
92 register_callback (plugin_name
,
93 PLUGIN_PRE_GENERICIZE
,