diff mbox series

[nvptx,committed] Add exit after call to noreturn function

Message ID 3d7059d5-9d8f-09ac-5d08-a3e0da2fb8f5@mentor.com
State New
Headers show
Series [nvptx,committed] Add exit after call to noreturn function | expand

Commit Message

Tom de Vries Sept. 25, 2017, 10:55 a.m. UTC
Hi,

atm for the nvptx target we're emitting a trap after a noreturn function 
to indicate the control flow barrier to ptxas:
...
  		call exit, (%out_arg1);
  		trap; // (noreturn)
...

However, after reporting a bug to nvidia ( 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81069#c3 ) we were informed 
that the trap insn (documented as 'Abort execution and generate an 
interrupt to the host CPU') in fact is not considered a control flow 
barrier by ptxas, given that a trap handler may return. The fix that was 
recommended was to put an exit after the trap. This patch implements that.

Committed.

Thanks,
- Tom
diff mbox series

Patch

[nvptx] Add exit after call to noreturn function

2017-09-25  Tom de Vries  <tom@codesourcery.com>

	PR target/80035
	PR target/81069
	* config/nvptx/nvptx.c (nvptx_output_call_insn): Add exit after call to
	noreturn function.

---
 gcc/config/nvptx/nvptx.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index 6cf9a66..634f660 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -2304,11 +2304,14 @@  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");
+    {
+      /* 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 and exit, which it does grok.  */
+      fprintf (asm_out_file, "\t\ttrap; // (noreturn)\n");
+      fprintf (asm_out_file, "\t\texit; // (noreturn)\n");
+    }
 
   if (result)
     {