nvptx.c (nvptx_output_call_insn): Emit trap after no return call.
authorNathan Sidwell <nathan@acm.org>
Mon, 7 Dec 2015 16:08:42 +0000 (16:08 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Mon, 7 Dec 2015 16:08:42 +0000 (16:08 +0000)
gcc/
* config/nvptx/nvptx.c (nvptx_output_call_insn): Emit trap after no
return call.

gcc/testsuite/
* gcc.target/nvptx/abort.c: New.

From-SVN: r231368

gcc/ChangeLog
gcc/config/nvptx/nvptx.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/nvptx/abort.c [new file with mode: 0644]

index 80e8481..2b92119 100644 (file)
@@ -1,3 +1,8 @@
+2015-12-07  Nathan Sidwell  <nathan@acm.org>
+
+       * config/nvptx/nvptx.c (nvptx_output_call_insn): Emit trap after no
+       return call.
+
 2015-12-07  David Malcolm  <dmalcolm@redhat.com>
 
        * pretty-print.c (text_info::set_range): Rename to...
index 2dec846..6ce8d4b 100644 (file)
@@ -1890,6 +1890,13 @@ nvptx_output_call_insn (rtx_insn *insn, rtx result, rtx callee)
     }
   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 93f3af2..2a8fce8 100644 (file)
@@ -1,3 +1,7 @@
+2015-12-07  Nathan Sidwell  <nathan@acm.org>
+
+       * gcc.target/nvptx/abort.c: New.
+
 2015-12-07  David Malcolm  <dmalcolm@redhat.com>
 
        * gcc.dg/diagnostic-ranges-1.c: New test file.
diff --git a/gcc/testsuite/gcc.target/nvptx/abort.c b/gcc/testsuite/gcc.target/nvptx/abort.c
new file mode 100644 (file)
index 0000000..d322068
--- /dev/null
@@ -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;" } } */