Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang] Fix IsVariable() to be false for procedure pointers #72577

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

klausler
Copy link
Contributor

The implementation of the predicate evaluate::IsVariable() needs to recognize procedure pointers and return a false result for them.

The implementation of the predicate evaluate::IsVariable() needs
to recognize procedure pointers and return a false result for them.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Nov 16, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 16, 2023

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

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 --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

Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM

@klausler klausler merged commit fcf5154 into llvm:main Nov 30, 2023
5 checks passed
@klausler klausler deleted the bug1438 branch November 30, 2023 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants