re PR fortran/91359 (logical function X returns .TRUE. - Warning: spaghetti code)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Tue, 6 Aug 2019 21:32:09 +0000 (21:32 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Tue, 6 Aug 2019 21:32:09 +0000 (21:32 +0000)
2019-08-06  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/91359
* trans-decl.c (gfc_generate_return): Ensure something is returned
from a function.

2019-08-06  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/91359
* gfortran.dg/pr91359_1.f: New test.
* gfortran.dg/pr91359_2.f: Ditto.

From-SVN: r274149

gcc/fortran/ChangeLog
gcc/fortran/trans-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr91359_1.f [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr91359_2.f [new file with mode: 0644]

index b88437aa96d0980c3efc040f55b663d800581c81..1a2129d0a25e2d499197412812c0aefb1bafa2ba 100644 (file)
@@ -1,3 +1,9 @@
+2019-08-06  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/91359
+       * trans-decl.c (gfc_generate_return): Ensure something is returned
+       from a function.
+
 2019-08-06  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/42546
index 96f0e1e56d2f55b69829c9ffd64b43adfc5fbdff..86c3d3a97964485f9a06a2ed65f0df3448bcbb23 100644 (file)
@@ -6449,6 +6449,20 @@ gfc_generate_return (void)
                                    TREE_TYPE (result), DECL_RESULT (fndecl),
                                    result);
        }
+      else
+       {
+         /* If the function does not have a result variable, result is
+            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)
+           {
+             result = gfc_get_fake_result_decl (sym, 0);
+             result = fold_build2_loc (input_location, MODIFY_EXPR,
+                                       TREE_TYPE (result),
+                                       DECL_RESULT (fndecl), result);
+           }
+       }
     }
 
   return build1_v (RETURN_EXPR, result);
index af5349ab252d15141aff820cec341ec308236c5b..cb8040c00fd1547c832e8fe8916c4652dcfdeb6e 100644 (file)
@@ -1,3 +1,9 @@
+2019-08-06  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/91359
+       * gfortran.dg/pr91359_1.f: New test.
+       * gfortran.dg/pr91359_2.f: Ditto.
+
 2019-08-06  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/42546
diff --git a/gcc/testsuite/gfortran.dg/pr91359_1.f b/gcc/testsuite/gfortran.dg/pr91359_1.f
new file mode 100644 (file)
index 0000000..2b8a35a
--- /dev/null
@@ -0,0 +1,16 @@
+! { dg do run }
+! PR fortran/91359
+! Orginal code contributed by Brian T. Carcich <briantcarcich at gmail dot com>
+!
+      logical function zero() result(a)
+         goto 2
+1        return
+2        a = .false.
+         if (.not.a) goto 1
+         return
+      end
+
+      program test_zero
+         logical zero
+         if (zero()) stop 1
+      end
diff --git a/gcc/testsuite/gfortran.dg/pr91359_2.f b/gcc/testsuite/gfortran.dg/pr91359_2.f
new file mode 100644 (file)
index 0000000..2b8a35a
--- /dev/null
@@ -0,0 +1,16 @@
+! { dg do run }
+! PR fortran/91359
+! Orginal code contributed by Brian T. Carcich <briantcarcich at gmail dot com>
+!
+      logical function zero() result(a)
+         goto 2
+1        return
+2        a = .false.
+         if (.not.a) goto 1
+         return
+      end
+
+      program test_zero
+         logical zero
+         if (zero()) stop 1
+      end