Fix warning with -Wsign-compare -Wsystem-headers
[official-gcc.git] / gcc / testsuite / gcc.dg / plugin / diagnostic_plugin_test_tree_expression_range.c
blob89cc95acd9999e4f47b103912ebaf16a028540b2
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"
6 #include "config.h"
7 #include "system.h"
8 #include "coretypes.h"
9 #include "tm.h"
10 #include "tree.h"
11 #include "stringpool.h"
12 #include "toplev.h"
13 #include "basic-block.h"
14 #include "hash-table.h"
15 #include "vec.h"
16 #include "ggc.h"
17 #include "basic-block.h"
18 #include "tree-ssa-alias.h"
19 #include "internal-fn.h"
20 #include "gimple-fold.h"
21 #include "tree-eh.h"
22 #include "gimple-expr.h"
23 #include "is-a.h"
24 #include "gimple.h"
25 #include "gimple-iterator.h"
26 #include "tree.h"
27 #include "tree-pass.h"
28 #include "intl.h"
29 #include "plugin-version.h"
30 #include "diagnostic.h"
31 #include "context.h"
32 #include "print-tree.h"
34 int plugin_is_GPL_compatible;
36 static void
37 emit_warning (location_t loc)
39 source_range src_range = get_range_from_loc (line_table, loc);
40 warning_at (loc, 0,
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));
48 tree
49 cb_walk_tree_fn (tree * tp, int * walk_subtrees,
50 void * data ATTRIBUTE_UNUSED)
52 if (TREE_CODE (*tp) != CALL_EXPR)
53 return NULL_TREE;
55 tree call_expr = *tp;
56 tree fn = CALL_EXPR_FN (call_expr);
57 if (TREE_CODE (fn) != ADDR_EXPR)
58 return NULL_TREE;
59 fn = TREE_OPERAND (fn, 0);
60 if (TREE_CODE (fn) != FUNCTION_DECL)
61 return NULL_TREE;
62 if (strcmp (IDENTIFIER_POINTER (DECL_NAME (fn)), "__emit_expression_range"))
63 return NULL_TREE;
65 /* Get arg 1; print it! */
66 tree arg = CALL_EXPR_ARG (call_expr, 1);
68 emit_warning (EXPR_LOCATION (arg));
70 return NULL_TREE;
73 static void
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);
80 int
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))
90 return 1;
92 register_callback (plugin_name,
93 PLUGIN_PRE_GENERICIZE,
94 callback,
95 NULL);
97 return 0;