1 /* Code coverage instrumentation for fuzzing.
2 Copyright (C) 2015-2016 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
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
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/>. */
23 #include "coretypes.h"
27 #include "basic-block.h"
31 #include "gimple-iterator.h"
33 #include "tree-pass.h"
34 #include "tree-iterator.h"
40 sancov_pass (function *fun)
42 initialize_sanitizer_builtins ();
44 /* Insert callback into beginning of every BB. */
45 tree fndecl = builtin_decl_implicit (BUILT_IN_SANITIZER_COV_TRACE_PC);
47 FOR_EACH_BB_FN (bb, fun)
49 gimple_stmt_iterator gsi = gsi_after_labels (bb);
52 gimple *stmt = gsi_stmt (gsi);
53 gimple *gcall = gimple_build_call (fndecl, 0);
54 gimple_set_location (gcall, gimple_location (stmt));
55 gsi_insert_before (&gsi, gcall, GSI_SAME_STMT);
60 template <bool O0> class pass_sancov : public gimple_opt_pass
63 pass_sancov (gcc::context *ctxt) : gimple_opt_pass (data, ctxt) {}
65 static const pass_data data;
69 return new pass_sancov<O0> (m_ctxt);
74 return flag_sanitize_coverage && (!O0 || !optimize);
77 execute (function *fun)
79 return sancov_pass (fun);
81 }; // class pass_sancov
84 const pass_data pass_sancov<O0>::data = {
85 GIMPLE_PASS, /* type */
86 O0 ? "sancov_O0" : "sancov", /* name */
87 OPTGROUP_NONE, /* optinfo_flags */
89 (PROP_cfg), /* properties_required */
90 0, /* properties_provided */
91 0, /* properties_destroyed */
92 0, /* todo_flags_start */
93 TODO_update_ssa, /* todo_flags_finish */
99 make_pass_sancov (gcc::context *ctxt)
101 return new pass_sancov<false> (ctxt);
105 make_pass_sancov_O0 (gcc::context *ctxt)
107 return new pass_sancov<true> (ctxt);