1 /* Integration of the analyzer with GCC's pass manager. 2 Copyright (C) 2019-2020 Free Software Foundation, Inc. 3 Contributed by David Malcolm <dmalcolm@redhat.com>. 4 5 This file is part of GCC. 6 7 GCC is free software; you can redistribute it and/or modify it 8 under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3, or (at your option) 10 any later version. 11 12 GCC is distributed in the hope that it will be useful, but 13 WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 General Public License 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 "context.h" 25 #include "tree-pass.h" 26 #include "diagnostic.h" 27 #include "options.h" 28 #include "analyzer/engine.h" 29 30 namespace { 31 32 /* Data for the analyzer pass. */ 33 34 const pass_data pass_data_analyzer = 35 { 36 IPA_PASS, /* type */ 37 "analyzer", /* name */ 38 OPTGROUP_NONE, /* optinfo_flags */ 39 TV_ANALYZER, /* tv_id */ 40 PROP_ssa, /* properties_required */ 41 0, /* properties_provided */ 42 0, /* properties_destroyed */ 43 0, /* todo_flags_start */ 44 0, /* todo_flags_finish */ 45 }; 46 47 /* The analyzer pass. */ 48 49 class pass_analyzer : public ipa_opt_pass_d 50 { 51 public: 52 pass_analyzer(gcc::context *ctxt) 53 : ipa_opt_pass_d (pass_data_analyzer, ctxt, 54 NULL, /* generate_summary */ 55 NULL, /* write_summary */ 56 NULL, /* read_summary */ 57 NULL, /* write_optimization_summary */ 58 NULL, /* read_optimization_summary */ 59 NULL, /* stmt_fixup */ 60 0, /* function_transform_todo_flags_start */ 61 NULL, /* function_transform */ 62 NULL) /* variable_transform */ 63 {} 64 65 /* opt_pass methods: */ 66 bool gate (function *) FINAL OVERRIDE; 67 unsigned int execute (function *) FINAL OVERRIDE; 68 }; // class pass_analyzer 69 70 /* Only run the analyzer if -fanalyzer. */ 71 72 bool 73 pass_analyzer::gate (function *) 74 { 75 return flag_analyzer != 0; 76 } 77 78 /* Entrypoint for the analyzer pass. */ 79 80 unsigned int 81 pass_analyzer::execute (function *) 82 { 83 #if ENABLE_ANALYZER 84 ana::run_checkers (); 85 #else 86 sorry ("%qs was not enabled in this build of GCC" 87 " (missing configure-time option %qs)", 88 "-fanalyzer", "--enable-analyzer"); 89 #endif 90 91 return 0; 92 } 93 94 } // anon namespace 95 96 /* Make an instance of the analyzer pass. */ 97 98 ipa_opt_pass_d * 99 make_pass_analyzer (gcc::context *ctxt) 100 { 101 return new pass_analyzer (ctxt); 102 } 103