aarch64 - Set the mode for the unspec in speculation_tracker insn.
[platform/upstream/linaro-gcc.git] / gcc / sanopt.c
1 /* Optimize and expand sanitizer functions.
2    Copyright (C) 2014-2016 Free Software Foundation, Inc.
3    Contributed by Marek Polacek <polacek@redhat.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 "backend.h"
25 #include "tree.h"
26 #include "gimple.h"
27 #include "tree-pass.h"
28 #include "tree-ssa-operands.h"
29 #include "gimple-pretty-print.h"
30 #include "fold-const.h"
31 #include "gimple-iterator.h"
32 #include "asan.h"
33 #include "ubsan.h"
34 #include "esan.h"
35 #include "params.h"
36 #include "tree-hash-traits.h"
37
38
39 /* This is used to carry information about basic blocks.  It is
40    attached to the AUX field of the standard CFG block.  */
41
42 struct sanopt_info
43 {
44   /* True if this BB might call (directly or indirectly) free/munmap
45      or similar operation.  */
46   bool has_freeing_call_p;
47
48   /* True if HAS_FREEING_CALL_P flag has been computed.  */
49   bool has_freeing_call_computed_p;
50
51   /* True if there is a block with HAS_FREEING_CALL_P flag set
52      on any path between an immediate dominator of BB, denoted
53      imm(BB), and BB.  */
54   bool imm_dom_path_with_freeing_call_p;
55
56   /* True if IMM_DOM_PATH_WITH_FREEING_CALL_P has been computed.  */
57   bool imm_dom_path_with_freeing_call_computed_p;
58
59   /* Number of possibly freeing calls encountered in this bb
60      (so far).  */
61   uint64_t freeing_call_events;
62
63   /* True if BB is currently being visited during computation
64      of IMM_DOM_PATH_WITH_FREEING_CALL_P flag.  */
65   bool being_visited_p;
66
67   /* True if this BB has been visited in the dominator walk.  */
68   bool visited_p;
69 };
70
71 /* If T has a single definition of form T = T2, return T2.  */
72
73 static tree
74 maybe_get_single_definition (tree t)
75 {
76   if (TREE_CODE (t) == SSA_NAME)
77     {
78       gimple *g = SSA_NAME_DEF_STMT (t);
79       if (gimple_assign_single_p (g))
80         return gimple_assign_rhs1 (g);
81     }
82   return NULL_TREE;
83 }
84
85 /* Tree triplet for vptr_check_map.  */
86 struct sanopt_tree_triplet
87 {
88   tree t1, t2, t3;
89 };
90
91 /* Traits class for tree triplet hash maps below.  */
92
93 struct sanopt_tree_triplet_hash : typed_noop_remove <sanopt_tree_triplet>
94 {
95   typedef sanopt_tree_triplet value_type;
96   typedef sanopt_tree_triplet compare_type;
97
98   static inline hashval_t
99   hash (const sanopt_tree_triplet &ref)
100   {
101     inchash::hash hstate (0);
102     inchash::add_expr (ref.t1, hstate);
103     inchash::add_expr (ref.t2, hstate);
104     inchash::add_expr (ref.t3, hstate);
105     return hstate.end ();
106   }
107
108   static inline bool
109   equal (const sanopt_tree_triplet &ref1, const sanopt_tree_triplet &ref2)
110   {
111     return operand_equal_p (ref1.t1, ref2.t1, 0)
112            && operand_equal_p (ref1.t2, ref2.t2, 0)
113            && operand_equal_p (ref1.t3, ref2.t3, 0);
114   }
115
116   static inline void
117   mark_deleted (sanopt_tree_triplet &ref)
118   {
119     ref.t1 = reinterpret_cast<tree> (1);
120   }
121
122   static inline void
123   mark_empty (sanopt_tree_triplet &ref)
124   {
125     ref.t1 = NULL;
126   }
127
128   static inline bool
129   is_deleted (const sanopt_tree_triplet &ref)
130   {
131     return ref.t1 == (void *) 1;
132   }
133
134   static inline bool
135   is_empty (const sanopt_tree_triplet &ref)
136   {
137     return ref.t1 == NULL;
138   }
139 };
140
141 /* This is used to carry various hash maps and variables used
142    in sanopt_optimize_walker.  */
143
144 struct sanopt_ctx
145 {
146   /* This map maps a pointer (the first argument of UBSAN_NULL) to
147      a vector of UBSAN_NULL call statements that check this pointer.  */
148   hash_map<tree, auto_vec<gimple *> > null_check_map;
149
150   /* This map maps a pointer (the second argument of ASAN_CHECK) to
151      a vector of ASAN_CHECK call statements that check the access.  */
152   hash_map<tree_operand_hash, auto_vec<gimple *> > asan_check_map;
153
154   /* This map maps a tree triplet (the first, second and fourth argument
155      of UBSAN_VPTR) to a vector of UBSAN_VPTR call statements that check
156      that virtual table pointer.  */
157   hash_map<sanopt_tree_triplet_hash, auto_vec<gimple *> > vptr_check_map;
158
159   /* Number of IFN_ASAN_CHECK statements.  */
160   int asan_num_accesses;
161 };
162
163
164 /* Return true if there might be any call to free/munmap operation
165    on any path in between DOM (which should be imm(BB)) and BB.  */
166
167 static bool
168 imm_dom_path_with_freeing_call (basic_block bb, basic_block dom)
169 {
170   sanopt_info *info = (sanopt_info *) bb->aux;
171   edge e;
172   edge_iterator ei;
173
174   if (info->imm_dom_path_with_freeing_call_computed_p)
175     return info->imm_dom_path_with_freeing_call_p;
176
177   info->being_visited_p = true;
178
179   FOR_EACH_EDGE (e, ei, bb->preds)
180     {
181       sanopt_info *pred_info = (sanopt_info *) e->src->aux;
182
183       if (e->src == dom)
184         continue;
185
186       if ((pred_info->imm_dom_path_with_freeing_call_computed_p
187           && pred_info->imm_dom_path_with_freeing_call_p)
188           || (pred_info->has_freeing_call_computed_p
189               && pred_info->has_freeing_call_p))
190         {
191           info->imm_dom_path_with_freeing_call_computed_p = true;
192           info->imm_dom_path_with_freeing_call_p = true;
193           info->being_visited_p = false;
194           return true;
195         }
196     }
197
198   FOR_EACH_EDGE (e, ei, bb->preds)
199     {
200       sanopt_info *pred_info = (sanopt_info *) e->src->aux;
201
202       if (e->src == dom)
203         continue;
204
205       if (pred_info->has_freeing_call_computed_p)
206         continue;
207
208       gimple_stmt_iterator gsi;
209       for (gsi = gsi_start_bb (e->src); !gsi_end_p (gsi); gsi_next (&gsi))
210         {
211           gimple *stmt = gsi_stmt (gsi);
212
213           if (is_gimple_call (stmt) && !nonfreeing_call_p (stmt))
214             {
215               pred_info->has_freeing_call_p = true;
216               break;
217             }
218         }
219
220       pred_info->has_freeing_call_computed_p = true;
221       if (pred_info->has_freeing_call_p)
222         {
223           info->imm_dom_path_with_freeing_call_computed_p = true;
224           info->imm_dom_path_with_freeing_call_p = true;
225           info->being_visited_p = false;
226           return true;
227         }
228     }
229
230   FOR_EACH_EDGE (e, ei, bb->preds)
231     {
232       if (e->src == dom)
233         continue;
234
235       basic_block src;
236       for (src = e->src; src != dom; )
237         {
238           sanopt_info *pred_info = (sanopt_info *) src->aux;
239           if (pred_info->being_visited_p)
240             break;
241           basic_block imm = get_immediate_dominator (CDI_DOMINATORS, src);
242           if (imm_dom_path_with_freeing_call (src, imm))
243             {
244               info->imm_dom_path_with_freeing_call_computed_p = true;
245               info->imm_dom_path_with_freeing_call_p = true;
246               info->being_visited_p = false;
247               return true;
248             }
249           src = imm;
250         }
251     }
252
253   info->imm_dom_path_with_freeing_call_computed_p = true;
254   info->imm_dom_path_with_freeing_call_p = false;
255   info->being_visited_p = false;
256   return false;
257 }
258
259 /* Get the first dominating check from the list of stored checks.
260    Non-dominating checks are silently dropped.  */
261
262 static gimple *
263 maybe_get_dominating_check (auto_vec<gimple *> &v)
264 {
265   for (; !v.is_empty (); v.pop ())
266     {
267       gimple *g = v.last ();
268       sanopt_info *si = (sanopt_info *) gimple_bb (g)->aux;
269       if (!si->visited_p)
270         /* At this point we shouldn't have any statements
271            that aren't dominating the current BB.  */
272         return g;
273     }
274   return NULL;
275 }
276
277 /* Optimize away redundant UBSAN_NULL calls.  */
278
279 static bool
280 maybe_optimize_ubsan_null_ifn (struct sanopt_ctx *ctx, gimple *stmt)
281 {
282   gcc_assert (gimple_call_num_args (stmt) == 3);
283   tree ptr = gimple_call_arg (stmt, 0);
284   tree cur_align = gimple_call_arg (stmt, 2);
285   gcc_assert (TREE_CODE (cur_align) == INTEGER_CST);
286   bool remove = false;
287
288   auto_vec<gimple *> &v = ctx->null_check_map.get_or_insert (ptr);
289   gimple *g = maybe_get_dominating_check (v);
290   if (!g)
291     {
292       /* For this PTR we don't have any UBSAN_NULL stmts recorded, so there's
293          nothing to optimize yet.  */
294       v.safe_push (stmt);
295       return false;
296     }
297
298   /* We already have recorded a UBSAN_NULL check for this pointer. Perhaps we
299      can drop this one.  But only if this check doesn't specify stricter
300      alignment.  */
301
302   tree align = gimple_call_arg (g, 2);
303   int kind = tree_to_shwi (gimple_call_arg (g, 1));
304   /* If this is a NULL pointer check where we had segv anyway, we can
305      remove it.  */
306   if (integer_zerop (align)
307       && (kind == UBSAN_LOAD_OF
308           || kind == UBSAN_STORE_OF
309           || kind == UBSAN_MEMBER_ACCESS))
310     remove = true;
311   /* Otherwise remove the check in non-recovering mode, or if the
312      stmts have same location.  */
313   else if (integer_zerop (align))
314     remove = (flag_sanitize_recover & SANITIZE_NULL) == 0
315               || flag_sanitize_undefined_trap_on_error
316               || gimple_location (g) == gimple_location (stmt);
317   else if (tree_int_cst_le (cur_align, align))
318     remove = (flag_sanitize_recover & SANITIZE_ALIGNMENT) == 0
319               || flag_sanitize_undefined_trap_on_error
320               || gimple_location (g) == gimple_location (stmt);
321
322   if (!remove && gimple_bb (g) == gimple_bb (stmt)
323       && tree_int_cst_compare (cur_align, align) == 0)
324     v.pop ();
325
326   if (!remove)
327     v.safe_push (stmt);
328   return remove;
329 }
330
331 /* Optimize away redundant UBSAN_VPTR calls.  The second argument
332    is the value loaded from the virtual table, so rely on FRE to find out
333    when we can actually optimize.  */
334
335 static bool
336 maybe_optimize_ubsan_vptr_ifn (struct sanopt_ctx *ctx, gimple *stmt)
337 {
338   gcc_assert (gimple_call_num_args (stmt) == 5);
339   sanopt_tree_triplet triplet;
340   triplet.t1 = gimple_call_arg (stmt, 0);
341   triplet.t2 = gimple_call_arg (stmt, 1);
342   triplet.t3 = gimple_call_arg (stmt, 3);
343
344   auto_vec<gimple *> &v = ctx->vptr_check_map.get_or_insert (triplet);
345   gimple *g = maybe_get_dominating_check (v);
346   if (!g)
347     {
348       /* For this PTR we don't have any UBSAN_VPTR stmts recorded, so there's
349          nothing to optimize yet.  */
350       v.safe_push (stmt);
351       return false;
352     }
353
354   return true;
355 }
356
357 /* Returns TRUE if ASan check of length LEN in block BB can be removed
358    if preceded by checks in V.  */
359
360 static bool
361 can_remove_asan_check (auto_vec<gimple *> &v, tree len, basic_block bb)
362 {
363   unsigned int i;
364   gimple *g;
365   gimple *to_pop = NULL;
366   bool remove = false;
367   basic_block last_bb = bb;
368   bool cleanup = false;
369
370   FOR_EACH_VEC_ELT_REVERSE (v, i, g)
371     {
372       basic_block gbb = gimple_bb (g);
373       sanopt_info *si = (sanopt_info *) gbb->aux;
374       if (gimple_uid (g) < si->freeing_call_events)
375         {
376           /* If there is a potentially freeing call after g in gbb, we should
377              remove it from the vector, can't use in optimization.  */
378           cleanup = true;
379           continue;
380         }
381
382       tree glen = gimple_call_arg (g, 2);
383       gcc_assert (TREE_CODE (glen) == INTEGER_CST);
384
385       /* If we've checked only smaller length than we want to check now,
386          we can't remove the current stmt.  If g is in the same basic block,
387          we want to remove it though, as the current stmt is better.  */
388       if (tree_int_cst_lt (glen, len))
389         {
390           if (gbb == bb)
391             {
392               to_pop = g;
393               cleanup = true;
394             }
395           continue;
396         }
397
398       while (last_bb != gbb)
399         {
400           /* Paths from last_bb to bb have been checked before.
401              gbb is necessarily a dominator of last_bb, but not necessarily
402              immediate dominator.  */
403           if (((sanopt_info *) last_bb->aux)->freeing_call_events)
404             break;
405
406           basic_block imm = get_immediate_dominator (CDI_DOMINATORS, last_bb);
407           gcc_assert (imm);
408           if (imm_dom_path_with_freeing_call (last_bb, imm))
409             break;
410
411           last_bb = imm;
412         }
413       if (last_bb == gbb)
414         remove = true;
415       break;
416     }
417
418   if (cleanup)
419     {
420       unsigned int j = 0, l = v.length ();
421       for (i = 0; i < l; i++)
422         if (v[i] != to_pop
423             && (gimple_uid (v[i])
424                 == ((sanopt_info *)
425                     gimple_bb (v[i])->aux)->freeing_call_events))
426           {
427             if (i != j)
428               v[j] = v[i];
429             j++;
430           }
431       v.truncate (j);
432     }
433
434   return remove;
435 }
436
437 /* Optimize away redundant ASAN_CHECK calls.  */
438
439 static bool
440 maybe_optimize_asan_check_ifn (struct sanopt_ctx *ctx, gimple *stmt)
441 {
442   gcc_assert (gimple_call_num_args (stmt) == 4);
443   tree ptr = gimple_call_arg (stmt, 1);
444   tree len = gimple_call_arg (stmt, 2);
445   basic_block bb = gimple_bb (stmt);
446   sanopt_info *info = (sanopt_info *) bb->aux;
447
448   if (TREE_CODE (len) != INTEGER_CST)
449     return false;
450   if (integer_zerop (len))
451     return false;
452
453   gimple_set_uid (stmt, info->freeing_call_events);
454
455   auto_vec<gimple *> *ptr_checks = &ctx->asan_check_map.get_or_insert (ptr);
456
457   tree base_addr = maybe_get_single_definition (ptr);
458   auto_vec<gimple *> *base_checks = NULL;
459   if (base_addr)
460     {
461       base_checks = &ctx->asan_check_map.get_or_insert (base_addr);
462       /* Original pointer might have been invalidated.  */
463       ptr_checks = ctx->asan_check_map.get (ptr);
464     }
465
466   gimple *g = maybe_get_dominating_check (*ptr_checks);
467   gimple *g2 = NULL;
468
469   if (base_checks)
470     /* Try with base address as well.  */
471     g2 = maybe_get_dominating_check (*base_checks);
472
473   if (g == NULL && g2 == NULL)
474     {
475       /* For this PTR we don't have any ASAN_CHECK stmts recorded, so there's
476          nothing to optimize yet.  */
477       ptr_checks->safe_push (stmt);
478       if (base_checks)
479         base_checks->safe_push (stmt);
480       return false;
481     }
482
483   bool remove = false;
484
485   if (ptr_checks)
486     remove = can_remove_asan_check (*ptr_checks, len, bb);
487
488   if (!remove && base_checks)
489     /* Try with base address as well.  */
490     remove = can_remove_asan_check (*base_checks, len, bb);
491
492   if (!remove)
493     {
494       ptr_checks->safe_push (stmt);
495       if (base_checks)
496         base_checks->safe_push (stmt);
497     }
498
499   return remove;
500 }
501
502 /* Try to optimize away redundant UBSAN_NULL and ASAN_CHECK calls.
503
504    We walk blocks in the CFG via a depth first search of the dominator
505    tree; we push unique UBSAN_NULL or ASAN_CHECK statements into a vector
506    in the NULL_CHECK_MAP or ASAN_CHECK_MAP hash maps as we enter the
507    blocks.  When leaving a block, we mark the block as visited; then
508    when checking the statements in the vector, we ignore statements that
509    are coming from already visited blocks, because these cannot dominate
510    anything anymore.  CTX is a sanopt context.  */
511
512 static void
513 sanopt_optimize_walker (basic_block bb, struct sanopt_ctx *ctx)
514 {
515   basic_block son;
516   gimple_stmt_iterator gsi;
517   sanopt_info *info = (sanopt_info *) bb->aux;
518   bool asan_check_optimize = (flag_sanitize & SANITIZE_ADDRESS) != 0;
519
520   for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
521     {
522       gimple *stmt = gsi_stmt (gsi);
523       bool remove = false;
524
525       if (!is_gimple_call (stmt))
526         {
527           /* Handle asm volatile or asm with "memory" clobber
528              the same as potentionally freeing call.  */
529           gasm *asm_stmt = dyn_cast <gasm *> (stmt);
530           if (asm_stmt
531               && asan_check_optimize
532               && (gimple_asm_clobbers_memory_p (asm_stmt)
533                   || gimple_asm_volatile_p (asm_stmt)))
534             info->freeing_call_events++;
535           gsi_next (&gsi);
536           continue;
537         }
538
539       if (asan_check_optimize && !nonfreeing_call_p (stmt))
540         info->freeing_call_events++;
541
542       if (gimple_call_internal_p (stmt))
543         switch (gimple_call_internal_fn (stmt))
544           {
545           case IFN_UBSAN_NULL:
546             remove = maybe_optimize_ubsan_null_ifn (ctx, stmt);
547             break;
548           case IFN_UBSAN_VPTR:
549             remove = maybe_optimize_ubsan_vptr_ifn (ctx, stmt);
550             break;
551           case IFN_ASAN_CHECK:
552             if (asan_check_optimize)
553               remove = maybe_optimize_asan_check_ifn (ctx, stmt);
554             if (!remove)
555               ctx->asan_num_accesses++;
556             break;
557           default:
558             break;
559           }
560
561       if (remove)
562         {
563           /* Drop this check.  */
564           if (dump_file && (dump_flags & TDF_DETAILS))
565             {
566               fprintf (dump_file, "Optimizing out\n  ");
567               print_gimple_stmt (dump_file, stmt, 0, dump_flags);
568               fprintf (dump_file, "\n");
569             }
570           unlink_stmt_vdef (stmt);
571           gsi_remove (&gsi, true);
572         }
573       else
574         gsi_next (&gsi);
575     }
576
577   if (asan_check_optimize)
578     {
579       info->has_freeing_call_p = info->freeing_call_events != 0;
580       info->has_freeing_call_computed_p = true;
581     }
582
583   for (son = first_dom_son (CDI_DOMINATORS, bb);
584        son;
585        son = next_dom_son (CDI_DOMINATORS, son))
586     sanopt_optimize_walker (son, ctx);
587
588   /* We're leaving this BB, so mark it to that effect.  */
589   info->visited_p = true;
590 }
591
592 /* Try to remove redundant sanitizer checks in function FUN.  */
593
594 static int
595 sanopt_optimize (function *fun)
596 {
597   struct sanopt_ctx ctx;
598   ctx.asan_num_accesses = 0;
599
600   /* Set up block info for each basic block.  */
601   alloc_aux_for_blocks (sizeof (sanopt_info));
602
603   /* We're going to do a dominator walk, so ensure that we have
604      dominance information.  */
605   calculate_dominance_info (CDI_DOMINATORS);
606
607   /* Recursively walk the dominator tree optimizing away
608      redundant checks.  */
609   sanopt_optimize_walker (ENTRY_BLOCK_PTR_FOR_FN (fun), &ctx);
610
611   free_aux_for_blocks ();
612
613   return ctx.asan_num_accesses;
614 }
615
616 /* Perform optimization of sanitize functions.  */
617
618 namespace {
619
620 const pass_data pass_data_sanopt =
621 {
622   GIMPLE_PASS, /* type */
623   "sanopt", /* name */
624   OPTGROUP_NONE, /* optinfo_flags */
625   TV_NONE, /* tv_id */
626   ( PROP_ssa | PROP_cfg | PROP_gimple_leh ), /* properties_required */
627   0, /* properties_provided */
628   0, /* properties_destroyed */
629   0, /* todo_flags_start */
630   TODO_update_ssa, /* todo_flags_finish */
631 };
632
633 class pass_sanopt : public gimple_opt_pass
634 {
635 public:
636   pass_sanopt (gcc::context *ctxt)
637     : gimple_opt_pass (pass_data_sanopt, ctxt)
638   {}
639
640   /* opt_pass methods: */
641   virtual bool gate (function *) { return flag_sanitize; }
642   virtual unsigned int execute (function *);
643
644 }; // class pass_sanopt
645
646 unsigned int
647 pass_sanopt::execute (function *fun)
648 {
649   basic_block bb;
650   int asan_num_accesses = 0;
651
652   /* Try to remove redundant checks.  */
653   if (optimize
654       && (flag_sanitize
655           & (SANITIZE_NULL | SANITIZE_ALIGNMENT
656              | SANITIZE_ADDRESS | SANITIZE_VPTR)))
657     asan_num_accesses = sanopt_optimize (fun);
658   else if (flag_sanitize & SANITIZE_ADDRESS)
659     {
660       gimple_stmt_iterator gsi;
661       FOR_EACH_BB_FN (bb, fun)
662         for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
663           {
664             gimple *stmt = gsi_stmt (gsi);
665             if (is_gimple_call (stmt) && gimple_call_internal_p (stmt)
666                 && gimple_call_internal_fn (stmt) == IFN_ASAN_CHECK)
667               ++asan_num_accesses;
668           }
669     }
670
671   bool use_calls = ASAN_INSTRUMENTATION_WITH_CALL_THRESHOLD < INT_MAX
672     && asan_num_accesses >= ASAN_INSTRUMENTATION_WITH_CALL_THRESHOLD;
673
674   FOR_EACH_BB_FN (bb, fun)
675     {
676       gimple_stmt_iterator gsi;
677       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); )
678         {
679           gimple *stmt = gsi_stmt (gsi);
680           bool no_next = false;
681
682           if (!is_gimple_call (stmt))
683             {
684               gsi_next (&gsi);
685               continue;
686             }
687
688           if (gimple_call_internal_p (stmt))
689             {
690               enum internal_fn ifn = gimple_call_internal_fn (stmt);
691               switch (ifn)
692                 {
693                 case IFN_UBSAN_NULL:
694                   no_next = ubsan_expand_null_ifn (&gsi);
695                   break;
696                 case IFN_UBSAN_BOUNDS:
697                   no_next = ubsan_expand_bounds_ifn (&gsi);
698                   break;
699                 case IFN_UBSAN_OBJECT_SIZE:
700                   no_next = ubsan_expand_objsize_ifn (&gsi);
701                   break;
702                 case IFN_UBSAN_VPTR:
703                   no_next = ubsan_expand_vptr_ifn (&gsi);
704                   break;
705                 case IFN_ASAN_CHECK:
706                   no_next = asan_expand_check_ifn (&gsi, use_calls);
707                   break;
708                 case IFN_ASAN_MARK:
709                   no_next = asan_expand_mark_ifn (&gsi);
710                   break;
711                 case IFN_ESAN_RECORD_ACCESS:
712                   no_next = esan_expand_record_access_ifn (&gsi);
713                 default:
714                   break;
715                 }
716             }
717           else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
718             {
719               tree callee = gimple_call_fndecl (stmt);
720               switch (DECL_FUNCTION_CODE (callee))
721                 {
722                 case BUILT_IN_UNREACHABLE:
723                   if (flag_sanitize & SANITIZE_UNREACHABLE
724                       && !lookup_attribute ("no_sanitize_undefined",
725                                             DECL_ATTRIBUTES (fun->decl)))
726                     no_next = ubsan_instrument_unreachable (&gsi);
727                   break;
728                 default:
729                   break;
730                 }
731             }
732
733           if (dump_file && (dump_flags & TDF_DETAILS))
734             {
735               fprintf (dump_file, "Expanded\n  ");
736               print_gimple_stmt (dump_file, stmt, 0, dump_flags);
737               fprintf (dump_file, "\n");
738             }
739
740           if (!no_next)
741             gsi_next (&gsi);
742         }
743     }
744   return 0;
745 }
746
747 } // anon namespace
748
749 gimple_opt_pass *
750 make_pass_sanopt (gcc::context *ctxt)
751 {
752   return new pass_sanopt (ctxt);
753 }