From 51baf85ab604958aa93d7f9c18c335bf080aaf70 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 7 Dec 2015 16:08:42 +0000 Subject: [PATCH] nvptx.c (nvptx_output_call_insn): Emit trap after no return call. 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 | 5 +++++ gcc/config/nvptx/nvptx.c | 7 +++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.target/nvptx/abort.c | 13 +++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 gcc/testsuite/gcc.target/nvptx/abort.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 80e848123c9..2b9211992ff 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-12-07 Nathan Sidwell + + * config/nvptx/nvptx.c (nvptx_output_call_insn): Emit trap after no + return call. + 2015-12-07 David Malcolm * pretty-print.c (text_info::set_range): Rename to... diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c index 2dec8467437..6ce8d4b37d5 100644 --- a/gcc/config/nvptx/nvptx.c +++ b/gcc/config/nvptx/nvptx.c @@ -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}" : "}"; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 93f3af2a201..2a8fce8903b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-12-07 Nathan Sidwell + + * gcc.target/nvptx/abort.c: New. + 2015-12-07 David Malcolm * 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 index 00000000000..d3220687400 --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/abort.c @@ -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;" } } */ -- 2.30.2