[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)) {
+ // A function result variable is local to its function and not an
+ // externally visible object for C1594 checks.
+ return nullptr;
} else if (ultimate.owner().IsDerivedType()) {
return nullptr;
} else if (&GetProgramUnitContaining(ultimate) !=
&GetProgramUnitContaining(scope)) {
----------------
jeanPerier wrote:
If I understand correctly the issue you are fixing, it is not related to function result of pure function in general, but to the function results of pure _module procedure_, is that correct?
I think the issues lies here in that `&GetProgramUnitContaining(ultimate) !=&GetProgramUnitContaining(scope)` does not really work as intended for module procedure where the function result symbol (`ultimate` here) is defined inside the scope of the interface and not the scope of the implementation (`scope` here).
I wonder if a stronger fix wouldn't be to use `IsHostAssociatedIntoSubprogram` and `IsUseAssociated` to detect host/use assoicated data instead (assuming they are coping with the module procedure case just fine).
Then there is no need to special case function result at all.
This checks should also likely be moved before the IsDummy checks to avoid bypassing it for the internal procedure case I gave above (the `ultimate.owner().IsDerivedType()` may still need to come first).
https://github.com/llvm/llvm-project/pull/192892
More information about the flang-commits
mailing list