Here's a shorten version of your code, where I removed
the IO to make the tree-dump easier to read.

program test
   implicit none
   integer :: a
   a = 2
   call alt_ret (a, *10, *20)
   stop
10 stop 1
20 stop 2
   contains
      subroutine alt_ret (v, *, *)
         integer, intent (in) :: v
         if (v == 1) return 1
         if (v == 2) return 2
         return
      end subroutine alt_ret
end program test

Now, with -fdump-tree-original, the subroutine is converted to

__attribute__((fn spec (". r . . ")))
integer(kind=4) alt_ret (integer(kind=4) & restrict v)
{
  integer(kind=4) __result_alt_ret;

  __result_alt_ret = 0;
  if (*v == 1)
    {
      __result_alt_ret = 1;
      return __result_alt_ret;
    }
  L.1:;
  if (*v == 2)
    {
      __result_alt_ret = 2;
      return __result_alt_ret;
    }
  L.2:;
  return __result_alt_ret;
  return __result_alt_ret;
}

As can be seen, __result_alt_ret is defined and it is
returned to the main program.

__attribute__((fn spec (". ")))
void test ()
{
  static integer(kind=4) alt_ret (integer(kind=4) & restrict);
  integer(kind=4) _result_alt_ret;
  integer(kind=4) a;

  a = 2;
  _result_alt_ret = alt_ret (&a);
  switch (_result_alt_ret)
    {
     ...
}

--
steve

On 11/24/26 02:19, Martin Tee wrote:
Thanks Steve for the reply.

So, are you saying that _result_alt_ret should be a defined variable
somehow? Because that doesn't seem sensible to me as this is not a
function. Unless the alternate return labels are seen as "returned"
variables? Earlier versions of the complier didn't do this so has a new
feature been added?

Cheers,
Martin

On Mon, 2026-11-23 at 11:48 -0800, Steve Kargl wrote:
On 11/23/26 07:05, Martin Tee wrote:
Consider this alternate return program (yes, I know it's
obsolescent,
but gfortran does support it ATM):


code remove to keep this short.


gcc version 17.0.0 20261122 (experimental) (GCC)

      7 |       call alt_ret (a, *10, *20)
        |                                1
Warning: Undefined variable '_result_alt_ret' used at (1) [-
Wundefined-
vars]
-fdump-tree-original shows that _result_alt_ret becomes defined.
Add -Wno-undefined-vars to your options.

Reply via email to