Commit ChangeLog entries.
[gcc.git] / gcc / tree-mudflap.c
1 /* Mudflap: narrow-pointer bounds-checking by tree rewriting.
2 Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
3 Contributed by Frank Ch. Eigler <fche@redhat.com>
4 and Graydon Hoare <graydon@redhat.com>
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA. */
22
23
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "hard-reg-set.h"
29 #include "rtl.h"
30 #include "tree.h"
31 #include "tm_p.h"
32 #include "basic-block.h"
33 #include "flags.h"
34 #include "function.h"
35 #include "tree-inline.h"
36 #include "tree-gimple.h"
37 #include "tree-flow.h"
38 #include "tree-mudflap.h"
39 #include "tree-dump.h"
40 #include "tree-pass.h"
41 #include "hashtab.h"
42 #include "diagnostic.h"
43 #include <demangle.h>
44 #include "langhooks.h"
45 #include "ggc.h"
46 #include "cgraph.h"
47 #include "toplev.h"
48
49 /* Internal function decls */
50
51 /* Helpers. */
52 static tree mf_build_string (const char *string);
53 static tree mf_varname_tree (tree);
54 static tree mf_file_function_line_tree (location_t);
55
56 /* Indirection-related instrumentation. */
57 static void mf_decl_cache_locals (void);
58 static void mf_decl_clear_locals (void);
59 static void mf_xform_derefs (void);
60 static unsigned int execute_mudflap_function_ops (void);
61
62 /* Addressable variables instrumentation. */
63 static void mf_xform_decls (tree, tree);
64 static tree mx_xfn_xform_decls (tree *, int *, void *);
65 static void mx_register_decls (tree, tree *);
66 static unsigned int execute_mudflap_function_decls (void);
67
68
69 /* ------------------------------------------------------------------------ */
70 /* Some generally helpful functions for mudflap instrumentation. */
71
72 /* Build a reference to a literal string. */
73 static tree
74 mf_build_string (const char *string)
75 {
76 size_t len = strlen (string);
77 tree result = mf_mark (build_string (len + 1, string));
78
79 TREE_TYPE (result) = build_array_type
80 (char_type_node, build_index_type (build_int_cst (NULL_TREE, len)));
81 TREE_CONSTANT (result) = 1;
82 TREE_INVARIANT (result) = 1;
83 TREE_READONLY (result) = 1;
84 TREE_STATIC (result) = 1;
85
86 result = build1 (ADDR_EXPR, build_pointer_type (char_type_node), result);
87
88 return mf_mark (result);
89 }
90
91 /* Create a properly typed STRING_CST node that describes the given
92 declaration. It will be used as an argument for __mf_register().
93 Try to construct a helpful string, including file/function/variable
94 name. */
95
96 static tree
97 mf_varname_tree (tree decl)
98 {
99 static pretty_printer buf_rec;
100 static int initialized = 0;
101 pretty_printer *buf = & buf_rec;
102 const char *buf_contents;
103 tree result;
104
105 gcc_assert (decl);
106
107 if (!initialized)
108 {
109 pp_construct (buf, /* prefix */ NULL, /* line-width */ 0);
110 initialized = 1;
111 }
112 pp_clear_output_area (buf);
113
114 /* Add FILENAME[:LINENUMBER[:COLUMNNUMBER]]. */
115 {
116 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (decl));
117 const char *sourcefile;
118 unsigned sourceline = xloc.line;
119 unsigned sourcecolumn = 0;
120 #ifdef USE_MAPPED_LOCATION
121 sourcecolumn = xloc.column;
122 #endif
123 sourcefile = xloc.file;
124 if (sourcefile == NULL && current_function_decl != NULL_TREE)
125 sourcefile = DECL_SOURCE_FILE (current_function_decl);
126 if (sourcefile == NULL)
127 sourcefile = "<unknown file>";
128
129 pp_string (buf, sourcefile);
130
131 if (sourceline != 0)
132 {
133 pp_string (buf, ":");
134 pp_decimal_int (buf, sourceline);
135
136 if (sourcecolumn != 0)
137 {
138 pp_string (buf, ":");
139 pp_decimal_int (buf, sourcecolumn);
140 }
141 }
142 }
143
144 if (current_function_decl != NULL_TREE)
145 {
146 /* Add (FUNCTION) */
147 pp_string (buf, " (");
148 {
149 const char *funcname = NULL;
150 if (DECL_NAME (current_function_decl))
151 funcname = lang_hooks.decl_printable_name (current_function_decl, 1);
152 if (funcname == NULL)
153 funcname = "anonymous fn";
154
155 pp_string (buf, funcname);
156 }
157 pp_string (buf, ") ");
158 }
159 else
160 pp_string (buf, " ");
161
162 /* Add <variable-declaration>, possibly demangled. */
163 {
164 const char *declname = NULL;
165
166 if (DECL_NAME (decl) != NULL)
167 {
168 if (strcmp ("GNU C++", lang_hooks.name) == 0)
169 {
170 /* The gcc/cp decl_printable_name hook doesn't do as good a job as
171 the libiberty demangler. */
172 declname = cplus_demangle (IDENTIFIER_POINTER (DECL_NAME (decl)),
173 DMGL_AUTO | DMGL_VERBOSE);
174 }
175 if (declname == NULL)
176 declname = lang_hooks.decl_printable_name (decl, 3);
177 }
178 if (declname == NULL)
179 declname = "<unnamed variable>";
180
181 pp_string (buf, declname);
182 }
183
184 /* Return the lot as a new STRING_CST. */
185 buf_contents = pp_base_formatted_text (buf);
186 result = mf_build_string (buf_contents);
187 pp_clear_output_area (buf);
188
189 return result;
190 }
191
192
193 /* And another friend, for producing a simpler message. */
194
195 static tree
196 mf_file_function_line_tree (location_t location)
197 {
198 expanded_location xloc = expand_location (location);
199 const char *file = NULL, *colon, *line, *op, *name, *cp;
200 char linecolbuf[30]; /* Enough for two decimal numbers plus a colon. */
201 char *string;
202 tree result;
203
204 /* Add FILENAME[:LINENUMBER[:COLUMNNUMBER]]. */
205 file = xloc.file;
206 if (file == NULL && current_function_decl != NULL_TREE)
207 file = DECL_SOURCE_FILE (current_function_decl);
208 if (file == NULL)
209 file = "<unknown file>";
210
211 if (xloc.line > 0)
212 {
213 #ifdef USE_MAPPED_LOCATION
214 if (xloc.column > 0)
215 sprintf (linecolbuf, "%d:%d", xloc.line, xloc.column);
216 else
217 #endif
218 sprintf (linecolbuf, "%d", xloc.line);
219 colon = ":";
220 line = linecolbuf;
221 }
222 else
223 colon = line = "";
224
225 /* Add (FUNCTION). */
226 name = lang_hooks.decl_printable_name (current_function_decl, 1);
227 if (name)
228 {
229 op = " (";
230 cp = ")";
231 }
232 else
233 op = name = cp = "";
234
235 string = concat (file, colon, line, op, name, cp, NULL);
236 result = mf_build_string (string);
237 free (string);
238
239 return result;
240 }
241
242
243 /* global tree nodes */
244
245 /* Global tree objects for global variables and functions exported by
246 mudflap runtime library. mf_init_extern_trees must be called
247 before using these. */
248
249 /* uintptr_t (usually "unsigned long") */
250 static GTY (()) tree mf_uintptr_type;
251
252 /* struct __mf_cache { uintptr_t low; uintptr_t high; }; */
253 static GTY (()) tree mf_cache_struct_type;
254
255 /* struct __mf_cache * const */
256 static GTY (()) tree mf_cache_structptr_type;
257
258 /* extern struct __mf_cache __mf_lookup_cache []; */
259 static GTY (()) tree mf_cache_array_decl;
260
261 /* extern unsigned char __mf_lc_shift; */
262 static GTY (()) tree mf_cache_shift_decl;
263
264 /* extern uintptr_t __mf_lc_mask; */
265 static GTY (()) tree mf_cache_mask_decl;
266
267 /* Their function-scope local shadows, used in single-threaded mode only. */
268
269 /* auto const unsigned char __mf_lc_shift_l; */
270 static GTY (()) tree mf_cache_shift_decl_l;
271
272 /* auto const uintptr_t __mf_lc_mask_l; */
273 static GTY (()) tree mf_cache_mask_decl_l;
274
275 /* extern void __mf_check (void *ptr, size_t sz, int type, const char *); */
276 static GTY (()) tree mf_check_fndecl;
277
278 /* extern void __mf_register (void *ptr, size_t sz, int type, const char *); */
279 static GTY (()) tree mf_register_fndecl;
280
281 /* extern void __mf_unregister (void *ptr, size_t sz, int type); */
282 static GTY (()) tree mf_unregister_fndecl;
283
284 /* extern void __mf_init (); */
285 static GTY (()) tree mf_init_fndecl;
286
287 /* extern int __mf_set_options (const char*); */
288 static GTY (()) tree mf_set_options_fndecl;
289
290
291 /* Helper for mudflap_init: construct a decl with the given category,
292 name, and type, mark it an external reference, and pushdecl it. */
293 static inline tree
294 mf_make_builtin (enum tree_code category, const char *name, tree type)
295 {
296 tree decl = mf_mark (build_decl (category, get_identifier (name), type));
297 TREE_PUBLIC (decl) = 1;
298 DECL_EXTERNAL (decl) = 1;
299 lang_hooks.decls.pushdecl (decl);
300 return decl;
301 }
302
303 /* Helper for mudflap_init: construct a tree corresponding to the type
304 struct __mf_cache { uintptr_t low; uintptr_t high; };
305 where uintptr_t is the FIELD_TYPE argument. */
306 static inline tree
307 mf_make_mf_cache_struct_type (tree field_type)
308 {
309 /* There is, abominably, no language-independent way to construct a
310 RECORD_TYPE. So we have to call the basic type construction
311 primitives by hand. */
312 tree fieldlo = build_decl (FIELD_DECL, get_identifier ("low"), field_type);
313 tree fieldhi = build_decl (FIELD_DECL, get_identifier ("high"), field_type);
314
315 tree struct_type = make_node (RECORD_TYPE);
316 DECL_CONTEXT (fieldlo) = struct_type;
317 DECL_CONTEXT (fieldhi) = struct_type;
318 TREE_CHAIN (fieldlo) = fieldhi;
319 TYPE_FIELDS (struct_type) = fieldlo;
320 TYPE_NAME (struct_type) = get_identifier ("__mf_cache");
321 layout_type (struct_type);
322
323 return struct_type;
324 }
325
326 #define build_function_type_0(rtype) \
327 build_function_type (rtype, void_list_node)
328 #define build_function_type_1(rtype, arg1) \
329 build_function_type (rtype, tree_cons (0, arg1, void_list_node))
330 #define build_function_type_3(rtype, arg1, arg2, arg3) \
331 build_function_type (rtype, tree_cons (0, arg1, tree_cons (0, arg2, \
332 tree_cons (0, arg3, void_list_node))))
333 #define build_function_type_4(rtype, arg1, arg2, arg3, arg4) \
334 build_function_type (rtype, tree_cons (0, arg1, tree_cons (0, arg2, \
335 tree_cons (0, arg3, tree_cons (0, arg4, \
336 void_list_node)))))
337
338 /* Initialize the global tree nodes that correspond to mf-runtime.h
339 declarations. */
340 void
341 mudflap_init (void)
342 {
343 static bool done = false;
344 tree mf_const_string_type;
345 tree mf_cache_array_type;
346 tree mf_check_register_fntype;
347 tree mf_unregister_fntype;
348 tree mf_init_fntype;
349 tree mf_set_options_fntype;
350
351 if (done)
352 return;
353 done = true;
354
355 mf_uintptr_type = lang_hooks.types.type_for_mode (ptr_mode,
356 /*unsignedp=*/true);
357 mf_const_string_type
358 = build_pointer_type (build_qualified_type
359 (char_type_node, TYPE_QUAL_CONST));
360
361 mf_cache_struct_type = mf_make_mf_cache_struct_type (mf_uintptr_type);
362 mf_cache_structptr_type = build_pointer_type (mf_cache_struct_type);
363 mf_cache_array_type = build_array_type (mf_cache_struct_type, 0);
364 mf_check_register_fntype =
365 build_function_type_4 (void_type_node, ptr_type_node, size_type_node,
366 integer_type_node, mf_const_string_type);
367 mf_unregister_fntype =
368 build_function_type_3 (void_type_node, ptr_type_node, size_type_node,
369 integer_type_node);
370 mf_init_fntype =
371 build_function_type_0 (void_type_node);
372 mf_set_options_fntype =
373 build_function_type_1 (integer_type_node, mf_const_string_type);
374
375 mf_cache_array_decl = mf_make_builtin (VAR_DECL, "__mf_lookup_cache",
376 mf_cache_array_type);
377 mf_cache_shift_decl = mf_make_builtin (VAR_DECL, "__mf_lc_shift",
378 unsigned_char_type_node);
379 mf_cache_mask_decl = mf_make_builtin (VAR_DECL, "__mf_lc_mask",
380 mf_uintptr_type);
381 /* Don't process these in mudflap_enqueue_decl, should they come by
382 there for some reason. */
383 mf_mark (mf_cache_array_decl);
384 mf_mark (mf_cache_shift_decl);
385 mf_mark (mf_cache_mask_decl);
386 mf_check_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_check",
387 mf_check_register_fntype);
388 mf_register_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_register",
389 mf_check_register_fntype);
390 mf_unregister_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_unregister",
391 mf_unregister_fntype);
392 mf_init_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_init",
393 mf_init_fntype);
394 mf_set_options_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_set_options",
395 mf_set_options_fntype);
396 }
397 #undef build_function_type_4
398 #undef build_function_type_3
399 #undef build_function_type_1
400 #undef build_function_type_0
401
402
403 /* ------------------------------------------------------------------------ */
404 /* Memory reference transforms. Perform the mudflap indirection-related
405 tree transforms on the current function.
406
407 This is the second part of the mudflap instrumentation. It works on
408 low-level GIMPLE using the CFG, because we want to run this pass after
409 tree optimizations have been performed, but we have to preserve the CFG
410 for expansion from trees to RTL. */
411
412 static unsigned int
413 execute_mudflap_function_ops (void)
414 {
415 /* Don't instrument functions such as the synthetic constructor
416 built during mudflap_finish_file. */
417 if (mf_marked_p (current_function_decl) ||
418 DECL_ARTIFICIAL (current_function_decl))
419 return 0;
420
421 push_gimplify_context ();
422
423 /* In multithreaded mode, don't cache the lookup cache parameters. */
424 if (! flag_mudflap_threads)
425 mf_decl_cache_locals ();
426
427 mf_xform_derefs ();
428
429 if (! flag_mudflap_threads)
430 mf_decl_clear_locals ();
431
432 pop_gimplify_context (NULL);
433 return 0;
434 }
435
436 /* Create and initialize local shadow variables for the lookup cache
437 globals. Put their decls in the *_l globals for use by
438 mf_build_check_statement_for. */
439
440 static void
441 mf_decl_cache_locals (void)
442 {
443 tree t, shift_init_stmts, mask_init_stmts;
444 tree_stmt_iterator tsi;
445
446 /* Build the cache vars. */
447 mf_cache_shift_decl_l
448 = mf_mark (create_tmp_var (TREE_TYPE (mf_cache_shift_decl),
449 "__mf_lookup_shift_l"));
450
451 mf_cache_mask_decl_l
452 = mf_mark (create_tmp_var (TREE_TYPE (mf_cache_mask_decl),
453 "__mf_lookup_mask_l"));
454
455 /* Build initialization nodes for the cache vars. We just load the
456 globals into the cache variables. */
457 t = build2 (MODIFY_EXPR, TREE_TYPE (mf_cache_shift_decl_l),
458 mf_cache_shift_decl_l, mf_cache_shift_decl);
459 SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (current_function_decl));
460 gimplify_to_stmt_list (&t);
461 shift_init_stmts = t;
462
463 t = build2 (MODIFY_EXPR, TREE_TYPE (mf_cache_mask_decl_l),
464 mf_cache_mask_decl_l, mf_cache_mask_decl);
465 SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (current_function_decl));
466 gimplify_to_stmt_list (&t);
467 mask_init_stmts = t;
468
469 /* Anticipating multiple entry points, we insert the cache vars
470 initializers in each successor of the ENTRY_BLOCK_PTR. */
471 for (tsi = tsi_start (shift_init_stmts);
472 ! tsi_end_p (tsi);
473 tsi_next (&tsi))
474 insert_edge_copies (tsi_stmt (tsi), ENTRY_BLOCK_PTR);
475
476 for (tsi = tsi_start (mask_init_stmts);
477 ! tsi_end_p (tsi);
478 tsi_next (&tsi))
479 insert_edge_copies (tsi_stmt (tsi), ENTRY_BLOCK_PTR);
480 bsi_commit_edge_inserts ();
481 }
482
483
484 static void
485 mf_decl_clear_locals (void)
486 {
487 /* Unset local shadows. */
488 mf_cache_shift_decl_l = NULL_TREE;
489 mf_cache_mask_decl_l = NULL_TREE;
490 }
491
492 static void
493 mf_build_check_statement_for (tree base, tree limit,
494 block_stmt_iterator *instr_bsi,
495 location_t *locus, tree dirflag)
496 {
497 tree_stmt_iterator head, tsi;
498 block_stmt_iterator bsi;
499 basic_block cond_bb, then_bb, join_bb;
500 edge e;
501 tree cond, t, u, v;
502 tree mf_base;
503 tree mf_elem;
504 tree mf_limit;
505
506 /* We first need to split the current basic block, and start altering
507 the CFG. This allows us to insert the statements we're about to
508 construct into the right basic blocks. */
509
510 cond_bb = bb_for_stmt (bsi_stmt (*instr_bsi));
511 bsi = *instr_bsi;
512 bsi_prev (&bsi);
513 if (! bsi_end_p (bsi))
514 e = split_block (cond_bb, bsi_stmt (bsi));
515 else
516 e = split_block_after_labels (cond_bb);
517 cond_bb = e->src;
518 join_bb = e->dest;
519
520 /* A recap at this point: join_bb is the basic block at whose head
521 is the gimple statement for which this check expression is being
522 built. cond_bb is the (possibly new, synthetic) basic block the
523 end of which will contain the cache-lookup code, and a
524 conditional that jumps to the cache-miss code or, much more
525 likely, over to join_bb. */
526
527 /* Create the bb that contains the cache-miss fallback block (mf_check). */
528 then_bb = create_empty_bb (cond_bb);
529 make_edge (cond_bb, then_bb, EDGE_TRUE_VALUE);
530 make_single_succ_edge (then_bb, join_bb, EDGE_FALLTHRU);
531
532 /* Mark the pseudo-fallthrough edge from cond_bb to join_bb. */
533 e = find_edge (cond_bb, join_bb);
534 e->flags = EDGE_FALSE_VALUE;
535 e->count = cond_bb->count;
536 e->probability = REG_BR_PROB_BASE;
537
538 /* Update dominance info. Note that bb_join's data was
539 updated by split_block. */
540 if (dom_info_available_p (CDI_DOMINATORS))
541 {
542 set_immediate_dominator (CDI_DOMINATORS, then_bb, cond_bb);
543 set_immediate_dominator (CDI_DOMINATORS, join_bb, cond_bb);
544 }
545
546 /* Build our local variables. */
547 mf_elem = create_tmp_var (mf_cache_structptr_type, "__mf_elem");
548 mf_base = create_tmp_var (mf_uintptr_type, "__mf_base");
549 mf_limit = create_tmp_var (mf_uintptr_type, "__mf_limit");
550
551 /* Build: __mf_base = (uintptr_t) <base address expression>. */
552 t = build2 (MODIFY_EXPR, void_type_node, mf_base,
553 convert (mf_uintptr_type, unshare_expr (base)));
554 SET_EXPR_LOCUS (t, locus);
555 gimplify_to_stmt_list (&t);
556 head = tsi_start (t);
557 tsi = tsi_last (t);
558
559 /* Build: __mf_limit = (uintptr_t) <limit address expression>. */
560 t = build2 (MODIFY_EXPR, void_type_node, mf_limit,
561 convert (mf_uintptr_type, unshare_expr (limit)));
562 SET_EXPR_LOCUS (t, locus);
563 gimplify_to_stmt_list (&t);
564 tsi_link_after (&tsi, t, TSI_CONTINUE_LINKING);
565
566 /* Build: __mf_elem = &__mf_lookup_cache [(__mf_base >> __mf_shift)
567 & __mf_mask]. */
568 t = build2 (RSHIFT_EXPR, mf_uintptr_type, mf_base,
569 (flag_mudflap_threads ? mf_cache_shift_decl : mf_cache_shift_decl_l));
570 t = build2 (BIT_AND_EXPR, mf_uintptr_type, t,
571 (flag_mudflap_threads ? mf_cache_mask_decl : mf_cache_mask_decl_l));
572 t = build4 (ARRAY_REF,
573 TREE_TYPE (TREE_TYPE (mf_cache_array_decl)),
574 mf_cache_array_decl, t, NULL_TREE, NULL_TREE);
575 t = build1 (ADDR_EXPR, mf_cache_structptr_type, t);
576 t = build2 (MODIFY_EXPR, void_type_node, mf_elem, t);
577 SET_EXPR_LOCUS (t, locus);
578 gimplify_to_stmt_list (&t);
579 tsi_link_after (&tsi, t, TSI_CONTINUE_LINKING);
580
581 /* Quick validity check.
582
583 if (__mf_elem->low > __mf_base
584 || (__mf_elem_high < __mf_limit))
585 {
586 __mf_check ();
587 ... and only if single-threaded:
588 __mf_lookup_shift_1 = f...;
589 __mf_lookup_mask_l = ...;
590 }
591
592 It is expected that this body of code is rarely executed so we mark
593 the edge to the THEN clause of the conditional jump as unlikely. */
594
595 /* Construct t <-- '__mf_elem->low > __mf_base'. */
596 t = build3 (COMPONENT_REF, mf_uintptr_type,
597 build1 (INDIRECT_REF, mf_cache_struct_type, mf_elem),
598 TYPE_FIELDS (mf_cache_struct_type), NULL_TREE);
599 t = build2 (GT_EXPR, boolean_type_node, t, mf_base);
600
601 /* Construct '__mf_elem->high < __mf_limit'.
602
603 First build:
604 1) u <-- '__mf_elem->high'
605 2) v <-- '__mf_limit'.
606
607 Then build 'u <-- (u < v). */
608
609 u = build3 (COMPONENT_REF, mf_uintptr_type,
610 build1 (INDIRECT_REF, mf_cache_struct_type, mf_elem),
611 TREE_CHAIN (TYPE_FIELDS (mf_cache_struct_type)), NULL_TREE);
612
613 v = mf_limit;
614
615 u = build2 (LT_EXPR, boolean_type_node, u, v);
616
617 /* Build the composed conditional: t <-- 't || u'. Then store the
618 result of the evaluation of 't' in a temporary variable which we
619 can use as the condition for the conditional jump. */
620 t = build2 (TRUTH_OR_EXPR, boolean_type_node, t, u);
621 cond = create_tmp_var (boolean_type_node, "__mf_unlikely_cond");
622 t = build2 (MODIFY_EXPR, boolean_type_node, cond, t);
623 gimplify_to_stmt_list (&t);
624 tsi_link_after (&tsi, t, TSI_CONTINUE_LINKING);
625
626 /* Build the conditional jump. 'cond' is just a temporary so we can
627 simply build a void COND_EXPR. We do need labels in both arms though. */
628 t = build3 (COND_EXPR, void_type_node, cond,
629 build1 (GOTO_EXPR, void_type_node, tree_block_label (then_bb)),
630 build1 (GOTO_EXPR, void_type_node, tree_block_label (join_bb)));
631 SET_EXPR_LOCUS (t, locus);
632 tsi_link_after (&tsi, t, TSI_CONTINUE_LINKING);
633
634 /* At this point, after so much hard work, we have only constructed
635 the conditional jump,
636
637 if (__mf_elem->low > __mf_base
638 || (__mf_elem_high < __mf_limit))
639
640 The lowered GIMPLE tree representing this code is in the statement
641 list starting at 'head'.
642
643 We can insert this now in the current basic block, i.e. the one that
644 the statement we're instrumenting was originally in. */
645 bsi = bsi_last (cond_bb);
646 for (tsi = head; ! tsi_end_p (tsi); tsi_next (&tsi))
647 bsi_insert_after (&bsi, tsi_stmt (tsi), BSI_CONTINUE_LINKING);
648
649 /* Now build up the body of the cache-miss handling:
650
651 __mf_check();
652 refresh *_l vars.
653
654 This is the body of the conditional. */
655
656 u = tree_cons (NULL_TREE,
657 mf_file_function_line_tree (locus == NULL ? UNKNOWN_LOCATION
658 : *locus),
659 NULL_TREE);
660 u = tree_cons (NULL_TREE, dirflag, u);
661 /* NB: we pass the overall [base..limit] range to mf_check. */
662 u = tree_cons (NULL_TREE,
663 fold_build2 (PLUS_EXPR, integer_type_node,
664 fold_build2 (MINUS_EXPR, mf_uintptr_type, mf_limit, mf_base),
665 integer_one_node),
666 u);
667 u = tree_cons (NULL_TREE, mf_base, u);
668 t = build_function_call_expr (mf_check_fndecl, u);
669 gimplify_to_stmt_list (&t);
670 head = tsi_start (t);
671 tsi = tsi_last (t);
672
673 if (! flag_mudflap_threads)
674 {
675 t = build2 (MODIFY_EXPR, void_type_node,
676 mf_cache_shift_decl_l, mf_cache_shift_decl);
677 tsi_link_after (&tsi, t, TSI_CONTINUE_LINKING);
678
679 t = build2 (MODIFY_EXPR, void_type_node,
680 mf_cache_mask_decl_l, mf_cache_mask_decl);
681 tsi_link_after (&tsi, t, TSI_CONTINUE_LINKING);
682 }
683
684 /* Insert the check code in the THEN block. */
685 bsi = bsi_start (then_bb);
686 for (tsi = head; ! tsi_end_p (tsi); tsi_next (&tsi))
687 bsi_insert_after (&bsi, tsi_stmt (tsi), BSI_CONTINUE_LINKING);
688
689 *instr_bsi = bsi_start (join_bb);
690 bsi_next (instr_bsi);
691 }
692
693
694 /* Check whether the given decl, generally a VAR_DECL or PARM_DECL, is
695 eligible for instrumentation. For the mudflap1 pass, this implies
696 that it should be registered with the libmudflap runtime. For the
697 mudflap2 pass this means instrumenting an indirection operation with
698 respect to the object.
699 */
700 static int
701 mf_decl_eligible_p (tree decl)
702 {
703 return ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
704 /* The decl must have its address taken. In the case of
705 arrays, this flag is also set if the indexes are not
706 compile-time known valid constants. */
707 && TREE_ADDRESSABLE (decl) /* XXX: not sufficient: return-by-value structs! */
708 /* The type of the variable must be complete. */
709 && COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (decl))
710 /* The decl hasn't been decomposed somehow. */
711 && !DECL_HAS_VALUE_EXPR_P (decl));
712 }
713
714
715 static void
716 mf_xform_derefs_1 (block_stmt_iterator *iter, tree *tp,
717 location_t *locus, tree dirflag)
718 {
719 tree type, base, limit, addr, size, t;
720
721 /* Don't instrument read operations. */
722 if (dirflag == integer_zero_node && flag_mudflap_ignore_reads)
723 return;
724
725 /* Don't instrument marked nodes. */
726 if (mf_marked_p (*tp))
727 return;
728
729 t = *tp;
730 type = TREE_TYPE (t);
731
732 if (type == error_mark_node)
733 return;
734
735 size = TYPE_SIZE_UNIT (type);
736
737 switch (TREE_CODE (t))
738 {
739 case ARRAY_REF:
740 case COMPONENT_REF:
741 {
742 /* This is trickier than it may first appear. The reason is
743 that we are looking at expressions from the "inside out" at
744 this point. We may have a complex nested aggregate/array
745 expression (e.g. "a.b[i].c"), maybe with an indirection as
746 the leftmost operator ("p->a.b.d"), where instrumentation
747 is necessary. Or we may have an innocent "a.b.c"
748 expression that must not be instrumented. We need to
749 recurse all the way down the nesting structure to figure it
750 out: looking just at the outer node is not enough. */
751 tree var;
752 int component_ref_only = (TREE_CODE (t) == COMPONENT_REF);
753 /* If we have a bitfield component reference, we must note the
754 innermost addressable object in ELT, from which we will
755 construct the byte-addressable bounds of the bitfield. */
756 tree elt = NULL_TREE;
757 int bitfield_ref_p = (TREE_CODE (t) == COMPONENT_REF
758 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (t, 1)));
759
760 /* Iterate to the top of the ARRAY_REF/COMPONENT_REF
761 containment hierarchy to find the outermost VAR_DECL. */
762 var = TREE_OPERAND (t, 0);
763 while (1)
764 {
765 if (bitfield_ref_p && elt == NULL_TREE
766 && (TREE_CODE (var) == ARRAY_REF || TREE_CODE (var) == COMPONENT_REF))
767 elt = var;
768
769 if (TREE_CODE (var) == ARRAY_REF)
770 {
771 component_ref_only = 0;
772 var = TREE_OPERAND (var, 0);
773 }
774 else if (TREE_CODE (var) == COMPONENT_REF)
775 var = TREE_OPERAND (var, 0);
776 else if (INDIRECT_REF_P (var))
777 {
778 base = TREE_OPERAND (var, 0);
779 break;
780 }
781 else
782 {
783 gcc_assert (TREE_CODE (var) == VAR_DECL
784 || TREE_CODE (var) == PARM_DECL
785 || TREE_CODE (var) == RESULT_DECL
786 || TREE_CODE (var) == STRING_CST);
787 /* Don't instrument this access if the underlying
788 variable is not "eligible". This test matches
789 those arrays that have only known-valid indexes,
790 and thus are not labeled TREE_ADDRESSABLE. */
791 if (! mf_decl_eligible_p (var) || component_ref_only)
792 return;
793 else
794 {
795 base = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (var)), var);
796 break;
797 }
798 }
799 }
800
801 /* Handle the case of ordinary non-indirection structure
802 accesses. These have only nested COMPONENT_REF nodes (no
803 INDIRECT_REF), but pass through the above filter loop.
804 Note that it's possible for such a struct variable to match
805 the eligible_p test because someone else might take its
806 address sometime. */
807
808 /* We need special processing for bitfield components, because
809 their addresses cannot be taken. */
810 if (bitfield_ref_p)
811 {
812 tree field = TREE_OPERAND (t, 1);
813
814 if (TREE_CODE (DECL_SIZE_UNIT (field)) == INTEGER_CST)
815 size = DECL_SIZE_UNIT (field);
816
817 if (elt)
818 elt = build1 (ADDR_EXPR, build_pointer_type TREE_TYPE (elt), elt);
819 addr = fold_convert (ptr_type_node, elt ? elt : base);
820 addr = fold_build2 (PLUS_EXPR, ptr_type_node,
821 addr, fold_convert (ptr_type_node,
822 byte_position (field)));
823 }
824 else
825 addr = build1 (ADDR_EXPR, build_pointer_type (type), t);
826
827 limit = fold_build2 (MINUS_EXPR, mf_uintptr_type,
828 fold_build2 (PLUS_EXPR, mf_uintptr_type,
829 convert (mf_uintptr_type, addr),
830 size),
831 integer_one_node);
832 }
833 break;
834
835 case INDIRECT_REF:
836 addr = TREE_OPERAND (t, 0);
837 base = addr;
838 limit = fold_build2 (MINUS_EXPR, ptr_type_node,
839 fold_build2 (PLUS_EXPR, ptr_type_node, base, size),
840 integer_one_node);
841 break;
842
843 case TARGET_MEM_REF:
844 addr = tree_mem_ref_addr (ptr_type_node, t);
845 base = addr;
846 limit = fold_build2 (MINUS_EXPR, ptr_type_node,
847 fold_build2 (PLUS_EXPR, ptr_type_node, base, size),
848 build_int_cst (ptr_type_node, 1));
849 break;
850
851 case ARRAY_RANGE_REF:
852 warning (0, "mudflap checking not yet implemented for ARRAY_RANGE_REF");
853 return;
854
855 case BIT_FIELD_REF:
856 /* ??? merge with COMPONENT_REF code above? */
857 {
858 tree ofs, rem, bpu;
859
860 /* If we're not dereferencing something, then the access
861 must be ok. */
862 if (TREE_CODE (TREE_OPERAND (t, 0)) != INDIRECT_REF)
863 return;
864
865 bpu = bitsize_int (BITS_PER_UNIT);
866 ofs = convert (bitsizetype, TREE_OPERAND (t, 2));
867 rem = size_binop (TRUNC_MOD_EXPR, ofs, bpu);
868 ofs = size_binop (TRUNC_DIV_EXPR, ofs, bpu);
869
870 size = convert (bitsizetype, TREE_OPERAND (t, 1));
871 size = size_binop (PLUS_EXPR, size, rem);
872 size = size_binop (CEIL_DIV_EXPR, size, bpu);
873 size = convert (sizetype, size);
874
875 addr = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
876 addr = convert (ptr_type_node, addr);
877 addr = fold_build2 (PLUS_EXPR, ptr_type_node, addr, ofs);
878
879 base = addr;
880 limit = fold_build2 (MINUS_EXPR, ptr_type_node,
881 fold_build2 (PLUS_EXPR, ptr_type_node, base, size),
882 integer_one_node);
883 }
884 break;
885
886 default:
887 return;
888 }
889
890 mf_build_check_statement_for (base, limit, iter, locus, dirflag);
891 }
892
893 static void
894 mf_xform_derefs (void)
895 {
896 basic_block bb, next;
897 block_stmt_iterator i;
898 int saved_last_basic_block = last_basic_block;
899
900 bb = ENTRY_BLOCK_PTR ->next_bb;
901 do
902 {
903 next = bb->next_bb;
904 for (i = bsi_start (bb); !bsi_end_p (i); bsi_next (&i))
905 {
906 tree s = bsi_stmt (i);
907
908 /* Only a few GIMPLE statements can reference memory. */
909 switch (TREE_CODE (s))
910 {
911 case MODIFY_EXPR:
912 mf_xform_derefs_1 (&i, &TREE_OPERAND (s, 0), EXPR_LOCUS (s),
913 integer_one_node);
914 mf_xform_derefs_1 (&i, &TREE_OPERAND (s, 1), EXPR_LOCUS (s),
915 integer_zero_node);
916 break;
917
918 case RETURN_EXPR:
919 if (TREE_OPERAND (s, 0) != NULL_TREE)
920 {
921 if (TREE_CODE (TREE_OPERAND (s, 0)) == MODIFY_EXPR)
922 mf_xform_derefs_1 (&i, &TREE_OPERAND (TREE_OPERAND (s, 0), 1),
923 EXPR_LOCUS (s), integer_zero_node);
924 else
925 mf_xform_derefs_1 (&i, &TREE_OPERAND (s, 0), EXPR_LOCUS (s),
926 integer_zero_node);
927 }
928 break;
929
930 default:
931 ;
932 }
933 }
934 bb = next;
935 }
936 while (bb && bb->index <= saved_last_basic_block);
937 }
938
939 /* ------------------------------------------------------------------------ */
940 /* ADDR_EXPR transforms. Perform the declaration-related mudflap tree
941 transforms on the current function.
942
943 This is the first part of the mudflap instrumentation. It works on
944 high-level GIMPLE because after lowering, all variables are moved out
945 of their BIND_EXPR binding context, and we lose liveness information
946 for the declarations we wish to instrument. */
947
948 static unsigned int
949 execute_mudflap_function_decls (void)
950 {
951 /* Don't instrument functions such as the synthetic constructor
952 built during mudflap_finish_file. */
953 if (mf_marked_p (current_function_decl) ||
954 DECL_ARTIFICIAL (current_function_decl))
955 return 0;
956
957 push_gimplify_context ();
958
959 mf_xform_decls (DECL_SAVED_TREE (current_function_decl),
960 DECL_ARGUMENTS (current_function_decl));
961
962 pop_gimplify_context (NULL);
963 return 0;
964 }
965
966 /* This struct is passed between mf_xform_decls to store state needed
967 during the traversal searching for objects that have their
968 addresses taken. */
969 struct mf_xform_decls_data
970 {
971 tree param_decls;
972 };
973
974
975 /* Synthesize a CALL_EXPR and a TRY_FINALLY_EXPR, for this chain of
976 _DECLs if appropriate. Arrange to call the __mf_register function
977 now, and the __mf_unregister function later for each. */
978 static void
979 mx_register_decls (tree decl, tree *stmt_list)
980 {
981 tree finally_stmts = NULL_TREE;
982 tree_stmt_iterator initially_stmts = tsi_start (*stmt_list);
983
984 while (decl != NULL_TREE)
985 {
986 if (mf_decl_eligible_p (decl)
987 /* Not already processed. */
988 && ! mf_marked_p (decl)
989 /* Automatic variable. */
990 && ! DECL_EXTERNAL (decl)
991 && ! TREE_STATIC (decl))
992 {
993 tree size = NULL_TREE, variable_name;
994 tree unregister_fncall, unregister_fncall_params;
995 tree register_fncall, register_fncall_params;
996
997 size = convert (size_type_node, TYPE_SIZE_UNIT (TREE_TYPE (decl)));
998
999 /* (& VARIABLE, sizeof (VARIABLE), __MF_TYPE_STACK) */
1000 unregister_fncall_params =
1001 tree_cons (NULL_TREE,
1002 convert (ptr_type_node,
1003 mf_mark (build1 (ADDR_EXPR,
1004 build_pointer_type (TREE_TYPE (decl)),
1005 decl))),
1006 tree_cons (NULL_TREE,
1007 size,
1008 tree_cons (NULL_TREE,
1009 /* __MF_TYPE_STACK */
1010 build_int_cst (NULL_TREE, 3),
1011 NULL_TREE)));
1012 /* __mf_unregister (...) */
1013 unregister_fncall = build_function_call_expr (mf_unregister_fndecl,
1014 unregister_fncall_params);
1015
1016 /* (& VARIABLE, sizeof (VARIABLE), __MF_TYPE_STACK, "name") */
1017 variable_name = mf_varname_tree (decl);
1018 register_fncall_params =
1019 tree_cons (NULL_TREE,
1020 convert (ptr_type_node,
1021 mf_mark (build1 (ADDR_EXPR,
1022 build_pointer_type (TREE_TYPE (decl)),
1023 decl))),
1024 tree_cons (NULL_TREE,
1025 size,
1026 tree_cons (NULL_TREE,
1027 /* __MF_TYPE_STACK */
1028 build_int_cst (NULL_TREE, 3),
1029 tree_cons (NULL_TREE,
1030 variable_name,
1031 NULL_TREE))));
1032
1033 /* __mf_register (...) */
1034 register_fncall = build_function_call_expr (mf_register_fndecl,
1035 register_fncall_params);
1036
1037 /* Accumulate the two calls. */
1038 /* ??? Set EXPR_LOCATION. */
1039 gimplify_stmt (&register_fncall);
1040 gimplify_stmt (&unregister_fncall);
1041
1042 /* Add the __mf_register call at the current appending point. */
1043 if (tsi_end_p (initially_stmts))
1044 warning (0, "mudflap cannot track %qs in stub function",
1045 IDENTIFIER_POINTER (DECL_NAME (decl)));
1046 else
1047 {
1048 tsi_link_before (&initially_stmts, register_fncall, TSI_SAME_STMT);
1049
1050 /* Accumulate the FINALLY piece. */
1051 append_to_statement_list (unregister_fncall, &finally_stmts);
1052 }
1053 mf_mark (decl);
1054 }
1055
1056 decl = TREE_CHAIN (decl);
1057 }
1058
1059 /* Actually, (initially_stmts!=NULL) <=> (finally_stmts!=NULL) */
1060 if (finally_stmts != NULL_TREE)
1061 {
1062 tree t = build2 (TRY_FINALLY_EXPR, void_type_node,
1063 *stmt_list, finally_stmts);
1064 *stmt_list = NULL;
1065 append_to_statement_list (t, stmt_list);
1066 }
1067 }
1068
1069
1070 /* Process every variable mentioned in BIND_EXPRs. */
1071 static tree
1072 mx_xfn_xform_decls (tree *t, int *continue_p, void *data)
1073 {
1074 struct mf_xform_decls_data* d = (struct mf_xform_decls_data*) data;
1075
1076 if (*t == NULL_TREE || *t == error_mark_node)
1077 {
1078 *continue_p = 0;
1079 return NULL_TREE;
1080 }
1081
1082 *continue_p = 1;
1083
1084 switch (TREE_CODE (*t))
1085 {
1086 case BIND_EXPR:
1087 {
1088 /* Process function parameters now (but only once). */
1089 mx_register_decls (d->param_decls, &BIND_EXPR_BODY (*t));
1090 d->param_decls = NULL_TREE;
1091
1092 mx_register_decls (BIND_EXPR_VARS (*t), &BIND_EXPR_BODY (*t));
1093 }
1094 break;
1095
1096 default:
1097 break;
1098 }
1099
1100 return NULL_TREE;
1101 }
1102
1103 /* Perform the object lifetime tracking mudflap transform on the given function
1104 tree. The tree is mutated in place, with possibly copied subtree nodes.
1105
1106 For every auto variable declared, if its address is ever taken
1107 within the function, then supply its lifetime to the mudflap
1108 runtime with the __mf_register and __mf_unregister calls.
1109 */
1110
1111 static void
1112 mf_xform_decls (tree fnbody, tree fnparams)
1113 {
1114 struct mf_xform_decls_data d;
1115 d.param_decls = fnparams;
1116 walk_tree_without_duplicates (&fnbody, mx_xfn_xform_decls, &d);
1117 }
1118
1119
1120 /* ------------------------------------------------------------------------ */
1121 /* Externally visible mudflap functions. */
1122
1123
1124 /* Mark and return the given tree node to prevent further mudflap
1125 transforms. */
1126 static GTY ((param_is (union tree_node))) htab_t marked_trees = NULL;
1127
1128 tree
1129 mf_mark (tree t)
1130 {
1131 void **slot;
1132
1133 if (marked_trees == NULL)
1134 marked_trees = htab_create_ggc (31, htab_hash_pointer, htab_eq_pointer, NULL);
1135
1136 slot = htab_find_slot (marked_trees, t, INSERT);
1137 *slot = t;
1138 return t;
1139 }
1140
1141 int
1142 mf_marked_p (tree t)
1143 {
1144 void *entry;
1145
1146 if (marked_trees == NULL)
1147 return 0;
1148
1149 entry = htab_find (marked_trees, t);
1150 return (entry != NULL);
1151 }
1152
1153 /* Remember given node as a static of some kind: global data,
1154 function-scope static, or an anonymous constant. Its assembler
1155 label is given. */
1156
1157 /* A list of globals whose incomplete declarations we encountered.
1158 Instead of emitting the __mf_register call for them here, it's
1159 delayed until program finish time. If they're still incomplete by
1160 then, warnings are emitted. */
1161
1162 static GTY (()) VEC(tree,gc) *deferred_static_decls;
1163
1164 /* A list of statements for calling __mf_register() at startup time. */
1165 static GTY (()) tree enqueued_call_stmt_chain;
1166
1167 static void
1168 mudflap_register_call (tree obj, tree object_size, tree varname)
1169 {
1170 tree arg, args, call_stmt;
1171
1172 args = tree_cons (NULL_TREE, varname, NULL_TREE);
1173
1174 arg = build_int_cst (NULL_TREE, 4); /* __MF_TYPE_STATIC */
1175 args = tree_cons (NULL_TREE, arg, args);
1176
1177 arg = convert (size_type_node, object_size);
1178 args = tree_cons (NULL_TREE, arg, args);
1179
1180 arg = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (obj)), obj);
1181 arg = convert (ptr_type_node, arg);
1182 args = tree_cons (NULL_TREE, arg, args);
1183
1184 call_stmt = build_function_call_expr (mf_register_fndecl, args);
1185
1186 append_to_statement_list (call_stmt, &enqueued_call_stmt_chain);
1187 }
1188
1189 void
1190 mudflap_enqueue_decl (tree obj)
1191 {
1192 if (mf_marked_p (obj))
1193 return;
1194
1195 /* We don't need to process variable decls that are internally
1196 generated extern. If we did, we'd end up with warnings for them
1197 during mudflap_finish_file (). That would confuse the user,
1198 since the text would refer to variables that don't show up in the
1199 user's source code. */
1200 if (DECL_P (obj) && DECL_EXTERNAL (obj) && DECL_ARTIFICIAL (obj))
1201 return;
1202
1203 VEC_safe_push (tree, gc, deferred_static_decls, obj);
1204 }
1205
1206
1207 void
1208 mudflap_enqueue_constant (tree obj)
1209 {
1210 tree object_size, varname;
1211
1212 if (mf_marked_p (obj))
1213 return;
1214
1215 if (TREE_CODE (obj) == STRING_CST)
1216 object_size = build_int_cst (NULL_TREE, TREE_STRING_LENGTH (obj));
1217 else
1218 object_size = size_in_bytes (TREE_TYPE (obj));
1219
1220 if (TREE_CODE (obj) == STRING_CST)
1221 varname = mf_build_string ("string literal");
1222 else
1223 varname = mf_build_string ("constant");
1224
1225 mudflap_register_call (obj, object_size, varname);
1226 }
1227
1228
1229 /* Emit any file-wide instrumentation. */
1230 void
1231 mudflap_finish_file (void)
1232 {
1233 tree ctor_statements = NULL_TREE;
1234
1235 /* No need to continue when there were errors. */
1236 if (errorcount != 0 || sorrycount != 0)
1237 return;
1238
1239 /* Insert a call to __mf_init. */
1240 {
1241 tree call2_stmt = build_function_call_expr (mf_init_fndecl, NULL_TREE);
1242 append_to_statement_list (call2_stmt, &ctor_statements);
1243 }
1244
1245 /* If appropriate, call __mf_set_options to pass along read-ignore mode. */
1246 if (flag_mudflap_ignore_reads)
1247 {
1248 tree arg = tree_cons (NULL_TREE,
1249 mf_build_string ("-ignore-reads"), NULL_TREE);
1250 tree call_stmt = build_function_call_expr (mf_set_options_fndecl, arg);
1251 append_to_statement_list (call_stmt, &ctor_statements);
1252 }
1253
1254 /* Process all enqueued object decls. */
1255 if (deferred_static_decls)
1256 {
1257 size_t i;
1258 tree obj;
1259 for (i = 0; VEC_iterate (tree, deferred_static_decls, i, obj); i++)
1260 {
1261 gcc_assert (DECL_P (obj));
1262
1263 if (mf_marked_p (obj))
1264 continue;
1265
1266 /* Omit registration for static unaddressed objects. NB:
1267 Perform registration for non-static objects regardless of
1268 TREE_USED or TREE_ADDRESSABLE, because they may be used
1269 from other compilation units. */
1270 if (! TREE_PUBLIC (obj) && ! TREE_ADDRESSABLE (obj))
1271 continue;
1272
1273 if (! COMPLETE_TYPE_P (TREE_TYPE (obj)))
1274 {
1275 warning (0, "mudflap cannot track unknown size extern %qs",
1276 IDENTIFIER_POINTER (DECL_NAME (obj)));
1277 continue;
1278 }
1279
1280 mudflap_register_call (obj,
1281 size_in_bytes (TREE_TYPE (obj)),
1282 mf_varname_tree (obj));
1283 }
1284
1285 VEC_truncate (tree, deferred_static_decls, 0);
1286 }
1287
1288 /* Append all the enqueued registration calls. */
1289 if (enqueued_call_stmt_chain)
1290 {
1291 append_to_statement_list (enqueued_call_stmt_chain, &ctor_statements);
1292 enqueued_call_stmt_chain = NULL_TREE;
1293 }
1294
1295 cgraph_build_static_cdtor ('I', ctor_statements,
1296 MAX_RESERVED_INIT_PRIORITY-1);
1297 }
1298
1299
1300 static bool
1301 gate_mudflap (void)
1302 {
1303 return flag_mudflap != 0;
1304 }
1305
1306 struct tree_opt_pass pass_mudflap_1 =
1307 {
1308 "mudflap1", /* name */
1309 gate_mudflap, /* gate */
1310 execute_mudflap_function_decls, /* execute */
1311 NULL, /* sub */
1312 NULL, /* next */
1313 0, /* static_pass_number */
1314 0, /* tv_id */
1315 PROP_gimple_any, /* properties_required */
1316 0, /* properties_provided */
1317 0, /* properties_destroyed */
1318 0, /* todo_flags_start */
1319 TODO_dump_func, /* todo_flags_finish */
1320 0 /* letter */
1321 };
1322
1323 struct tree_opt_pass pass_mudflap_2 =
1324 {
1325 "mudflap2", /* name */
1326 gate_mudflap, /* gate */
1327 execute_mudflap_function_ops, /* execute */
1328 NULL, /* sub */
1329 NULL, /* next */
1330 0, /* static_pass_number */
1331 0, /* tv_id */
1332 PROP_gimple_leh, /* properties_required */
1333 0, /* properties_provided */
1334 0, /* properties_destroyed */
1335 0, /* todo_flags_start */
1336 TODO_verify_flow | TODO_verify_stmts
1337 | TODO_dump_func, /* todo_flags_finish */
1338 0 /* letter */
1339 };
1340
1341 #include "gt-tree-mudflap.h"