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 argument mismatch issue #55841

Closed
kiranchandramohan opened this issue Jun 2, 2022 · 8 comments
Closed

[Flang] Fix argument mismatch issue #55841

kiranchandramohan opened this issue Jun 2, 2022 · 8 comments

Comments

@kiranchandramohan
Copy link
Contributor

kiranchandramohan commented Jun 2, 2022

When functions in different modules have the same name, it causes semantic checks to be confused. Using the wrong function signature for checks can cause the arguments to be mismatched. A reproducer is given below.

module aString
  implicit none
  Type string
    character(len=1),dimension(:),pointer :: c
  End Type string
  interface clean; module procedure clean_; end interface
contains
  subroutine clean_(str)
    implicit none
    type(string), intent(inout) :: str
  end subroutine clean_
end module

module aList
implicit none
Type list
  character(len=1),dimension(:),pointer :: bf
  integer,       dimension(:,:),pointer :: lc
End Type list
interface clean; module procedure clean_; end interface
contains
subroutine clean_(aList, stat)
implicit none
type(list),        intent(inout) :: aList
integer, optional, intent(out)   :: stat
end subroutine clean_
end module

module tmp_mod
use aString             ,only: a_string             => string
use aString             ,only: a_string_clean       => clean
use aList               ,only: a_list               => list
use aList               ,only: a_list_clean         => clean
end module

module flds
  use tmp_mod
  implicit none
contains
  subroutine sb()
    type(a_string) :: tmpOStr
    type(a_list)   :: tmpIstr
    call a_list_clean(tmpIstr)
    call a_string_clean(tmpOStr)
end subroutine
end module

This issue was found while investigating 527.cam4_r.

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 2, 2022

@llvm/issue-subscribers-flang-frontend

@klausler
Copy link
Contributor

Here's a patch that might help you advance to the next problem in that code:

diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 9f9107ea..dcf92101 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -2207,6 +2207,7 @@ const Symbol &ExpressionAnalyzer::AccessSpecific(
     // Create a renaming USE of the specific procedure.
     auto rename{context_.SaveTempName(
         used->symbol().owner().GetName().value().ToString() + "$" +
+        specific.owner().GetName().value().ToString() + "$" +
         specific.name().ToString())};
     return *const_cast<semantics::Scope &>(scope)
                 .try_emplace(rename, specific.attrs(),
diff --git a/flang/test/Semantics/modfile39.f90 b/flang/test/Semantics/modfile39.f90
index 6041d6cc..fbbd6ae4 100644
--- a/flang/test/Semantics/modfile39.f90
+++ b/flang/test/Semantics/modfile39.f90
@@ -36,11 +36,11 @@ end module
 !Expect: m2.mod
 !module m2
 !use m1,only:gen
-!use m1,only:m1$priv=>priv
-!private::m1$priv
+!use m1,only:m1$m1$priv=>priv
+!private::m1$m1$priv
 !contains
 !subroutine s(a)
-!real(4)::a(1_8:int(m1$priv(1_4),kind=8))
+!real(4)::a(1_8:int(m1$m1$priv(1_4),kind=8))
 !end
 !end

@kiranchandramohan kiranchandramohan moved this from To Do to In Progress in Flang Spec2017 issues Jun 14, 2022
@klausler
Copy link
Contributor

Does that patch solve your bug?

@kiranchandramohan
Copy link
Contributor Author

Thanks @klausler. Yes, it fixed the issue in this bug as well as in the benchmark. But as you say there are other issues.

@klausler
Copy link
Contributor

I don't think that I know anything or wrote anything about "other issues". What are they?

@kiranchandramohan
Copy link
Contributor Author

The other issues in cam4 seem to be in the lowering/MLIR area, at least the failures are coming from there. I will file separate issues for these.

@banach-space
Copy link
Contributor

@klausler Thanks for the fix! Are you planning to merge it? Once that's in tree, we can close this ticket.

@kiranchandramohan
Copy link
Contributor Author

Patch is here: https://reviews.llvm.org/D127790

@kiranchandramohan kiranchandramohan moved this from In Progress to Done in Flang Spec2017 issues Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants