Fortran: do not generate conflicting results under -ff2c [PR104313]
authorSteve Kargl <kargl@gcc.gnu.org>
Fri, 15 Jul 2022 20:07:15 +0000 (22:07 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Fri, 15 Jul 2022 20:08:24 +0000 (22:08 +0200)
gcc/fortran/ChangeLog:

PR fortran/104313
* trans-decl.cc (gfc_generate_return): Do not generate conflicting
fake results for functions with no result variable under -ff2c.

gcc/testsuite/ChangeLog:

PR fortran/104313
* gfortran.dg/pr104313.f: New test.

gcc/fortran/trans-decl.cc
gcc/testsuite/gfortran.dg/pr104313.f [new file with mode: 0644]

index 6493cc2..908a4c6 100644 (file)
@@ -6474,7 +6474,7 @@ gfc_generate_return (void)
             NULL_TREE, and a 'return' is generated without a variable.
             The following generates a 'return __result_XXX' where XXX is
             the function name.  */
-         if (sym == sym->result && sym->attr.function)
+         if (sym == sym->result && sym->attr.function && !flag_f2c)
            {
              result = gfc_get_fake_result_decl (sym, 0);
              result = fold_build2_loc (input_location, MODIFY_EXPR,
diff --git a/gcc/testsuite/gfortran.dg/pr104313.f b/gcc/testsuite/gfortran.dg/pr104313.f
new file mode 100644 (file)
index 0000000..89c8947
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! { dg-additional-options "-ff2c -fdump-tree-original" }
+!
+! PR fortran/104313 - ICE verify_gimple failed with -ff2c
+! Contributed by G.Steinmetz
+
+      function f(a)
+      return
+      end
+
+! { dg-final { scan-tree-dump-times "return" 1 "original" } }