]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Defuse 'RESULT_DECL' check in 'pass_nrv' (for offloading compilation) [PR119835]
authorThomas Schwinge <tschwinge@baylibre.com>
Wed, 28 May 2025 16:40:31 +0000 (18:40 +0200)
committerThomas Schwinge <tschwinge@baylibre.com>
Fri, 30 May 2025 12:47:40 +0000 (14:47 +0200)
... 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 <rguenther@suse.de>
gcc/tree-nrv.cc
libgomp/testsuite/libgomp.c-c++-common/target-abi-struct-1-O0.c
libgomp/testsuite/libgomp.c-c++-common/target-abi-struct-1.c [new file with mode: 0644]
libgomp/testsuite/libgomp.oacc-c-c++-common/abi-struct-1.c

index 180ce39de4c57433b25ee3ce4891d02b12e24599..3be97afb319e6bf81c06f30f8699fc0c037d8f42 100644 (file)
@@ -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)
index 35ec75d648d31864dd5946041691a0b7a7be9913..9bf949a1f066da8e5399ef6545ddcad414999600 100644 (file)
@@ -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 (file)
index 0000000..d9268af
--- /dev/null
@@ -0,0 +1 @@
+#include "../libgomp.oacc-c-c++-common/abi-struct-1.c"
index 80786555fe21d71fd24d02062c8513d5c15a07ec..4b541711f36385e4628c80d0c3344076c80595fb 100644 (file)
@@ -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;