re PR ipa/61324 (ICE: SIGSEGV at ipa-comdats.c:321 with -fno-use-cxa-atexit -fkeep...
[gcc.git] / gcc / ipa-chkp.c
1 /* Pointer Bounds Checker IPA passes.
2 Copyright (C) 2014 Free Software Foundation, Inc.
3 Contributed by Ilya Enkovich (ilya.enkovich@intel.com)
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tree-core.h"
25 #include "stor-layout.h"
26 #include "tree.h"
27 #include "tree-pass.h"
28 #include "stringpool.h"
29 #include "bitmap.h"
30 #include "gimple-expr.h"
31 #include "tm.h"
32 #include "hard-reg-set.h"
33 #include "function.h"
34 #include "is-a.h"
35 #include "tree-ssa-alias.h"
36 #include "predict.h"
37 #include "basic-block.h"
38 #include "gimple.h"
39 #include "ipa-ref.h"
40 #include "lto-streamer.h"
41 #include "cgraph.h"
42 #include "tree-chkp.h"
43 #include "ipa-chkp.h"
44
45 /* Pointer Bounds Checker has two IPA passes to support code instrumentation.
46
47 In instrumented code each pointer is provided with bounds. For input
48 pointer parameters it means we also have bounds passed. For calls it
49 means we have additional bounds arguments for pointer arguments.
50
51 To have all IPA optimizations working correctly we have to express
52 dataflow between passed and received bounds explicitly via additional
53 entries in function declaration arguments list and in function type.
54 Since we may have both instrumented and not instrumented code at the
55 same time, we cannot replace all original functions with their
56 instrumented variants. Therefore we create clones (versions) instead.
57
58 Instrumentation clones creation is a separate IPA pass which is a part
59 of early local passes. Clones are created after SSA is built (because
60 instrumentation pass works on SSA) and before any transformations
61 which may change pointer flow and therefore lead to incorrect code
62 instrumentation (possibly causing false bounds check failures).
63
64 Instrumentation clones have pointer bounds arguments added right after
65 pointer arguments. Clones have assembler name of the original
66 function with suffix added. New assembler name is in transparent
67 alias chain with the original name. Thus we expect all calls to the
68 original and instrumented functions look similar in assembler.
69
70 During instrumentation versioning pass we create instrumented versions
71 of all function with body and also for all their aliases and thunks.
72 Clones for functions with no body are created on demand (usually
73 during call instrumentation).
74
75 Original and instrumented function nodes are connected with IPA
76 reference IPA_REF_CHKP. It is mostly done to have reachability
77 analysis working correctly. We may have no references to the
78 instrumented function in the code but it still should be counted
79 as reachable if the original function is reachable.
80
81 When original function bodies are not needed anymore we release
82 them and transform functions into a special kind of thunks. Each
83 thunk has a call edge to the instrumented version. These thunks
84 help to keep externally visible instrumented functions visible
85 when linker resolution files are used. Linker has no info about
86 connection between original and instrumented function and
87 therefore we may wrongly decide (due to difference in assembler
88 names) that instrumented function version is local and can be
89 removed. */
90
91 #define CHKP_BOUNDS_OF_SYMBOL_PREFIX "__chkp_bounds_of_"
92
93 /* Build a clone of FNDECL with a modified name. */
94
95 static tree
96 chkp_build_instrumented_fndecl (tree fndecl)
97 {
98 tree new_decl = copy_node (fndecl);
99 tree new_name;
100 std::string s;
101
102 /* called_as_built_in checks DECL_NAME to identify calls to
103 builtins. We want instrumented calls to builtins to be
104 recognized by called_as_built_in. Therefore use original
105 DECL_NAME for cloning with no prefixes. */
106 s = IDENTIFIER_POINTER (DECL_NAME (fndecl));
107 s += ".chkp";
108 DECL_NAME (new_decl) = get_identifier (s.c_str ());
109
110 /* References to the original and to the instrumented version
111 should look the same in the output assembly. And we cannot
112 use the same assembler name for the instrumented version
113 because it conflicts with decl merging algorithms in LTO.
114 Achieve the result by using transparent alias name for the
115 instrumented version. */
116 s = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
117 s += ".chkp";
118 new_name = get_identifier (s.c_str ());
119 IDENTIFIER_TRANSPARENT_ALIAS (new_name) = 1;
120 TREE_CHAIN (new_name) = DECL_ASSEMBLER_NAME (fndecl);
121 SET_DECL_ASSEMBLER_NAME (new_decl, new_name);
122
123 /* For functions with body versioning will make a copy of arguments.
124 For functions with no body we need to do it here. */
125 if (!gimple_has_body_p (fndecl))
126 DECL_ARGUMENTS (new_decl) = copy_list (DECL_ARGUMENTS (fndecl));
127
128 /* We are going to modify attributes list and therefore should
129 make own copy. */
130 DECL_ATTRIBUTES (new_decl) = copy_list (DECL_ATTRIBUTES (fndecl));
131
132 /* Change builtin function code. */
133 if (DECL_BUILT_IN (new_decl))
134 {
135 gcc_assert (DECL_BUILT_IN_CLASS (new_decl) == BUILT_IN_NORMAL);
136 gcc_assert (DECL_FUNCTION_CODE (new_decl) < BEGIN_CHKP_BUILTINS);
137 DECL_FUNCTION_CODE (new_decl)
138 = (enum built_in_function)(DECL_FUNCTION_CODE (new_decl)
139 + BEGIN_CHKP_BUILTINS + 1);
140 }
141
142 return new_decl;
143 }
144
145
146 /* Fix operands of attribute from ATTRS list named ATTR_NAME.
147 Integer operands are replaced with values according to
148 INDEXES map having LEN elements. For operands out of len
149 we just add DELTA. */
150
151 static void
152 chkp_map_attr_arg_indexes (tree attrs, const char *attr_name,
153 unsigned *indexes, int len, int delta)
154 {
155 tree attr = lookup_attribute (attr_name, attrs);
156 tree op;
157
158 if (!attr)
159 return;
160
161 TREE_VALUE (attr) = copy_list (TREE_VALUE (attr));
162 for (op = TREE_VALUE (attr); op; op = TREE_CHAIN (op))
163 {
164 int idx;
165
166 if (TREE_CODE (TREE_VALUE (op)) != INTEGER_CST)
167 continue;
168
169 idx = TREE_INT_CST_LOW (TREE_VALUE (op));
170
171 /* If idx exceeds indexes length then we just
172 keep it at the same distance from the last
173 known arg. */
174 if (idx > len)
175 idx += delta;
176 else
177 idx = indexes[idx - 1] + 1;
178 TREE_VALUE (op) = build_int_cst (TREE_TYPE (TREE_VALUE (op)), idx);
179 }
180 }
181
182 /* Make a copy of function type ORIG_TYPE adding pointer
183 bounds as additional arguments. */
184
185 tree
186 chkp_copy_function_type_adding_bounds (tree orig_type)
187 {
188 tree type;
189 tree arg_type, attrs, t;
190 unsigned len = list_length (TYPE_ARG_TYPES (orig_type));
191 unsigned *indexes = XALLOCAVEC (unsigned, len);
192 unsigned idx = 0, new_idx = 0;
193
194 for (arg_type = TYPE_ARG_TYPES (orig_type);
195 arg_type;
196 arg_type = TREE_CHAIN (arg_type))
197 if (TREE_VALUE (arg_type) == void_type_node)
198 continue;
199 else if (BOUNDED_TYPE_P (TREE_VALUE (arg_type))
200 || pass_by_reference (NULL, TYPE_MODE (TREE_VALUE (arg_type)),
201 TREE_VALUE (arg_type), true)
202 || chkp_type_has_pointer (TREE_VALUE (arg_type)))
203 break;
204
205 /* We may use original type if there are no bounds passed. */
206 if (!arg_type)
207 return orig_type;
208
209 type = copy_node (orig_type);
210 TYPE_ARG_TYPES (type) = copy_list (TYPE_ARG_TYPES (type));
211
212 for (arg_type = TYPE_ARG_TYPES (type);
213 arg_type;
214 arg_type = TREE_CHAIN (arg_type))
215 {
216 indexes[idx++] = new_idx++;
217
218 /* pass_by_reference returns 1 for void type,
219 so check for it first. */
220 if (TREE_VALUE (arg_type) == void_type_node)
221 continue;
222 else if (BOUNDED_TYPE_P (TREE_VALUE (arg_type))
223 || pass_by_reference (NULL, TYPE_MODE (TREE_VALUE (arg_type)),
224 TREE_VALUE (arg_type), true))
225 {
226 tree new_type = build_tree_list (NULL_TREE,
227 pointer_bounds_type_node);
228 TREE_CHAIN (new_type) = TREE_CHAIN (arg_type);
229 TREE_CHAIN (arg_type) = new_type;
230
231 arg_type = TREE_CHAIN (arg_type);
232 new_idx++;
233 }
234 else if (chkp_type_has_pointer (TREE_VALUE (arg_type)))
235 {
236 bitmap slots = BITMAP_ALLOC (NULL);
237 bitmap_iterator bi;
238 unsigned bnd_no;
239
240 chkp_find_bound_slots (TREE_VALUE (arg_type), slots);
241
242 EXECUTE_IF_SET_IN_BITMAP (slots, 0, bnd_no, bi)
243 {
244 tree new_type = build_tree_list (NULL_TREE,
245 pointer_bounds_type_node);
246 TREE_CHAIN (new_type) = TREE_CHAIN (arg_type);
247 TREE_CHAIN (arg_type) = new_type;
248
249 arg_type = TREE_CHAIN (arg_type);
250 new_idx++;
251 }
252 BITMAP_FREE (slots);
253 }
254 }
255
256 /* If function type has attribute with arg indexes then
257 we have to copy it fixing attribute ops. Map for
258 fixing is in indexes array. */
259 attrs = TYPE_ATTRIBUTES (type);
260 if (lookup_attribute ("nonnull", attrs)
261 || lookup_attribute ("format", attrs)
262 || lookup_attribute ("format_arg", attrs))
263 {
264 int delta = new_idx - len;
265 attrs = copy_list (TYPE_ATTRIBUTES (type));
266 chkp_map_attr_arg_indexes (attrs, "nonnull", indexes, len, delta);
267 chkp_map_attr_arg_indexes (attrs, "format", indexes, len, delta);
268 chkp_map_attr_arg_indexes (attrs, "format_arg", indexes, len, delta);
269 TYPE_ATTRIBUTES (type) = attrs;
270 }
271
272 t = TYPE_MAIN_VARIANT (orig_type);
273 if (orig_type != t)
274 {
275 TYPE_MAIN_VARIANT (type) = t;
276 TYPE_NEXT_VARIANT (type) = TYPE_NEXT_VARIANT (t);
277 TYPE_NEXT_VARIANT (t) = type;
278 }
279 else
280 {
281 TYPE_MAIN_VARIANT (type) = type;
282 TYPE_NEXT_VARIANT (type) = NULL;
283 }
284
285
286 return type;
287 }
288
289 /* For given function FNDECL add bounds arguments to arguments
290 list. */
291
292 static void
293 chkp_add_bounds_params_to_function (tree fndecl)
294 {
295 tree arg;
296
297 for (arg = DECL_ARGUMENTS (fndecl); arg; arg = DECL_CHAIN (arg))
298 if (BOUNDED_P (arg))
299 {
300 std::string new_name = CHKP_BOUNDS_OF_SYMBOL_PREFIX;
301 tree new_arg;
302
303 if (DECL_NAME (arg))
304 new_name += IDENTIFIER_POINTER (DECL_NAME (arg));
305 else
306 {
307 char uid[25];
308 snprintf (uid, 25, "D.%u", DECL_UID (arg));
309 new_name += uid;
310 }
311
312 new_arg = build_decl (DECL_SOURCE_LOCATION (arg), PARM_DECL,
313 get_identifier (new_name.c_str ()),
314 pointer_bounds_type_node);
315 DECL_ARG_TYPE (new_arg) = pointer_bounds_type_node;
316 DECL_CONTEXT (new_arg) = DECL_CONTEXT (arg);
317 DECL_ARTIFICIAL (new_arg) = 1;
318 DECL_CHAIN (new_arg) = DECL_CHAIN (arg);
319 DECL_CHAIN (arg) = new_arg;
320
321 arg = DECL_CHAIN (arg);
322
323 }
324 else if (chkp_type_has_pointer (TREE_TYPE (arg)))
325 {
326 tree orig_arg = arg;
327 bitmap slots = BITMAP_ALLOC (NULL);
328 bitmap_iterator bi;
329 unsigned bnd_no;
330
331 chkp_find_bound_slots (TREE_TYPE (arg), slots);
332
333 EXECUTE_IF_SET_IN_BITMAP (slots, 0, bnd_no, bi)
334 {
335 std::string new_name = CHKP_BOUNDS_OF_SYMBOL_PREFIX;
336 tree new_arg;
337 char offs[25];
338
339 if (DECL_NAME (orig_arg))
340 new_name += IDENTIFIER_POINTER (DECL_NAME (orig_arg));
341 else
342 {
343 snprintf (offs, 25, "D.%u", DECL_UID (arg));
344 new_name += offs;
345 }
346 snprintf (offs, 25, "__%u", bnd_no * POINTER_SIZE / BITS_PER_UNIT);
347
348 new_arg = build_decl (DECL_SOURCE_LOCATION (orig_arg),
349 PARM_DECL,
350 get_identifier (new_name.c_str ()),
351 pointer_bounds_type_node);
352 DECL_ARG_TYPE (new_arg) = pointer_bounds_type_node;
353 DECL_CONTEXT (new_arg) = DECL_CONTEXT (orig_arg);
354 DECL_ARTIFICIAL (new_arg) = 1;
355 DECL_CHAIN (new_arg) = DECL_CHAIN (arg);
356 DECL_CHAIN (arg) = new_arg;
357
358 arg = DECL_CHAIN (arg);
359 }
360 BITMAP_FREE (slots);
361 }
362
363 TREE_TYPE (fndecl) =
364 chkp_copy_function_type_adding_bounds (TREE_TYPE (fndecl));
365 }
366
367 /* Return an instrumentation clone for builtin function
368 FNDECL. Create one if needed. */
369
370 tree
371 chkp_maybe_clone_builtin_fndecl (tree fndecl)
372 {
373 tree clone;
374 enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
375
376 gcc_assert (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
377 && fcode < BEGIN_CHKP_BUILTINS);
378
379 fcode = (enum built_in_function) (fcode + BEGIN_CHKP_BUILTINS + 1);
380 clone = builtin_decl_explicit (fcode);
381 if (clone)
382 return clone;
383
384 clone = chkp_build_instrumented_fndecl (fndecl);
385 chkp_add_bounds_params_to_function (clone);
386
387 gcc_assert (DECL_FUNCTION_CODE (clone) == fcode);
388
389 set_builtin_decl (fcode, clone, false);
390
391 return clone;
392 }
393
394 /* Return clone created for instrumentation of NODE or NULL. */
395
396 cgraph_node *
397 chkp_maybe_create_clone (tree fndecl)
398 {
399 cgraph_node *node = cgraph_node::get_create (fndecl);
400 cgraph_node *clone = node->instrumented_version;
401
402 gcc_assert (!node->instrumentation_clone);
403
404 if (DECL_BUILT_IN (fndecl)
405 && (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL
406 || DECL_FUNCTION_CODE (fndecl) >= BEGIN_CHKP_BUILTINS))
407 return NULL;
408
409 clone = node->instrumented_version;
410
411 /* Some instrumented builtin function calls may be optimized and
412 cgraph nodes may be removed as unreachable. Later optimizations
413 may generate new calls to removed functions and in this case
414 we have to recreate cgraph node. FUNCTION_DECL for instrumented
415 builtin still exists and should be reused in such case. */
416 if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
417 && fndecl == builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl))
418 && !clone)
419 {
420 enum built_in_function fncode = DECL_FUNCTION_CODE (fndecl);
421 tree new_decl;
422
423 fncode = (enum built_in_function) (fncode + BEGIN_CHKP_BUILTINS + 1);
424 new_decl = builtin_decl_explicit (fncode);
425
426 /* We've actually already created an instrumented clone once.
427 Restore it. */
428 if (new_decl)
429 {
430 clone = cgraph_node::get (new_decl);
431
432 if (!clone)
433 {
434 gcc_assert (!gimple_has_body_p (fndecl));
435 clone = cgraph_node::get_create (new_decl);
436 clone->externally_visible = node->externally_visible;
437 clone->local = node->local;
438 clone->address_taken = node->address_taken;
439 clone->thunk = node->thunk;
440 clone->alias = node->alias;
441 clone->weakref = node->weakref;
442 clone->cpp_implicit_alias = node->cpp_implicit_alias;
443 clone->orig_decl = fndecl;
444 clone->instrumentation_clone = true;
445 }
446
447 clone->instrumented_version = node;
448 node->instrumented_version = clone;
449 }
450 }
451
452 if (!clone)
453 {
454 tree new_decl = chkp_build_instrumented_fndecl (fndecl);
455 struct cgraph_edge *e;
456 struct ipa_ref *ref;
457 int i;
458
459 clone = node->create_version_clone (new_decl, vNULL, NULL);
460 clone->externally_visible = node->externally_visible;
461 clone->local = node->local;
462 clone->address_taken = node->address_taken;
463 clone->thunk = node->thunk;
464 clone->alias = node->alias;
465 clone->weakref = node->weakref;
466 clone->cpp_implicit_alias = node->cpp_implicit_alias;
467 clone->instrumented_version = node;
468 clone->orig_decl = fndecl;
469 clone->instrumentation_clone = true;
470 node->instrumented_version = clone;
471
472 if (gimple_has_body_p (fndecl))
473 {
474 /* If function will not be instrumented, then it's instrumented
475 version is a thunk for the original. */
476 if (lookup_attribute ("bnd_legacy", DECL_ATTRIBUTES (fndecl))
477 || (flag_chkp_instrument_marked_only
478 && !lookup_attribute ("bnd_instrument", DECL_ATTRIBUTES (fndecl))))
479 {
480 clone->thunk.thunk_p = true;
481 clone->thunk.add_pointer_bounds_args = true;
482 clone->create_edge (node, NULL, 0, CGRAPH_FREQ_BASE);
483 }
484 else
485 {
486 tree_function_versioning (fndecl, new_decl, NULL, false,
487 NULL, false, NULL, NULL);
488 clone->lowered = true;
489 }
490 }
491
492 /* New params are inserted after versioning because it
493 actually copies args list from the original decl. */
494 chkp_add_bounds_params_to_function (new_decl);
495
496 /* Remember builtin fndecl. */
497 if (DECL_BUILT_IN_CLASS (clone->decl) == BUILT_IN_NORMAL
498 && fndecl == builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
499 {
500 gcc_assert (!builtin_decl_explicit (DECL_FUNCTION_CODE (clone->decl)));
501 set_builtin_decl (DECL_FUNCTION_CODE (clone->decl),
502 clone->decl, false);
503 }
504
505 /* Clones have the same comdat group as originals. */
506 if (node->same_comdat_group
507 || DECL_ONE_ONLY (node->decl))
508 clone->add_to_same_comdat_group (node);
509
510 if (gimple_has_body_p (fndecl))
511 symtab->call_cgraph_insertion_hooks (clone);
512
513 /* Clone all aliases. */
514 for (i = 0; node->iterate_referring (i, ref); i++)
515 if (ref->use == IPA_REF_ALIAS)
516 {
517 struct cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
518 struct cgraph_node *chkp_alias
519 = chkp_maybe_create_clone (alias->decl);
520 chkp_alias->create_reference (clone, IPA_REF_ALIAS, NULL);
521 }
522
523 /* Clone all thunks. */
524 for (e = node->callers; e; e = e->next_caller)
525 if (e->caller->thunk.thunk_p)
526 {
527 struct cgraph_node *thunk
528 = chkp_maybe_create_clone (e->caller->decl);
529 /* Redirect thunk clone edge to the node clone. */
530 thunk->callees->redirect_callee (clone);
531 }
532
533 /* For aliases and thunks we should make sure target is cloned
534 to have proper references and edges. */
535 if (node->thunk.thunk_p)
536 chkp_maybe_create_clone (node->callees->callee->decl);
537 else if (node->alias)
538 {
539 struct cgraph_node *target;
540
541 ref = node->ref_list.first_reference ();
542 if (ref)
543 chkp_maybe_create_clone (ref->referred->decl);
544
545 if (node->alias_target)
546 {
547 if (TREE_CODE (node->alias_target) == FUNCTION_DECL)
548 {
549 target = chkp_maybe_create_clone (node->alias_target);
550 clone->alias_target = target->decl;
551 }
552 else
553 clone->alias_target = node->alias_target;
554 }
555 }
556
557 /* Add IPA reference. It's main role is to keep instrumented
558 version reachable while original node is reachable. */
559 ref = node->create_reference (clone, IPA_REF_CHKP, NULL);
560 }
561
562 return clone;
563 }
564
565 /* Create clone for all functions to be instrumented. */
566
567 static unsigned int
568 chkp_versioning (void)
569 {
570 struct cgraph_node *node;
571
572 bitmap_obstack_initialize (NULL);
573
574 FOR_EACH_DEFINED_FUNCTION (node)
575 {
576 if (!node->instrumentation_clone
577 && !node->instrumented_version
578 && !node->alias
579 && !node->thunk.thunk_p
580 && !lookup_attribute ("bnd_legacy", DECL_ATTRIBUTES (node->decl))
581 && (!flag_chkp_instrument_marked_only
582 || lookup_attribute ("bnd_instrument",
583 DECL_ATTRIBUTES (node->decl)))
584 && (!DECL_BUILT_IN (node->decl)
585 || (DECL_BUILT_IN_CLASS (node->decl) == BUILT_IN_NORMAL
586 && DECL_FUNCTION_CODE (node->decl) < BEGIN_CHKP_BUILTINS)))
587 chkp_maybe_create_clone (node->decl);
588 }
589
590 /* Mark all aliases and thunks of functions with no instrumented
591 version as legacy function. */
592 FOR_EACH_DEFINED_FUNCTION (node)
593 {
594 if (!node->instrumentation_clone
595 && !node->instrumented_version
596 && (node->alias || node->thunk.thunk_p)
597 && !lookup_attribute ("bnd_legacy", DECL_ATTRIBUTES (node->decl)))
598 DECL_ATTRIBUTES (node->decl)
599 = tree_cons (get_identifier ("bnd_legacy"), NULL,
600 DECL_ATTRIBUTES (node->decl));
601 }
602
603 bitmap_obstack_release (NULL);
604
605 return 0;
606 }
607
608 /* In this pass we remove bodies of functions having
609 instrumented version. Functions with removed bodies
610 become a special kind of thunks to provide a connection
611 between calls to the original version and instrumented
612 function. */
613
614 static unsigned int
615 chkp_produce_thunks (void)
616 {
617 struct cgraph_node *node;
618
619 FOR_EACH_DEFINED_FUNCTION (node)
620 {
621 if (!node->instrumentation_clone
622 && node->instrumented_version
623 && gimple_has_body_p (node->decl)
624 && gimple_has_body_p (node->instrumented_version->decl))
625 {
626 node->release_body ();
627 node->remove_callees ();
628 node->remove_all_references ();
629
630 node->thunk.thunk_p = true;
631 node->thunk.add_pointer_bounds_args = true;
632 node->create_edge (node->instrumented_version, NULL,
633 0, CGRAPH_FREQ_BASE);
634 node->create_reference (node->instrumented_version,
635 IPA_REF_CHKP, NULL);
636 }
637 }
638
639 /* Mark instrumentation clones created for aliases and thunks
640 as insttrumented so they could be removed as unreachable
641 now. */
642 FOR_EACH_DEFINED_FUNCTION (node)
643 {
644 if (node->instrumentation_clone
645 && (node->alias || node->thunk.thunk_p)
646 && !chkp_function_instrumented_p (node->decl))
647 chkp_function_mark_instrumented (node->decl);
648 }
649
650 return TODO_remove_functions;
651 }
652
653 const pass_data pass_data_ipa_chkp_versioning =
654 {
655 SIMPLE_IPA_PASS, /* type */
656 "chkp_versioning", /* name */
657 OPTGROUP_NONE, /* optinfo_flags */
658 TV_NONE, /* tv_id */
659 0, /* properties_required */
660 0, /* properties_provided */
661 0, /* properties_destroyed */
662 0, /* todo_flags_start */
663 0 /* todo_flags_finish */
664 };
665
666 const pass_data pass_data_ipa_chkp_produce_thunks =
667 {
668 SIMPLE_IPA_PASS, /* type */
669 "chkp_cleanup", /* name */
670 OPTGROUP_NONE, /* optinfo_flags */
671 TV_NONE, /* tv_id */
672 0, /* properties_required */
673 0, /* properties_provided */
674 0, /* properties_destroyed */
675 0, /* todo_flags_start */
676 0 /* todo_flags_finish */
677 };
678
679 class pass_ipa_chkp_versioning : public simple_ipa_opt_pass
680 {
681 public:
682 pass_ipa_chkp_versioning (gcc::context *ctxt)
683 : simple_ipa_opt_pass (pass_data_ipa_chkp_versioning, ctxt)
684 {}
685
686 /* opt_pass methods: */
687 virtual opt_pass * clone ()
688 {
689 return new pass_ipa_chkp_versioning (m_ctxt);
690 }
691
692 virtual bool gate (function *)
693 {
694 return flag_check_pointer_bounds;
695 }
696
697 virtual unsigned int execute (function *)
698 {
699 return chkp_versioning ();
700 }
701
702 }; // class pass_ipa_chkp_versioning
703
704 class pass_ipa_chkp_produce_thunks : public simple_ipa_opt_pass
705 {
706 public:
707 pass_ipa_chkp_produce_thunks (gcc::context *ctxt)
708 : simple_ipa_opt_pass (pass_data_ipa_chkp_produce_thunks, ctxt)
709 {}
710
711 /* opt_pass methods: */
712 virtual opt_pass * clone ()
713 {
714 return new pass_ipa_chkp_produce_thunks (m_ctxt);
715 }
716
717 virtual bool gate (function *)
718 {
719 return flag_check_pointer_bounds;
720 }
721
722 virtual unsigned int execute (function *)
723 {
724 return chkp_produce_thunks ();
725 }
726
727 }; // class pass_chkp_produce_thunks
728
729 simple_ipa_opt_pass *
730 make_pass_ipa_chkp_versioning (gcc::context *ctxt)
731 {
732 return new pass_ipa_chkp_versioning (ctxt);
733 }
734
735 simple_ipa_opt_pass *
736 make_pass_ipa_chkp_produce_thunks (gcc::context *ctxt)
737 {
738 return new pass_ipa_chkp_produce_thunks (ctxt);
739 }