Skip to content

[Flang] Use specific symbol rather than generic symbol as procInterface to declare procedure pointer. #80738

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

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

DanielCChen
Copy link
Contributor

@DanielCChen DanielCChen commented Feb 5, 2024

Flang crashes when lowering the type of p1 with the following code. The problem is when it sets up the procInterface, it uses the generic symbol int, not the specific int. This PR is to correct that.

  INTERFACE Int
    integer FUNCTION Int(arg)
      integer :: arg
    END FUNCTION
  END INTERFACE

  integer :: res
  procedure(int), pointer :: p1
  p1 => int
  res = p1(4)
  end

@DanielCChen DanielCChen self-assigned this Feb 5, 2024
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Feb 5, 2024
@DanielCChen DanielCChen changed the title [Flang] Use specific symbol rather than generic symbol as proceInterface to declare procedure pointer. [Flang] Use specific symbol rather than generic symbol as procInterface to declare procedure pointer. Feb 5, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 5, 2024

@llvm/pr-subscribers-flang-semantics

Author: Daniel Chen (DanielCChen)

Changes

Flang crashes when lowering the type of p1 with the following code. The problem is when it sets up the proceInterface, it uses the generic symbol int, not the specific int. This PR is to correct that.

  INTERFACE Int
    integer FUNCTION Int(arg)
      integer :: arg
    END FUNCTION
  END INTERFACE

  integer :: res
  procedure(int), pointer :: p1
  p1 => int
  res = p1(4)
  end

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

1 Files Affected:

  • (modified) flang/lib/Semantics/resolve-names.cpp (+3-1)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 6914f95837f676..36deab969456d0 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5648,7 +5648,9 @@ 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;
+    procInterface = interfaceName_->symbol->has<GenericDetails>()
+        ? interfaceName_->symbol->get<GenericDetails>().specific()
+        : interfaceName_->symbol;
   }
   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.

Thanks Daniel, this makes sense to me.

@DanielCChen
Copy link
Contributor Author

Thanks for the review!

@DanielCChen DanielCChen merged commit 7e4ac85 into llvm:main Feb 7, 2024
@DanielCChen DanielCChen deleted the cdchen branch February 7, 2024 16:38
DanielCChen added a commit that referenced this pull request Feb 8, 2024
…modules (#81087)

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 added a commit to DanielCChen/llvm-project that referenced this pull request Feb 19, 2024
…erent way by adding a GenericDetails in GetTypeImpl.
DanielCChen added a commit to DanielCChen/llvm-project that referenced this pull request Feb 21, 2024
…erent way by adding a GenericDetails in GetTypeImpl.
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.

3 participants