calls to no return fns can cause problems with the PTX JIT. It doesn't
understand their no-return nature and can erroneously think there are unexitable
loops (depending on the precise placement of bbs). It can get so upset it
segfaults.
gcc.dg/pr68671.c started causing this last week, with what looked like
incomplete jump threading.
This patch changes call emission to look for a noreturn note and emit a trap
insn after the call. The JIT no longer explodes.
nathan
2015-12-07 Nathan Sidwell <[email protected]>
gcc/
* config/nvptx/nvptx.c (nvptx_output_call_insn): Emit trap after no
return call.
gcc/testsuite/
* gcc.target/nvptx/abort.c: New.
Index: config/nvptx/nvptx.c
===================================================================
--- config/nvptx/nvptx.c (revision 231362)
+++ config/nvptx/nvptx.c (working copy)
@@ -1890,6 +1890,13 @@ nvptx_output_call_insn (rtx_insn *insn,
}
fprintf (asm_out_file, ";\n");
+ if (find_reg_note (insn, REG_NORETURN, NULL))
+ /* No return functions confuse the PTX JIT, as it doesn't realize
+ the flow control barrier they imply. It can seg fault if it
+ encounters what looks like an unexitable loop. Emit a trailing
+ trap, which it does grok. */
+ fprintf (asm_out_file, "\t\ttrap; // (noreturn)\n");
+
return result != NULL_RTX ? "\tld.param%t0\t%0, [%%retval_in];\n\t}" : "}";
}
Index: testsuite/gcc.target/nvptx/abort.c
===================================================================
--- testsuite/gcc.target/nvptx/abort.c (revision 0)
+++ testsuite/gcc.target/nvptx/abort.c (working copy)
@@ -0,0 +1,13 @@
+/* { dg-do compile} */
+/* Annotate no return functions with a trailing 'trap'. */
+
+extern void abort ();
+
+int main (int argc, char **argv)
+{
+ if (argc > 2)
+ abort ();
+ return 0;
+}
+
+/* { dg-final { scan-assembler "call abort;\[\r\n\t \]+trap;" } } */