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] Update the fix of PR 80738 to cover generic interface inside modules #81087

Merged
merged 1 commit into from
Feb 8, 2024

Conversation

DanielCChen
Copy link
Contributor

The following test cases crashes. The problem is that the fix for PR #80738 is not quite complete. It should GetUltimate() of the interface_ before check if it is generic.

  MODULE M

    CONTAINS

    FUNCTION Int(Arg)
    INTEGER :: Int, Arg
      Int = Arg
    END FUNCTION

    FUNCTION Int8(Arg)
    INTEGER(8) :: Int8, Arg
      Int8 = 8_8
    END FUNCTION

  END MODULE

  MODULE M1
  USE M

    INTERFACE Int8
      MODULE PROCEDURE  Int
      MODULE PROCEDURE  Int8
    END INTERFACE

  END MODULE

  PROGRAM PtrAssignGen
  USE M
  USE M1
  IMPLICIT NONE

  INTERFACE Int
    MODULE PROCEDURE  Int
    MODULE PROCEDURE  Int8
  END INTERFACE

  PROCEDURE(Int8),   POINTER :: PtrInt8

  PtrInt8 => Int8
  IF ( PtrInt8(100_8) .NE. 8_8 ) ERROR STOP 12

  END

@DanielCChen DanielCChen self-assigned this Feb 8, 2024
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Feb 8, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 8, 2024

@llvm/pr-subscribers-flang-semantics

Author: Daniel Chen (DanielCChen)

Changes

The following test cases crashes. The problem is that the fix for PR #80738 is not quite complete. It should GetUltimate() of the interface_ before check if it is generic.

  MODULE M

    CONTAINS

    FUNCTION Int(Arg)
    INTEGER :: Int, Arg
      Int = Arg
    END FUNCTION

    FUNCTION Int8(Arg)
    INTEGER(8) :: Int8, Arg
      Int8 = 8_8
    END FUNCTION

  END MODULE

  MODULE M1
  USE M

    INTERFACE Int8
      MODULE PROCEDURE  Int
      MODULE PROCEDURE  Int8
    END INTERFACE

  END MODULE

  PROGRAM PtrAssignGen
  USE M
  USE M1
  IMPLICIT NONE

  INTERFACE Int
    MODULE PROCEDURE  Int
    MODULE PROCEDURE  Int8
  END INTERFACE

  PROCEDURE(Int8),   POINTER :: PtrInt8

  PtrInt8 => Int8
  IF ( PtrInt8(100_8) .NE. 8_8 ) ERROR STOP 12

  END

Full diff: https://github.com/llvm/llvm-project/pull/81087.diff

1 Files Affected:

  • (modified) flang/lib/Semantics/resolve-names.cpp (+4-3)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 36deab969456d0..2a42c79161468a 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5648,9 +5648,10 @@ void DeclarationVisitor::Post(const parser::ProcDecl &x) {
   const auto &name{std::get<parser::Name>(x.t)};
   const Symbol *procInterface{nullptr};
   if (interfaceName_) {
-    procInterface = interfaceName_->symbol->has<GenericDetails>()
-        ? interfaceName_->symbol->get<GenericDetails>().specific()
-        : interfaceName_->symbol;
+    Symbol *ultimate{&interfaceName_->symbol->GetUltimate()};
+    procInterface = ultimate->has<GenericDetails>()
+        ? ultimate->get<GenericDetails>().specific()
+        : ultimate;
   }
   auto attrs{HandleSaveName(name.source, GetAttrs())};
   DerivedTypeDetails *dtDetails{nullptr};

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.

LGTM

@DanielCChen DanielCChen merged commit 0802596 into llvm:main Feb 8, 2024
7 checks passed
@DanielCChen DanielCChen deleted the daniel_pptr2 branch February 8, 2024 15:38
@psteinfeld
Copy link
Contributor

This change is causing some of our tests to fail. Here's an example. I have two files that are compiled separately. Here's the first file:

module fmod
contains
  subroutine inner(n)
    print *, n
  end subroutine
end module
module fmod1
  use fmod,proc1=>inner
  procedure(proc1),pointer :: p1
end module

I then compile this file with flang-new -c first.f90. Here's the second file:

Program test
  Use fmod1
  p1 => proc1
  Call p1(343)
End Program

I then compile this file with flang-new main.f90 first.o. I expect this to not produce errors. But I get the following output:

error: Semantic errors in main.f90
./main.f90:3:3: error: 'inner' is not a procedure
    p1 => proc1
    ^^^^^^^^^^^
./main.f90:3:3: error: In assignment to object pointer 'p1', the target 'inner' is a procedure designator
    p1 => proc1
    ^^^^^^^^^^^
./fmod1.mod:4:27: Declaration of 'p1'
  procedure(inner),pointer::p1
                            ^^
./main.f90:4:3: error: 'inner' is not a procedure
    Call p1(343)
    ^^^^^^^^^^^^
./fmod1.mod:4:11: error: 'inner' must be an abstract interface or a procedure with an explicit interface
  procedure(inner),pointer::p1
            ^^^^^

Weirdly, if I concatenate these two files, everything works.

I'm planning to revert this change. Stay tuned for that.

psteinfeld added a commit to psteinfeld/llvm-project that referenced this pull request Feb 9, 2024
… inside modules (llvm#81087)"

This reverts commit 0802596.

See comments in PR llvm#81087 for a test case that shows why I'm reverting.
psteinfeld added a commit that referenced this pull request Feb 10, 2024
#81321)

… inside modules (#81087)"

This reverts commit 0802596.

See comments in PR #81087 for a test case that shows why I'm reverting.
@DanielCChen
Copy link
Contributor Author

@psteinfeld Thanks for the notification. I will take a another look of the fix and your test case.

@DanielCChen
Copy link
Contributor Author

#81544 is created to handle both the original case in this PR and the regressions.

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

4 participants