{
return new pass_pru_tiabi_check (ctxt);
}
+\f
+namespace {
+
+/* Scan the tree to ensure that the compiled code by GCC
+ conforms to the non-standard minimal runtime. */
+const pass_data pass_data_pru_minrt_check =
+{
+ GIMPLE_PASS, /* type */
+ "*pru_minrt_check", /* name */
+ OPTGROUP_NONE, /* optinfo_flags */
+ TV_NONE, /* tv_id */
+ PROP_gimple_any, /* properties_required */
+ 0, /* properties_provided */
+ 0, /* properties_destroyed */
+ 0, /* todo_flags_start */
+ 0, /* todo_flags_finish */
+};
+
+/* Implementation class for the minrt compliance-check pass. */
+class pass_pru_minrt_check : public gimple_opt_pass
+{
+public:
+ pass_pru_minrt_check (gcc::context *ctxt)
+ : gimple_opt_pass (pass_data_pru_minrt_check, ctxt)
+ {}
+
+ /* opt_pass methods: */
+ virtual unsigned int execute (function *);
+
+ virtual bool gate (function *)
+ {
+ return TARGET_MINRT;
+ }
+
+}; // class pass_pru_minrt_check
+\f
+/* Pass implementation. */
+unsigned
+pass_pru_minrt_check::execute (function *fun)
+{
+ const_tree fntype = TREE_TYPE (fun->decl);
+
+ if (id_equal (DECL_NAME (fun->decl), "main"))
+ {
+ /* Argument list always ends with VOID_TYPE, so subtract one
+ to get the number of function arguments. */
+ const unsigned num_args = list_length (TYPE_ARG_TYPES (fntype)) - 1;
+
+ if (num_args != 0)
+ error_at (DECL_SOURCE_LOCATION (fun->decl), "function %<main%> "
+ "must have no arguments when using the "
+ "%<-minrt%> option");
+
+ /* The required CFG analysis to detect when a functions would never
+ return is available only with -O1 and higher. */
+ if (optimize >= 1 && !TREE_THIS_VOLATILE (fun->decl))
+ error_at (DECL_SOURCE_LOCATION (fun->decl), "function %<main%> "
+ "must never return when using the "
+ "%<-minrt%> option");
+ }
+ return 0;
+}
+
+} // anon namespace
+
+gimple_opt_pass *
+make_pru_minrt_check (gcc::context *ctxt)
+{
+ return new pass_pru_minrt_check (ctxt);
+}
If GCC cannot output a conforming code, then an error is raised. */
INSERT_PASS_AFTER (pass_warn_unused_result, 1, pru_tiabi_check);
+
+/* If -minrt option is used, then this pass would validate
+ that the compiled code by GCC is compatible with the minimal
+ C runtime. */
+INSERT_PASS_AFTER (pass_warn_function_noreturn, 1, pru_minrt_check);
--- /dev/null
+# Copyright (C) 2024 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Exit immediately if this isn't a pru target.
+if ![istarget pru*-*-*] then {
+ return
+}
+
+# Load support procs.
+load_lib g++-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.cc]] "" ""
+
+# All done.
+dg-finish