Fix ICE in substring-handling building 502.gcc_r (PR 87562)
[official-gcc.git] / gcc / testsuite / gcc.dg / plugin / must_tail_call_plugin.c
blob5294f28abbc44697c752e53703afb9585bbe5f2b
1 /* { dg-options "-O" } */
3 /* Mark all CALL_EXPRs not within "main" as requiring tail-call. */
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 "tree.h"
25 #include "tree-pass.h"
26 #include "intl.h"
27 #include "plugin-version.h"
29 int plugin_is_GPL_compatible;
31 tree
32 cb_walk_tree_fn (tree * tp, int * walk_subtrees,
33 void * data ATTRIBUTE_UNUSED)
35 if (TREE_CODE (*tp) != CALL_EXPR)
36 return NULL_TREE;
38 tree call_expr = *tp;
40 /* Forcibly mark the CALL_EXPR as requiring tail-call optimization. */
41 CALL_EXPR_MUST_TAIL_CALL (call_expr) = 1;
43 return NULL_TREE;
46 static void
47 callback (void *gcc_data, void *user_data)
49 tree fndecl = (tree)gcc_data;
50 gcc_assert (TREE_CODE (fndecl) == FUNCTION_DECL);
52 /* Don't mark calls inside "main". */
53 tree decl_name = DECL_NAME (fndecl);
54 if (decl_name)
55 if (0 == strcmp (IDENTIFIER_POINTER (decl_name), "main"))
56 return;
58 walk_tree (&DECL_SAVED_TREE (fndecl), cb_walk_tree_fn, NULL, NULL);
61 int
62 plugin_init (struct plugin_name_args *plugin_info,
63 struct plugin_gcc_version *version)
65 const char *plugin_name = plugin_info->base_name;
67 if (!plugin_default_version_check (version, &gcc_version))
68 return 1;
70 register_callback (plugin_name,
71 PLUGIN_PRE_GENERICIZE,
72 callback,
73 NULL);
75 return 0;