[flang-commits] [flang] [flang] Fix IsVariable() to be false for procedure pointers (PR #72577)
via flang-commits
flang-commits at lists.llvm.org
Thu Nov 16 14:11:29 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
The implementation of the predicate evaluate::IsVariable() needs to recognize procedure pointers and return a false result for them.
---
Full diff: https://github.com/llvm/llvm-project/pull/72577.diff
2 Files Affected:
- (modified) flang/include/flang/Evaluate/tools.h (+7)
- (modified) flang/test/Semantics/associated.f90 (+3)
``````````diff
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index 55262a912d95629..ba065c4ee1b174e 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -59,6 +59,13 @@ struct IsVariableHelper
}
}
return false;
+ } else if constexpr (std::is_same_v<T, SomeType>) {
+ if (std::holds_alternative<ProcedureDesignator>(x.u) ||
+ std::holds_alternative<ProcedureRef>(x.u)) {
+ return false; // procedure pointer
+ } else {
+ return (*this)(x.u);
+ }
} else {
return (*this)(x.u);
}
diff --git a/flang/test/Semantics/associated.f90 b/flang/test/Semantics/associated.f90
index bf8bcf474986336..1da94d28ae6bacc 100644
--- a/flang/test/Semantics/associated.f90
+++ b/flang/test/Semantics/associated.f90
@@ -92,6 +92,7 @@ subroutine test(assumedRank)
integer, target :: targetIntArr(2)
integer, target :: targetIntCoarray[*]
integer, pointer :: intPointerArr(:)
+ procedure(objPtrFunc), pointer :: objPtrFuncPointer
!ERROR: Assumed-rank array cannot be forwarded to 'target=' argument
lvar = associated(assumedRank, assumedRank)
@@ -204,6 +205,8 @@ subroutine test(assumedRank)
lvar = associated(intProcPointer1, elementalProc)
!ERROR: POINTER= argument 'intpointervar1' is an object pointer but the TARGET= argument 'intfunc' is not a variable
lvar = associated (intPointerVar1, intFunc)
+ !ERROR: POINTER= argument 'intpointervar1' is an object pointer but the TARGET= argument 'objptrfuncpointer' is not a variable
+ lvar = associated (intPointerVar1, objPtrFuncPointer)
!ERROR: In assignment to object pointer 'intpointervar1', the target 'intfunc' is a procedure designator
intPointerVar1 => intFunc
!ERROR: In assignment to procedure pointer 'intprocpointer1', the target is not a procedure or procedure pointer
``````````
</details>
https://github.com/llvm/llvm-project/pull/72577
More information about the flang-commits
mailing list