Fix ICE with stack checking emulation at -O2
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 1 Oct 2021 08:56:45 +0000 (10:56 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Fri, 1 Oct 2021 08:56:45 +0000 (10:56 +0200)
On bare-metal platforms, the Ada compiler emulates stack checking (it is
required by the language and tested by ACATS) in the runtime via the
stack_check_libfunc hook of the RTL middle-end.  Calls to the function
are generated as libcalls but they now require a proper function type
at -O2 or above.

gcc/
* explow.c: Include langhooks.h.
(set_stack_check_libfunc): Build a proper function type.

gcc/explow.c

index b6da277..a35423f 100644 (file)
@@ -34,6 +34,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "recog.h"
 #include "diagnostic-core.h"
 #include "stor-layout.h"
+#include "langhooks.h"
 #include "except.h"
 #include "dojump.h"
 #include "explow.h"
@@ -1641,8 +1642,14 @@ set_stack_check_libfunc (const char *libfunc_name)
 {
   gcc_assert (stack_check_libfunc == NULL_RTX);
   stack_check_libfunc = gen_rtx_SYMBOL_REF (Pmode, libfunc_name);
+  tree ptype
+    = Pmode == ptr_mode
+      ? ptr_type_node
+      : lang_hooks.types.type_for_mode (Pmode, 1);
+  tree ftype
+    = build_function_type_list (void_type_node, ptype, NULL_TREE);
   tree decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
-                         get_identifier (libfunc_name), void_type_node);
+                         get_identifier (libfunc_name), ftype);
   DECL_EXTERNAL (decl) = 1;
   SET_SYMBOL_REF_DECL (stack_check_libfunc, decl);
 }