Fix typo in chnagelog entry
[official-gcc.git] / gcc / tree-mudflap.c
blob90d044891889c7c7152364df488f26fe59bdf395
1 /* Mudflap: narrow-pointer bounds-checking by tree rewriting.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012
3 Free Software Foundation, Inc.
4 Contributed by Frank Ch. Eigler <fche@redhat.com>
5 and Graydon Hoare <graydon@redhat.com>
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "tree.h"
29 #include "tm_p.h"
30 #include "basic-block.h"
31 #include "flags.h"
32 #include "function.h"
33 #include "tree-inline.h"
34 #include "gimple.h"
35 #include "tree-iterator.h"
36 #include "tree-flow.h"
37 #include "tree-mudflap.h"
38 #include "tree-pass.h"
39 #include "hashtab.h"
40 #include "diagnostic.h"
41 #include "demangle.h"
42 #include "langhooks.h"
43 #include "ggc.h"
44 #include "cgraph.h"
45 #include "gimple.h"
47 extern void add_bb_to_loop (basic_block, struct loop *);
49 /* Internal function decls */
52 /* Options. */
53 #define flag_mudflap_threads (flag_mudflap == 2)
55 /* Helpers. */
56 static tree mf_build_string (const char *string);
57 static tree mf_varname_tree (tree);
58 static tree mf_file_function_line_tree (location_t);
60 /* Indirection-related instrumentation. */
61 static void mf_decl_cache_locals (void);
62 static void mf_decl_clear_locals (void);
63 static void mf_xform_statements (void);
64 static unsigned int execute_mudflap_function_ops (void);
66 /* Addressable variables instrumentation. */
67 static void mf_xform_decls (gimple_seq, tree);
68 static tree mx_xfn_xform_decls (gimple_stmt_iterator *, bool *,
69 struct walk_stmt_info *);
70 static gimple_seq mx_register_decls (tree, gimple_seq, location_t);
71 static unsigned int execute_mudflap_function_decls (void);
73 /* Return true if DECL is artificial stub that shouldn't be instrumented by
74 mf. We should instrument clones of non-artificial functions. */
75 static inline bool
76 mf_artificial (const_tree decl)
78 return DECL_ARTIFICIAL (DECL_ORIGIN (decl));
81 /* ------------------------------------------------------------------------ */
82 /* Some generally helpful functions for mudflap instrumentation. */
84 /* Build a reference to a literal string. */
85 static tree
86 mf_build_string (const char *string)
88 size_t len = strlen (string);
89 tree result = mf_mark (build_string (len + 1, string));
91 TREE_TYPE (result) = build_array_type
92 (char_type_node, build_index_type (size_int (len)));
93 TREE_CONSTANT (result) = 1;
94 TREE_READONLY (result) = 1;
95 TREE_STATIC (result) = 1;
97 result = build1 (ADDR_EXPR, build_pointer_type (char_type_node), result);
99 return mf_mark (result);
102 /* Create a properly typed STRING_CST node that describes the given
103 declaration. It will be used as an argument for __mf_register().
104 Try to construct a helpful string, including file/function/variable
105 name. */
107 static tree
108 mf_varname_tree (tree decl)
110 static pretty_printer buf_rec;
111 static int initialized = 0;
112 pretty_printer *buf = & buf_rec;
113 const char *buf_contents;
114 tree result;
116 gcc_assert (decl);
118 if (!initialized)
120 pp_construct (buf, /* prefix */ NULL, /* line-width */ 0);
121 initialized = 1;
123 pp_clear_output_area (buf);
125 /* Add FILENAME[:LINENUMBER[:COLUMNNUMBER]]. */
127 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (decl));
128 const char *sourcefile;
129 unsigned sourceline = xloc.line;
130 unsigned sourcecolumn = 0;
131 sourcecolumn = xloc.column;
132 sourcefile = xloc.file;
133 if (sourcefile == NULL && current_function_decl != NULL_TREE)
134 sourcefile = DECL_SOURCE_FILE (current_function_decl);
135 if (sourcefile == NULL)
136 sourcefile = "<unknown file>";
138 pp_string (buf, sourcefile);
140 if (sourceline != 0)
142 pp_string (buf, ":");
143 pp_decimal_int (buf, sourceline);
145 if (sourcecolumn != 0)
147 pp_string (buf, ":");
148 pp_decimal_int (buf, sourcecolumn);
153 if (current_function_decl != NULL_TREE)
155 /* Add (FUNCTION) */
156 pp_string (buf, " (");
158 const char *funcname = NULL;
159 if (DECL_NAME (current_function_decl))
160 funcname = lang_hooks.decl_printable_name (current_function_decl, 1);
161 if (funcname == NULL)
162 funcname = "anonymous fn";
164 pp_string (buf, funcname);
166 pp_string (buf, ") ");
168 else
169 pp_string (buf, " ");
171 /* Add <variable-declaration>, possibly demangled. */
173 const char *declname = NULL;
175 if (DECL_NAME (decl) != NULL)
177 if (strcmp ("GNU C++", lang_hooks.name) == 0)
179 /* The gcc/cp decl_printable_name hook doesn't do as good a job as
180 the libiberty demangler. */
181 declname = cplus_demangle (IDENTIFIER_POINTER (DECL_NAME (decl)),
182 DMGL_AUTO | DMGL_VERBOSE);
184 if (declname == NULL)
185 declname = lang_hooks.decl_printable_name (decl, 3);
187 if (declname == NULL)
188 declname = "<unnamed variable>";
190 pp_string (buf, declname);
193 /* Return the lot as a new STRING_CST. */
194 buf_contents = pp_base_formatted_text (buf);
195 result = mf_build_string (buf_contents);
196 pp_clear_output_area (buf);
198 return result;
202 /* And another friend, for producing a simpler message. */
204 static tree
205 mf_file_function_line_tree (location_t location)
207 expanded_location xloc = expand_location (location);
208 const char *file = NULL, *colon, *line, *op, *name, *cp;
209 char linecolbuf[30]; /* Enough for two decimal numbers plus a colon. */
210 char *string;
211 tree result;
213 /* Add FILENAME[:LINENUMBER[:COLUMNNUMBER]]. */
214 file = xloc.file;
215 if (file == NULL && current_function_decl != NULL_TREE)
216 file = DECL_SOURCE_FILE (current_function_decl);
217 if (file == NULL)
218 file = "<unknown file>";
220 if (xloc.line > 0)
222 if (xloc.column > 0)
223 sprintf (linecolbuf, "%d:%d", xloc.line, xloc.column);
224 else
225 sprintf (linecolbuf, "%d", xloc.line);
226 colon = ":";
227 line = linecolbuf;
229 else
230 colon = line = "";
232 /* Add (FUNCTION). */
233 name = lang_hooks.decl_printable_name (current_function_decl, 1);
234 if (name)
236 op = " (";
237 cp = ")";
239 else
240 op = name = cp = "";
242 string = concat (file, colon, line, op, name, cp, NULL);
243 result = mf_build_string (string);
244 free (string);
246 return result;
250 /* global tree nodes */
252 /* Global tree objects for global variables and functions exported by
253 mudflap runtime library. mf_init_extern_trees must be called
254 before using these. */
256 /* uintptr_t (usually "unsigned long") */
257 static GTY (()) tree mf_uintptr_type;
259 /* struct __mf_cache { uintptr_t low; uintptr_t high; }; */
260 static GTY (()) tree mf_cache_struct_type;
262 /* struct __mf_cache * const */
263 static GTY (()) tree mf_cache_structptr_type;
265 /* extern struct __mf_cache __mf_lookup_cache []; */
266 static GTY (()) tree mf_cache_array_decl;
268 /* extern unsigned char __mf_lc_shift; */
269 static GTY (()) tree mf_cache_shift_decl;
271 /* extern uintptr_t __mf_lc_mask; */
272 static GTY (()) tree mf_cache_mask_decl;
274 /* Their function-scope local shadows, used in single-threaded mode only. */
276 /* auto const unsigned char __mf_lc_shift_l; */
277 static GTY (()) tree mf_cache_shift_decl_l;
279 /* auto const uintptr_t __mf_lc_mask_l; */
280 static GTY (()) tree mf_cache_mask_decl_l;
282 /* extern void __mf_check (void *ptr, size_t sz, int type, const char *); */
283 static GTY (()) tree mf_check_fndecl;
285 /* extern void __mf_register (void *ptr, size_t sz, int type, const char *); */
286 static GTY (()) tree mf_register_fndecl;
288 /* extern void __mf_unregister (void *ptr, size_t sz, int type); */
289 static GTY (()) tree mf_unregister_fndecl;
291 /* extern void __mf_init (); */
292 static GTY (()) tree mf_init_fndecl;
294 /* extern int __mf_set_options (const char*); */
295 static GTY (()) tree mf_set_options_fndecl;
298 /* Helper for mudflap_init: construct a decl with the given category,
299 name, and type, mark it an external reference, and pushdecl it. */
300 static inline tree
301 mf_make_builtin (enum tree_code category, const char *name, tree type)
303 tree decl = mf_mark (build_decl (UNKNOWN_LOCATION,
304 category, get_identifier (name), type));
305 TREE_PUBLIC (decl) = 1;
306 DECL_EXTERNAL (decl) = 1;
307 lang_hooks.decls.pushdecl (decl);
308 /* The decl was declared by the compiler. */
309 DECL_ARTIFICIAL (decl) = 1;
310 /* And we don't want debug info for it. */
311 DECL_IGNORED_P (decl) = 1;
312 return decl;
315 /* Helper for mudflap_init: construct a tree corresponding to the type
316 struct __mf_cache { uintptr_t low; uintptr_t high; };
317 where uintptr_t is the FIELD_TYPE argument. */
318 static inline tree
319 mf_make_mf_cache_struct_type (tree field_type)
321 /* There is, abominably, no language-independent way to construct a
322 RECORD_TYPE. So we have to call the basic type construction
323 primitives by hand. */
324 tree fieldlo = build_decl (UNKNOWN_LOCATION,
325 FIELD_DECL, get_identifier ("low"), field_type);
326 tree fieldhi = build_decl (UNKNOWN_LOCATION,
327 FIELD_DECL, get_identifier ("high"), field_type);
329 tree struct_type = make_node (RECORD_TYPE);
330 DECL_CONTEXT (fieldlo) = struct_type;
331 DECL_CONTEXT (fieldhi) = struct_type;
332 DECL_CHAIN (fieldlo) = fieldhi;
333 TYPE_FIELDS (struct_type) = fieldlo;
334 TYPE_NAME (struct_type) = get_identifier ("__mf_cache");
335 layout_type (struct_type);
337 return struct_type;
340 /* Initialize the global tree nodes that correspond to mf-runtime.h
341 declarations. */
342 void
343 mudflap_init (void)
345 static bool done = false;
346 tree mf_const_string_type;
347 tree mf_cache_array_type;
348 tree mf_check_register_fntype;
349 tree mf_unregister_fntype;
350 tree mf_init_fntype;
351 tree mf_set_options_fntype;
353 if (done)
354 return;
355 done = true;
357 mf_uintptr_type = lang_hooks.types.type_for_mode (ptr_mode,
358 /*unsignedp=*/true);
359 mf_const_string_type
360 = build_pointer_type (build_qualified_type
361 (char_type_node, TYPE_QUAL_CONST));
363 mf_cache_struct_type = mf_make_mf_cache_struct_type (mf_uintptr_type);
364 mf_cache_structptr_type = build_pointer_type (mf_cache_struct_type);
365 mf_cache_array_type = build_array_type (mf_cache_struct_type, 0);
366 mf_check_register_fntype =
367 build_function_type_list (void_type_node, ptr_type_node, size_type_node,
368 integer_type_node, mf_const_string_type, NULL_TREE);
369 mf_unregister_fntype =
370 build_function_type_list (void_type_node, ptr_type_node, size_type_node,
371 integer_type_node, NULL_TREE);
372 mf_init_fntype =
373 build_function_type_list (void_type_node, NULL_TREE);
374 mf_set_options_fntype =
375 build_function_type_list (integer_type_node, mf_const_string_type, NULL_TREE);
377 mf_cache_array_decl = mf_make_builtin (VAR_DECL, "__mf_lookup_cache",
378 mf_cache_array_type);
379 mf_cache_shift_decl = mf_make_builtin (VAR_DECL, "__mf_lc_shift",
380 unsigned_char_type_node);
381 mf_cache_mask_decl = mf_make_builtin (VAR_DECL, "__mf_lc_mask",
382 mf_uintptr_type);
383 /* Don't process these in mudflap_enqueue_decl, should they come by
384 there for some reason. */
385 mf_mark (mf_cache_array_decl);
386 mf_mark (mf_cache_shift_decl);
387 mf_mark (mf_cache_mask_decl);
388 mf_check_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_check",
389 mf_check_register_fntype);
390 mf_register_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_register",
391 mf_check_register_fntype);
392 mf_unregister_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_unregister",
393 mf_unregister_fntype);
394 mf_init_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_init",
395 mf_init_fntype);
396 mf_set_options_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_set_options",
397 mf_set_options_fntype);
401 /* ------------------------------------------------------------------------ */
402 /* This is the second part of the mudflap instrumentation. It works on
403 low-level GIMPLE using the CFG, because we want to run this pass after
404 tree optimizations have been performed, but we have to preserve the CFG
405 for expansion from trees to RTL.
406 Below is the list of transformations performed on statements in the
407 current function.
409 1) Memory reference transforms: Perform the mudflap indirection-related
410 tree transforms on memory references.
412 2) Mark BUILTIN_ALLOCA calls not inlineable.
416 static unsigned int
417 execute_mudflap_function_ops (void)
419 struct gimplify_ctx gctx;
421 /* Don't instrument functions such as the synthetic constructor
422 built during mudflap_finish_file. */
423 if (mf_marked_p (current_function_decl)
424 || mf_artificial (current_function_decl))
425 return 0;
427 push_gimplify_context (&gctx);
429 /* In multithreaded mode, don't cache the lookup cache parameters. */
430 if (! flag_mudflap_threads)
431 mf_decl_cache_locals ();
433 mf_xform_statements ();
435 if (! flag_mudflap_threads)
436 mf_decl_clear_locals ();
438 pop_gimplify_context (NULL);
439 return 0;
442 /* Insert a gimple_seq SEQ on all the outgoing edges out of BB. Note that
443 if BB has more than one edge, STMT will be replicated for each edge.
444 Also, abnormal edges will be ignored. */
446 static void
447 insert_edge_copies_seq (gimple_seq seq, basic_block bb)
449 edge e;
450 edge_iterator ei;
451 unsigned n_copies = -1;
453 FOR_EACH_EDGE (e, ei, bb->succs)
454 if (!(e->flags & EDGE_ABNORMAL))
455 n_copies++;
457 FOR_EACH_EDGE (e, ei, bb->succs)
458 if (!(e->flags & EDGE_ABNORMAL))
459 gsi_insert_seq_on_edge (e, n_copies-- > 0 ? gimple_seq_copy (seq) : seq);
462 /* Create and initialize local shadow variables for the lookup cache
463 globals. Put their decls in the *_l globals for use by
464 mf_build_check_statement_for. */
466 static void
467 mf_decl_cache_locals (void)
469 gimple g;
470 gimple_seq seq = NULL;
472 /* Build the cache vars. */
473 mf_cache_shift_decl_l
474 = mf_mark (create_tmp_reg (TREE_TYPE (mf_cache_shift_decl),
475 "__mf_lookup_shift_l"));
477 mf_cache_mask_decl_l
478 = mf_mark (create_tmp_reg (TREE_TYPE (mf_cache_mask_decl),
479 "__mf_lookup_mask_l"));
481 /* Build initialization nodes for the cache vars. We just load the
482 globals into the cache variables. */
483 g = gimple_build_assign (mf_cache_shift_decl_l, mf_cache_shift_decl);
484 gimple_set_location (g, DECL_SOURCE_LOCATION (current_function_decl));
485 gimple_seq_add_stmt (&seq, g);
487 g = gimple_build_assign (mf_cache_mask_decl_l, mf_cache_mask_decl);
488 gimple_set_location (g, DECL_SOURCE_LOCATION (current_function_decl));
489 gimple_seq_add_stmt (&seq, g);
491 insert_edge_copies_seq (seq, ENTRY_BLOCK_PTR);
493 gsi_commit_edge_inserts ();
497 static void
498 mf_decl_clear_locals (void)
500 /* Unset local shadows. */
501 mf_cache_shift_decl_l = NULL_TREE;
502 mf_cache_mask_decl_l = NULL_TREE;
505 static void
506 mf_build_check_statement_for (tree base, tree limit,
507 gimple_stmt_iterator *instr_gsi,
508 location_t location, tree dirflag)
510 gimple_stmt_iterator gsi;
511 basic_block cond_bb, then_bb, join_bb;
512 edge e;
513 tree cond, t, u, v;
514 tree mf_base;
515 tree mf_elem;
516 tree mf_limit;
517 gimple g;
518 gimple_seq seq, stmts;
520 /* We first need to split the current basic block, and start altering
521 the CFG. This allows us to insert the statements we're about to
522 construct into the right basic blocks. */
524 cond_bb = gimple_bb (gsi_stmt (*instr_gsi));
525 gsi = *instr_gsi;
526 gsi_prev (&gsi);
527 if (! gsi_end_p (gsi))
528 e = split_block (cond_bb, gsi_stmt (gsi));
529 else
530 e = split_block_after_labels (cond_bb);
531 cond_bb = e->src;
532 join_bb = e->dest;
534 /* A recap at this point: join_bb is the basic block at whose head
535 is the gimple statement for which this check expression is being
536 built. cond_bb is the (possibly new, synthetic) basic block the
537 end of which will contain the cache-lookup code, and a
538 conditional that jumps to the cache-miss code or, much more
539 likely, over to join_bb. */
541 /* Create the bb that contains the cache-miss fallback block (mf_check). */
542 then_bb = create_empty_bb (cond_bb);
543 make_edge (cond_bb, then_bb, EDGE_TRUE_VALUE);
544 make_single_succ_edge (then_bb, join_bb, EDGE_FALLTHRU);
546 /* Mark the pseudo-fallthrough edge from cond_bb to join_bb. */
547 e = find_edge (cond_bb, join_bb);
548 e->flags = EDGE_FALSE_VALUE;
549 e->count = cond_bb->count;
550 e->probability = REG_BR_PROB_BASE;
552 /* Update dominance info. Note that bb_join's data was
553 updated by split_block. */
554 if (dom_info_available_p (CDI_DOMINATORS))
556 set_immediate_dominator (CDI_DOMINATORS, then_bb, cond_bb);
557 set_immediate_dominator (CDI_DOMINATORS, join_bb, cond_bb);
560 /* Update loop info. */
561 if (current_loops)
562 add_bb_to_loop (then_bb, cond_bb->loop_father);
564 /* Build our local variables. */
565 mf_elem = create_tmp_reg (mf_cache_structptr_type, "__mf_elem");
566 mf_base = create_tmp_reg (mf_uintptr_type, "__mf_base");
567 mf_limit = create_tmp_reg (mf_uintptr_type, "__mf_limit");
569 /* Build: __mf_base = (uintptr_t) <base address expression>. */
570 seq = NULL;
571 t = fold_convert_loc (location, mf_uintptr_type,
572 unshare_expr (base));
573 t = force_gimple_operand (t, &stmts, false, NULL_TREE);
574 gimple_seq_add_seq (&seq, stmts);
575 g = gimple_build_assign (mf_base, t);
576 gimple_set_location (g, location);
577 gimple_seq_add_stmt (&seq, g);
579 /* Build: __mf_limit = (uintptr_t) <limit address expression>. */
580 t = fold_convert_loc (location, mf_uintptr_type,
581 unshare_expr (limit));
582 t = force_gimple_operand (t, &stmts, false, NULL_TREE);
583 gimple_seq_add_seq (&seq, stmts);
584 g = gimple_build_assign (mf_limit, t);
585 gimple_set_location (g, location);
586 gimple_seq_add_stmt (&seq, g);
588 /* Build: __mf_elem = &__mf_lookup_cache [(__mf_base >> __mf_shift)
589 & __mf_mask]. */
590 t = build2 (RSHIFT_EXPR, mf_uintptr_type, mf_base,
591 flag_mudflap_threads ? mf_cache_shift_decl
592 : mf_cache_shift_decl_l);
593 t = build2 (BIT_AND_EXPR, mf_uintptr_type, t,
594 flag_mudflap_threads ? mf_cache_mask_decl
595 : mf_cache_mask_decl_l);
596 t = build4 (ARRAY_REF,
597 TREE_TYPE (TREE_TYPE (mf_cache_array_decl)),
598 mf_cache_array_decl, t, NULL_TREE, NULL_TREE);
599 t = build1 (ADDR_EXPR, mf_cache_structptr_type, t);
600 t = force_gimple_operand (t, &stmts, false, NULL_TREE);
601 gimple_seq_add_seq (&seq, stmts);
602 g = gimple_build_assign (mf_elem, t);
603 gimple_set_location (g, location);
604 gimple_seq_add_stmt (&seq, g);
606 /* Quick validity check.
608 if (__mf_elem->low > __mf_base
609 || (__mf_elem_high < __mf_limit))
611 __mf_check ();
612 ... and only if single-threaded:
613 __mf_lookup_shift_1 = f...;
614 __mf_lookup_mask_l = ...;
617 It is expected that this body of code is rarely executed so we mark
618 the edge to the THEN clause of the conditional jump as unlikely. */
620 /* Construct t <-- '__mf_elem->low > __mf_base'. */
621 t = build3 (COMPONENT_REF, mf_uintptr_type,
622 build1 (INDIRECT_REF, mf_cache_struct_type, mf_elem),
623 TYPE_FIELDS (mf_cache_struct_type), NULL_TREE);
624 t = build2 (GT_EXPR, boolean_type_node, t, mf_base);
626 /* Construct '__mf_elem->high < __mf_limit'.
628 First build:
629 1) u <-- '__mf_elem->high'
630 2) v <-- '__mf_limit'.
632 Then build 'u <-- (u < v). */
634 u = build3 (COMPONENT_REF, mf_uintptr_type,
635 build1 (INDIRECT_REF, mf_cache_struct_type, mf_elem),
636 DECL_CHAIN (TYPE_FIELDS (mf_cache_struct_type)), NULL_TREE);
638 v = mf_limit;
640 u = build2 (LT_EXPR, boolean_type_node, u, v);
642 /* Build the composed conditional: t <-- 't || u'. Then store the
643 result of the evaluation of 't' in a temporary variable which we
644 can use as the condition for the conditional jump. */
645 t = build2 (TRUTH_OR_EXPR, boolean_type_node, t, u);
646 t = force_gimple_operand (t, &stmts, false, NULL_TREE);
647 gimple_seq_add_seq (&seq, stmts);
648 cond = create_tmp_reg (boolean_type_node, "__mf_unlikely_cond");
649 g = gimple_build_assign (cond, t);
650 gimple_set_location (g, location);
651 gimple_seq_add_stmt (&seq, g);
653 /* Build the conditional jump. 'cond' is just a temporary so we can
654 simply build a void COND_EXPR. We do need labels in both arms though. */
655 g = gimple_build_cond (NE_EXPR, cond, boolean_false_node, NULL_TREE,
656 NULL_TREE);
657 gimple_set_location (g, location);
658 gimple_seq_add_stmt (&seq, g);
660 /* At this point, after so much hard work, we have only constructed
661 the conditional jump,
663 if (__mf_elem->low > __mf_base
664 || (__mf_elem_high < __mf_limit))
666 The lowered GIMPLE tree representing this code is in the statement
667 list starting at 'head'.
669 We can insert this now in the current basic block, i.e. the one that
670 the statement we're instrumenting was originally in. */
671 gsi = gsi_last_bb (cond_bb);
672 gsi_insert_seq_after (&gsi, seq, GSI_CONTINUE_LINKING);
674 /* Now build up the body of the cache-miss handling:
676 __mf_check();
677 refresh *_l vars.
679 This is the body of the conditional. */
681 seq = NULL;
682 /* u is a string, so it is already a gimple value. */
683 u = mf_file_function_line_tree (location);
684 /* NB: we pass the overall [base..limit] range to mf_check. */
685 v = fold_build2_loc (location, PLUS_EXPR, mf_uintptr_type,
686 fold_build2_loc (location,
687 MINUS_EXPR, mf_uintptr_type, mf_limit, mf_base),
688 build_int_cst (mf_uintptr_type, 1));
689 v = force_gimple_operand (v, &stmts, true, NULL_TREE);
690 gimple_seq_add_seq (&seq, stmts);
691 g = gimple_build_call (mf_check_fndecl, 4, mf_base, v, dirflag, u);
692 gimple_seq_add_stmt (&seq, g);
694 if (! flag_mudflap_threads)
696 if (stmt_ends_bb_p (g))
698 gsi = gsi_start_bb (then_bb);
699 gsi_insert_seq_after (&gsi, seq, GSI_CONTINUE_LINKING);
700 e = split_block (then_bb, g);
701 then_bb = e->dest;
702 seq = NULL;
705 g = gimple_build_assign (mf_cache_shift_decl_l, mf_cache_shift_decl);
706 gimple_seq_add_stmt (&seq, g);
708 g = gimple_build_assign (mf_cache_mask_decl_l, mf_cache_mask_decl);
709 gimple_seq_add_stmt (&seq, g);
712 /* Insert the check code in the THEN block. */
713 gsi = gsi_start_bb (then_bb);
714 gsi_insert_seq_after (&gsi, seq, GSI_CONTINUE_LINKING);
716 *instr_gsi = gsi_start_bb (join_bb);
720 /* Check whether the given decl, generally a VAR_DECL or PARM_DECL, is
721 eligible for instrumentation. For the mudflap1 pass, this implies
722 that it should be registered with the libmudflap runtime. For the
723 mudflap2 pass this means instrumenting an indirection operation with
724 respect to the object.
726 static int
727 mf_decl_eligible_p (tree decl)
729 return ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
730 /* The decl must have its address taken. In the case of
731 arrays, this flag is also set if the indexes are not
732 compile-time known valid constants. */
733 /* XXX: not sufficient: return-by-value structs! */
734 && TREE_ADDRESSABLE (decl)
735 /* The type of the variable must be complete. */
736 && COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (decl))
737 /* The decl hasn't been decomposed somehow. */
738 && !DECL_HAS_VALUE_EXPR_P (decl));
742 static void
743 mf_xform_derefs_1 (gimple_stmt_iterator *iter, tree *tp,
744 location_t location, tree dirflag)
746 tree type, base, limit, addr, size, t;
748 /* Don't instrument read operations. */
749 if (dirflag == integer_zero_node && flag_mudflap_ignore_reads)
750 return;
752 /* Don't instrument marked nodes. */
753 if (mf_marked_p (*tp))
754 return;
756 t = *tp;
757 type = TREE_TYPE (t);
759 if (type == error_mark_node)
760 return;
762 size = TYPE_SIZE_UNIT (type);
764 switch (TREE_CODE (t))
766 case ARRAY_REF:
767 case COMPONENT_REF:
769 /* This is trickier than it may first appear. The reason is
770 that we are looking at expressions from the "inside out" at
771 this point. We may have a complex nested aggregate/array
772 expression (e.g. "a.b[i].c"), maybe with an indirection as
773 the leftmost operator ("p->a.b.d"), where instrumentation
774 is necessary. Or we may have an innocent "a.b.c"
775 expression that must not be instrumented. We need to
776 recurse all the way down the nesting structure to figure it
777 out: looking just at the outer node is not enough. */
778 tree var;
779 int component_ref_only = (TREE_CODE (t) == COMPONENT_REF);
780 /* If we have a bitfield component reference, we must note the
781 innermost addressable object in ELT, from which we will
782 construct the byte-addressable bounds of the bitfield. */
783 tree elt = NULL_TREE;
784 int bitfield_ref_p = (TREE_CODE (t) == COMPONENT_REF
785 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (t, 1)));
787 /* Iterate to the top of the ARRAY_REF/COMPONENT_REF
788 containment hierarchy to find the outermost VAR_DECL. */
789 var = TREE_OPERAND (t, 0);
790 while (1)
792 if (bitfield_ref_p && elt == NULL_TREE
793 && (TREE_CODE (var) == ARRAY_REF
794 || TREE_CODE (var) == COMPONENT_REF))
795 elt = var;
797 if (TREE_CODE (var) == ARRAY_REF)
799 component_ref_only = 0;
800 var = TREE_OPERAND (var, 0);
802 else if (TREE_CODE (var) == COMPONENT_REF)
803 var = TREE_OPERAND (var, 0);
804 else if (INDIRECT_REF_P (var)
805 || TREE_CODE (var) == MEM_REF)
807 base = TREE_OPERAND (var, 0);
808 break;
810 else if (TREE_CODE (var) == VIEW_CONVERT_EXPR)
812 var = TREE_OPERAND (var, 0);
813 if (CONSTANT_CLASS_P (var)
814 && TREE_CODE (var) != STRING_CST)
815 return;
817 else
819 gcc_assert (TREE_CODE (var) == VAR_DECL
820 || TREE_CODE (var) == PARM_DECL
821 || TREE_CODE (var) == RESULT_DECL
822 || TREE_CODE (var) == STRING_CST);
823 /* Don't instrument this access if the underlying
824 variable is not "eligible". This test matches
825 those arrays that have only known-valid indexes,
826 and thus are not labeled TREE_ADDRESSABLE. */
827 if (! mf_decl_eligible_p (var) || component_ref_only)
828 return;
829 else
831 base = build1 (ADDR_EXPR,
832 build_pointer_type (TREE_TYPE (var)), var);
833 break;
838 /* Handle the case of ordinary non-indirection structure
839 accesses. These have only nested COMPONENT_REF nodes (no
840 INDIRECT_REF), but pass through the above filter loop.
841 Note that it's possible for such a struct variable to match
842 the eligible_p test because someone else might take its
843 address sometime. */
845 /* We need special processing for bitfield components, because
846 their addresses cannot be taken. */
847 if (bitfield_ref_p)
849 tree field = TREE_OPERAND (t, 1);
851 if (TREE_CODE (DECL_SIZE_UNIT (field)) == INTEGER_CST)
852 size = DECL_SIZE_UNIT (field);
854 if (elt)
855 elt = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (elt)),
856 elt);
857 addr = fold_convert_loc (location, ptr_type_node, elt ? elt : base);
858 addr = fold_build_pointer_plus_loc (location,
859 addr, byte_position (field));
861 else
862 addr = build1 (ADDR_EXPR, build_pointer_type (type), t);
864 limit = fold_build2_loc (location, MINUS_EXPR, mf_uintptr_type,
865 fold_build2_loc (location, PLUS_EXPR, mf_uintptr_type,
866 fold_convert (mf_uintptr_type, addr),
867 size),
868 integer_one_node);
870 break;
872 case INDIRECT_REF:
873 addr = TREE_OPERAND (t, 0);
874 base = addr;
875 limit = fold_build_pointer_plus_hwi_loc
876 (location, fold_build_pointer_plus_loc (location, base, size), -1);
877 break;
879 case MEM_REF:
880 if (addr_expr_of_non_mem_decl_p (TREE_OPERAND (t, 0)))
881 return;
883 addr = fold_build_pointer_plus_loc (location, TREE_OPERAND (t, 0),
884 TREE_OPERAND (t, 1));
885 base = addr;
886 limit = fold_build_pointer_plus_hwi_loc (location,
887 fold_build_pointer_plus_loc (location,
888 base, size), -1);
889 break;
891 case TARGET_MEM_REF:
892 if (addr_expr_of_non_mem_decl_p (TMR_BASE (t)))
893 return;
895 addr = tree_mem_ref_addr (ptr_type_node, t);
896 base = addr;
897 limit = fold_build_pointer_plus_hwi_loc (location,
898 fold_build_pointer_plus_loc (location,
899 base, size), -1);
900 break;
902 case ARRAY_RANGE_REF:
903 warning (OPT_Wmudflap,
904 "mudflap checking not yet implemented for ARRAY_RANGE_REF");
905 return;
907 case BIT_FIELD_REF:
908 /* ??? merge with COMPONENT_REF code above? */
910 tree ofs, rem, bpu;
912 /* If we're not dereferencing something, then the access
913 must be ok. */
914 if (TREE_CODE (TREE_OPERAND (t, 0)) != INDIRECT_REF)
915 return;
917 bpu = bitsize_int (BITS_PER_UNIT);
918 ofs = fold_convert (bitsizetype, TREE_OPERAND (t, 2));
919 rem = size_binop_loc (location, TRUNC_MOD_EXPR, ofs, bpu);
920 ofs = size_binop_loc (location, TRUNC_DIV_EXPR, ofs, bpu);
922 size = fold_convert (bitsizetype, TREE_OPERAND (t, 1));
923 size = size_binop_loc (location, PLUS_EXPR, size, rem);
924 size = size_binop_loc (location, CEIL_DIV_EXPR, size, bpu);
925 size = fold_convert (sizetype, size);
927 addr = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
928 addr = fold_convert (ptr_type_node, addr);
929 addr = fold_build_pointer_plus_loc (location, addr, ofs);
931 base = addr;
932 limit = fold_build_pointer_plus_hwi_loc (location,
933 fold_build_pointer_plus_loc (location,
934 base, size), -1);
936 break;
938 default:
939 return;
942 mf_build_check_statement_for (base, limit, iter, location, dirflag);
944 /* Transform
945 1) Memory references.
947 static void
948 mf_xform_statements (void)
950 basic_block bb, next;
951 gimple_stmt_iterator i;
952 int saved_last_basic_block = last_basic_block;
953 enum gimple_rhs_class grhs_class;
955 bb = ENTRY_BLOCK_PTR ->next_bb;
958 next = bb->next_bb;
959 for (i = gsi_start_bb (bb); !gsi_end_p (i); gsi_next (&i))
961 gimple s = gsi_stmt (i);
963 /* Only a few GIMPLE statements can reference memory. */
964 switch (gimple_code (s))
966 case GIMPLE_ASSIGN:
967 mf_xform_derefs_1 (&i, gimple_assign_lhs_ptr (s),
968 gimple_location (s), integer_one_node);
969 mf_xform_derefs_1 (&i, gimple_assign_rhs1_ptr (s),
970 gimple_location (s), integer_zero_node);
971 grhs_class = get_gimple_rhs_class (gimple_assign_rhs_code (s));
972 if (grhs_class == GIMPLE_BINARY_RHS)
973 mf_xform_derefs_1 (&i, gimple_assign_rhs2_ptr (s),
974 gimple_location (s), integer_zero_node);
975 break;
977 case GIMPLE_RETURN:
978 if (gimple_return_retval (s) != NULL_TREE)
980 mf_xform_derefs_1 (&i, gimple_return_retval_ptr (s),
981 gimple_location (s),
982 integer_zero_node);
984 break;
986 default:
990 bb = next;
992 while (bb && bb->index <= saved_last_basic_block);
995 /* ------------------------------------------------------------------------ */
996 /* ADDR_EXPR transforms. Perform the declaration-related mudflap tree
997 transforms on the current function.
999 This is the first part of the mudflap instrumentation. It works on
1000 high-level GIMPLE because after lowering, all variables are moved out
1001 of their BIND_EXPR binding context, and we lose liveness information
1002 for the declarations we wish to instrument. */
1004 static unsigned int
1005 execute_mudflap_function_decls (void)
1007 struct gimplify_ctx gctx;
1009 /* Don't instrument functions such as the synthetic constructor
1010 built during mudflap_finish_file. */
1011 if (mf_marked_p (current_function_decl)
1012 || mf_artificial (current_function_decl))
1013 return 0;
1015 push_gimplify_context (&gctx);
1017 mf_xform_decls (gimple_body (current_function_decl),
1018 DECL_ARGUMENTS (current_function_decl));
1020 pop_gimplify_context (NULL);
1021 return 0;
1024 /* This struct is passed between mf_xform_decls to store state needed
1025 during the traversal searching for objects that have their
1026 addresses taken. */
1027 struct mf_xform_decls_data
1029 tree param_decls;
1033 /* Synthesize a CALL_EXPR and a TRY_FINALLY_EXPR, for this chain of
1034 _DECLs if appropriate. Arrange to call the __mf_register function
1035 now, and the __mf_unregister function later for each. Return the
1036 gimple sequence after synthesis. */
1037 gimple_seq
1038 mx_register_decls (tree decl, gimple_seq seq, location_t location)
1040 gimple_seq finally_stmts = NULL;
1041 gimple_stmt_iterator initially_stmts = gsi_start (seq);
1043 while (decl != NULL_TREE)
1045 if (mf_decl_eligible_p (decl)
1046 /* Not already processed. */
1047 && ! mf_marked_p (decl)
1048 /* Automatic variable. */
1049 && ! DECL_EXTERNAL (decl)
1050 && ! TREE_STATIC (decl))
1052 tree size = NULL_TREE, variable_name;
1053 gimple unregister_fncall, register_fncall;
1054 tree unregister_fncall_param, register_fncall_param;
1056 /* Variable-sized objects should have sizes already been
1057 gimplified when we got here. */
1058 size = fold_convert (size_type_node,
1059 TYPE_SIZE_UNIT (TREE_TYPE (decl)));
1060 gcc_assert (is_gimple_val (size));
1063 unregister_fncall_param =
1064 mf_mark (build1 (ADDR_EXPR,
1065 build_pointer_type (TREE_TYPE (decl)),
1066 decl));
1067 /* __mf_unregister (&VARIABLE, sizeof (VARIABLE), __MF_TYPE_STACK) */
1068 unregister_fncall = gimple_build_call (mf_unregister_fndecl, 3,
1069 unregister_fncall_param,
1070 size,
1071 integer_three_node);
1074 variable_name = mf_varname_tree (decl);
1075 register_fncall_param =
1076 mf_mark (build1 (ADDR_EXPR,
1077 build_pointer_type (TREE_TYPE (decl)),
1078 decl));
1079 /* __mf_register (&VARIABLE, sizeof (VARIABLE), __MF_TYPE_STACK,
1080 "name") */
1081 register_fncall = gimple_build_call (mf_register_fndecl, 4,
1082 register_fncall_param,
1083 size,
1084 integer_three_node,
1085 variable_name);
1088 /* Accumulate the two calls. */
1089 gimple_set_location (register_fncall, location);
1090 gimple_set_location (unregister_fncall, location);
1092 /* Add the __mf_register call at the current appending point. */
1093 if (gsi_end_p (initially_stmts))
1095 if (!mf_artificial (decl))
1096 warning (OPT_Wmudflap,
1097 "mudflap cannot track %qE in stub function",
1098 DECL_NAME (decl));
1100 else
1102 gsi_insert_before (&initially_stmts, register_fncall,
1103 GSI_SAME_STMT);
1105 /* Accumulate the FINALLY piece. */
1106 gimple_seq_add_stmt (&finally_stmts, unregister_fncall);
1108 mf_mark (decl);
1111 decl = DECL_CHAIN (decl);
1114 /* Actually, (initially_stmts!=NULL) <=> (finally_stmts!=NULL) */
1115 if (finally_stmts != NULL)
1117 gimple stmt = gimple_build_try (seq, finally_stmts, GIMPLE_TRY_FINALLY);
1118 gimple_seq new_seq = NULL;
1120 gimple_seq_add_stmt (&new_seq, stmt);
1121 return new_seq;
1123 else
1124 return seq;
1128 /* Process every variable mentioned in BIND_EXPRs. */
1129 static tree
1130 mx_xfn_xform_decls (gimple_stmt_iterator *gsi,
1131 bool *handled_operands_p ATTRIBUTE_UNUSED,
1132 struct walk_stmt_info *wi)
1134 struct mf_xform_decls_data *d = (struct mf_xform_decls_data *) wi->info;
1135 gimple stmt = gsi_stmt (*gsi);
1137 switch (gimple_code (stmt))
1139 case GIMPLE_BIND:
1141 /* Process function parameters now (but only once). */
1142 if (d->param_decls)
1144 gimple_bind_set_body (stmt,
1145 mx_register_decls (d->param_decls,
1146 gimple_bind_body (stmt),
1147 gimple_location (stmt)));
1148 d->param_decls = NULL_TREE;
1151 gimple_bind_set_body (stmt,
1152 mx_register_decls (gimple_bind_vars (stmt),
1153 gimple_bind_body (stmt),
1154 gimple_location (stmt)));
1156 break;
1158 default:
1159 break;
1162 return NULL_TREE;
1165 /* Perform the object lifetime tracking mudflap transform on the given function
1166 tree. The tree is mutated in place, with possibly copied subtree nodes.
1168 For every auto variable declared, if its address is ever taken
1169 within the function, then supply its lifetime to the mudflap
1170 runtime with the __mf_register and __mf_unregister calls.
1173 static void
1174 mf_xform_decls (gimple_seq fnbody, tree fnparams)
1176 struct mf_xform_decls_data d;
1177 struct walk_stmt_info wi;
1178 struct pointer_set_t *pset = pointer_set_create ();
1180 d.param_decls = fnparams;
1181 memset (&wi, 0, sizeof (wi));
1182 wi.info = (void*) &d;
1183 wi.pset = pset;
1184 walk_gimple_seq (fnbody, mx_xfn_xform_decls, NULL, &wi);
1185 pointer_set_destroy (pset);
1189 /* ------------------------------------------------------------------------ */
1190 /* Externally visible mudflap functions. */
1193 /* Mark and return the given tree node to prevent further mudflap
1194 transforms. */
1195 static GTY ((param_is (union tree_node))) htab_t marked_trees = NULL;
1197 tree
1198 mf_mark (tree t)
1200 void **slot;
1202 if (marked_trees == NULL)
1203 marked_trees = htab_create_ggc (31, htab_hash_pointer, htab_eq_pointer,
1204 NULL);
1206 slot = htab_find_slot (marked_trees, t, INSERT);
1207 *slot = t;
1208 return t;
1212 mf_marked_p (tree t)
1214 void *entry;
1216 if (marked_trees == NULL)
1217 return 0;
1219 entry = htab_find (marked_trees, t);
1220 return (entry != NULL);
1223 /* Remember given node as a static of some kind: global data,
1224 function-scope static, or an anonymous constant. Its assembler
1225 label is given. */
1227 /* A list of globals whose incomplete declarations we encountered.
1228 Instead of emitting the __mf_register call for them here, it's
1229 delayed until program finish time. If they're still incomplete by
1230 then, warnings are emitted. */
1232 static GTY (()) vec<tree, va_gc> *deferred_static_decls;
1234 /* A list of statements for calling __mf_register() at startup time. */
1235 static GTY (()) tree enqueued_call_stmt_chain;
1237 static void
1238 mudflap_register_call (tree obj, tree object_size, tree varname)
1240 tree arg, call_stmt;
1242 arg = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (obj)), obj);
1243 arg = fold_convert (ptr_type_node, arg);
1245 call_stmt = build_call_expr (mf_register_fndecl, 4,
1246 arg,
1247 fold_convert (size_type_node, object_size),
1248 /* __MF_TYPE_STATIC */
1249 build_int_cst (integer_type_node, 4),
1250 varname);
1252 append_to_statement_list (call_stmt, &enqueued_call_stmt_chain);
1255 void
1256 mudflap_enqueue_decl (tree obj)
1258 if (mf_marked_p (obj))
1259 return;
1261 /* We don't need to process variable decls that are internally
1262 generated extern. If we did, we'd end up with warnings for them
1263 during mudflap_finish_file (). That would confuse the user,
1264 since the text would refer to variables that don't show up in the
1265 user's source code. */
1266 if (DECL_P (obj) && DECL_EXTERNAL (obj) && mf_artificial (obj))
1267 return;
1269 vec_safe_push (deferred_static_decls, obj);
1273 void
1274 mudflap_enqueue_constant (tree obj)
1276 tree object_size, varname;
1278 if (mf_marked_p (obj))
1279 return;
1281 if (TREE_CODE (obj) == STRING_CST)
1282 object_size = size_int (TREE_STRING_LENGTH (obj));
1283 else
1284 object_size = size_in_bytes (TREE_TYPE (obj));
1286 if (TREE_CODE (obj) == STRING_CST)
1287 varname = mf_build_string ("string literal");
1288 else
1289 varname = mf_build_string ("constant");
1291 mudflap_register_call (obj, object_size, varname);
1295 /* Emit any file-wide instrumentation. */
1296 void
1297 mudflap_finish_file (void)
1299 tree ctor_statements = NULL_TREE;
1301 /* No need to continue when there were errors. */
1302 if (seen_error ())
1303 return;
1305 /* Insert a call to __mf_init. */
1307 tree call2_stmt = build_call_expr (mf_init_fndecl, 0);
1308 append_to_statement_list (call2_stmt, &ctor_statements);
1311 /* If appropriate, call __mf_set_options to pass along read-ignore mode. */
1312 if (flag_mudflap_ignore_reads)
1314 tree arg = mf_build_string ("-ignore-reads");
1315 tree call_stmt = build_call_expr (mf_set_options_fndecl, 1, arg);
1316 append_to_statement_list (call_stmt, &ctor_statements);
1319 /* Process all enqueued object decls. */
1320 if (deferred_static_decls)
1322 size_t i;
1323 tree obj;
1324 FOR_EACH_VEC_ELT (*deferred_static_decls, i, obj)
1326 gcc_assert (DECL_P (obj));
1328 if (mf_marked_p (obj))
1329 continue;
1331 /* Omit registration for static unaddressed objects. NB:
1332 Perform registration for non-static objects regardless of
1333 TREE_USED or TREE_ADDRESSABLE, because they may be used
1334 from other compilation units. */
1335 if (! TREE_PUBLIC (obj) && ! TREE_ADDRESSABLE (obj))
1336 continue;
1338 if (! COMPLETE_TYPE_P (TREE_TYPE (obj)))
1340 warning (OPT_Wmudflap,
1341 "mudflap cannot track unknown size extern %qE",
1342 DECL_NAME (obj));
1343 continue;
1346 mudflap_register_call (obj,
1347 size_in_bytes (TREE_TYPE (obj)),
1348 mf_varname_tree (obj));
1351 deferred_static_decls->truncate (0);
1354 /* Append all the enqueued registration calls. */
1355 if (enqueued_call_stmt_chain)
1357 append_to_statement_list (enqueued_call_stmt_chain, &ctor_statements);
1358 enqueued_call_stmt_chain = NULL_TREE;
1361 cgraph_build_static_cdtor ('I', ctor_statements,
1362 MAX_RESERVED_INIT_PRIORITY-1);
1366 static bool
1367 gate_mudflap (void)
1369 return flag_mudflap != 0;
1372 struct gimple_opt_pass pass_mudflap_1 =
1375 GIMPLE_PASS,
1376 "mudflap1", /* name */
1377 OPTGROUP_NONE, /* optinfo_flags */
1378 gate_mudflap, /* gate */
1379 execute_mudflap_function_decls, /* execute */
1380 NULL, /* sub */
1381 NULL, /* next */
1382 0, /* static_pass_number */
1383 TV_NONE, /* tv_id */
1384 PROP_gimple_any, /* properties_required */
1385 0, /* properties_provided */
1386 0, /* properties_destroyed */
1387 0, /* todo_flags_start */
1388 0 /* todo_flags_finish */
1392 struct gimple_opt_pass pass_mudflap_2 =
1395 GIMPLE_PASS,
1396 "mudflap2", /* name */
1397 OPTGROUP_NONE, /* optinfo_flags */
1398 gate_mudflap, /* gate */
1399 execute_mudflap_function_ops, /* execute */
1400 NULL, /* sub */
1401 NULL, /* next */
1402 0, /* static_pass_number */
1403 TV_NONE, /* tv_id */
1404 PROP_ssa | PROP_cfg | PROP_gimple_leh,/* properties_required */
1405 0, /* properties_provided */
1406 0, /* properties_destroyed */
1407 0, /* todo_flags_start */
1408 TODO_verify_flow | TODO_verify_stmts
1409 | TODO_update_ssa /* todo_flags_finish */
1413 #include "gt-tree-mudflap.h"