[flang-commits] [flang] [Flang][Semantics] Treat function result variables as local in pure definability checks. (PR #192892)

via flang-commits flang-commits at lists.llvm.org
Thu Apr 30 01:14:03 PDT 2026


================
@@ -338,12 +338,16 @@ const Symbol *FindExternallyVisibleObject(
         IsPureProcedure(ultimate.owner()) && IsFunction(ultimate.owner())) {
       return &ultimate;
     }
+  } else if (IsFunctionResult(ultimate)) {
----------------
jeanPerier wrote:

So, this is actually too broad, because this could be the function result of a parent procedure, in which case it is invalid to modify it.

For instance, after your patch, I think no error will be raised for:

```
function test_func(x) result(i)
  integer, pointer :: i
  real :: x
  x = func()
contains
 real pure function func()
   i = 0
   func = 0.
 end function
end function
```

To be fair, doing so you also exposed an existing similar bug for the IsDummy check above that is allowing the following code to pass through:

```
subroutine test_bad(i, x)
  integer, pointer :: i
  real :: x
  x = func()
contains
 real pure function func()
   i = 0
   func = 0.
 end function
end subroutine
```

https://github.com/llvm/llvm-project/pull/192892


More information about the flang-commits mailing list