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
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"
35 #include "stringpool.h"
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
);
49 FOR_EACH_BB_FN (bb
, fun
)
51 gimple_stmt_iterator gsi
= gsi_start_nondebug_after_labels_bb (bb
);
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
);
62 template <bool O0
> class pass_sancov
: public gimple_opt_pass
65 pass_sancov (gcc::context
*ctxt
) : gimple_opt_pass (data
, ctxt
) {}
67 static const pass_data data
;
71 return new pass_sancov
<O0
> (m_ctxt
);
76 return flag_sanitize_coverage
&& (!O0
|| !optimize
);
79 execute (function
*fun
)
81 return sancov_pass (fun
);
83 }; // class pass_sancov
86 const pass_data pass_sancov
<O0
>::data
= {
87 GIMPLE_PASS
, /* type */
88 O0
? "sancov_O0" : "sancov", /* name */
89 OPTGROUP_NONE
, /* optinfo_flags */
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 */
101 make_pass_sancov (gcc::context
*ctxt
)
103 return new pass_sancov
<false> (ctxt
);
107 make_pass_sancov_O0 (gcc::context
*ctxt
)
109 return new pass_sancov
<true> (ctxt
);