https://gcc.gnu.org/g:ad212f7025627e49330094a408845bf09fc367a5
commit ad212f7025627e49330094a408845bf09fc367a5 Author: Thomas Schwinge <tschwi...@baylibre.com> Date: Wed May 28 18:40:31 2025 +0200 Defuse 'RESULT_DECL' check in 'pass_nrv' (for offloading compilation) [PR119835] ... to avoid running into ICEs per PR119835, until that's resolved properly. PR middle-end/119835 gcc/ * tree-nrv.cc (pass_nrv::execute): Defuse 'RESULT_DECL' check. libgomp/ * testsuite/libgomp.oacc-c-c++-common/abi-struct-1.c: '#pragma GCC optimize "-fno-inline"'. * testsuite/libgomp.c-c++-common/target-abi-struct-1.c: New. * testsuite/libgomp.c-c++-common/target-abi-struct-1-O0.c: Adjust. Co-authored-by: Richard Biener <rguent...@suse.de> (cherry picked from commit 543f7e1d59f0b6628e0de6610ad5e1cf7150090b) Diff: --- gcc/tree-nrv.cc | 19 ++++++++++++------- .../libgomp.c-c++-common/target-abi-struct-1-O0.c | 2 +- .../libgomp.c-c++-common/target-abi-struct-1.c | 1 + .../libgomp.oacc-c-c++-common/abi-struct-1.c | 6 +++++- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/gcc/tree-nrv.cc b/gcc/tree-nrv.cc index 180ce39de4c5..3be97afb319e 100644 --- a/gcc/tree-nrv.cc +++ b/gcc/tree-nrv.cc @@ -167,16 +167,21 @@ pass_nrv::execute (function *fun) for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { gimple *stmt = gsi_stmt (gsi); - tree ret_val; if (greturn *return_stmt = dyn_cast <greturn *> (stmt)) { - /* In a function with an aggregate return value, the - gimplifier has changed all non-empty RETURN_EXPRs to - return the RESULT_DECL. */ - ret_val = gimple_return_retval (return_stmt); - if (ret_val) - gcc_assert (ret_val == result); + /* We cannot perform NRV optimizations in a function with an + aggregate return value if there is a return that does not + return RESULT_DECL. We used to assert this scenario doesn't + happen: the gimplifier has changed all non-empty RETURN_EXPRs + to return the RESULT_DECL. However, per PR119835 we may run + into this scenario for offloading compilation, and therefore + gracefully bail out. */ + if (tree ret_val = gimple_return_retval (return_stmt)) + { + if (ret_val != result) + return 0; + } } else if (gimple_has_lhs (stmt) && gimple_get_lhs (stmt) == result) diff --git a/libgomp/testsuite/libgomp.c-c++-common/target-abi-struct-1-O0.c b/libgomp/testsuite/libgomp.c-c++-common/target-abi-struct-1-O0.c index 35ec75d648d3..9bf949a1f066 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/target-abi-struct-1-O0.c +++ b/libgomp/testsuite/libgomp.c-c++-common/target-abi-struct-1-O0.c @@ -1,3 +1,3 @@ /* { dg-additional-options -O0 } */ -#include "../libgomp.oacc-c-c++-common/abi-struct-1.c" +#include "target-abi-struct-1.c" diff --git a/libgomp/testsuite/libgomp.c-c++-common/target-abi-struct-1.c b/libgomp/testsuite/libgomp.c-c++-common/target-abi-struct-1.c new file mode 100644 index 000000000000..d9268af55cfe --- /dev/null +++ b/libgomp/testsuite/libgomp.c-c++-common/target-abi-struct-1.c @@ -0,0 +1 @@ +#include "../libgomp.oacc-c-c++-common/abi-struct-1.c" diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/abi-struct-1.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/abi-struct-1.c index 80786555fe21..4b541711f363 100644 --- a/libgomp/testsuite/libgomp.oacc-c-c++-common/abi-struct-1.c +++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/abi-struct-1.c @@ -1,6 +1,10 @@ /* Inspired by 'gcc.target/nvptx/abi-struct-arg.c', 'gcc.target/nvptx/abi-struct-ret.c'. */ -/* See also '../libgomp.c-c++-common/target-abi-struct-1-O0.c'. */ +/* See also '../libgomp.c-c++-common/target-abi-struct-1.c'. */ + +/* To exercise PR119835 (if optimizations enabled): disable inlining, so that + GIMPLE passes still see the functions that return aggregate types. */ +#pragma GCC optimize "-fno-inline" typedef struct {} empty; /* See 'gcc/doc/extend.texi', "Empty Structures". */ typedef struct {char a;} schar;