PR82045: Avoid passing machine modes through "..."
[official-gcc.git] / gcc / sancov.c
blobb19de8bbbc5fc99416b4440c98dca0e9a3dfc8ea
1 /* Code coverage instrumentation for fuzzing.
2 Copyright (C) 2015-2017 Free Software Foundation, Inc.
3 Contributed by Dmitry Vyukov <dvyukov@google.com>
5 This file is part of GCC.
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.
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.
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/>. */
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 "basic-block.h"
28 #include "options.h"
29 #include "flags.h"
30 #include "stmt.h"
31 #include "gimple-iterator.h"
32 #include "tree-cfg.h"
33 #include "tree-pass.h"
34 #include "tree-iterator.h"
35 #include "stringpool.h"
36 #include "attribs.h"
37 #include "asan.h"
39 namespace {
41 unsigned
42 sancov_pass (function *fun)
44 initialize_sanitizer_builtins ();
46 /* Insert callback into beginning of every BB. */
47 tree fndecl = builtin_decl_implicit (BUILT_IN_SANITIZER_COV_TRACE_PC);
48 basic_block bb;
49 FOR_EACH_BB_FN (bb, fun)
51 gimple_stmt_iterator gsi = gsi_start_nondebug_after_labels_bb (bb);
52 if (gsi_end_p (gsi))
53 continue;
54 gimple *stmt = gsi_stmt (gsi);
55 gimple *gcall = gimple_build_call (fndecl, 0);
56 gimple_set_location (gcall, gimple_location (stmt));
57 gsi_insert_before (&gsi, gcall, GSI_SAME_STMT);
59 return 0;
62 template <bool O0> class pass_sancov : public gimple_opt_pass
64 public:
65 pass_sancov (gcc::context *ctxt) : gimple_opt_pass (data, ctxt) {}
67 static const pass_data data;
68 opt_pass *
69 clone ()
71 return new pass_sancov<O0> (m_ctxt);
73 virtual bool
74 gate (function *)
76 return flag_sanitize_coverage && (!O0 || !optimize);
78 virtual unsigned int
79 execute (function *fun)
81 return sancov_pass (fun);
83 }; // class pass_sancov
85 template <bool O0>
86 const pass_data pass_sancov<O0>::data = {
87 GIMPLE_PASS, /* type */
88 O0 ? "sancov_O0" : "sancov", /* name */
89 OPTGROUP_NONE, /* optinfo_flags */
90 TV_NONE, /* tv_id */
91 (PROP_cfg), /* properties_required */
92 0, /* properties_provided */
93 0, /* properties_destroyed */
94 0, /* todo_flags_start */
95 TODO_update_ssa, /* todo_flags_finish */
98 } // anon namespace
100 gimple_opt_pass *
101 make_pass_sancov (gcc::context *ctxt)
103 return new pass_sancov<false> (ctxt);
106 gimple_opt_pass *
107 make_pass_sancov_O0 (gcc::context *ctxt)
109 return new pass_sancov<true> (ctxt);