Skip to content

[Flang] Get fir::SequenceType from hlfir::ExprType before getShape. #90055

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 2 commits into from
May 2, 2024

Conversation

DanielCChen
Copy link
Contributor

@DanielCChen DanielCChen commented Apr 25, 2024

This PR is to fix issue #88889 .
Because the type of an actual argument of an array expression of character has type of hlfir::ExprType, we need to transform it to fir::SequenceType before calling getBoxTypeWithNewShape.
Calling hlfir::ExprType::getShape inside of getBoxTypeWithNewShape will introduce a circular dependency on FIRDialect and HLFIRDialect libraries.

@DanielCChen DanielCChen requested a review from jeanPerier April 25, 2024 14:00
@DanielCChen DanielCChen self-assigned this Apr 25, 2024
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Apr 25, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 25, 2024

@llvm/pr-subscribers-flang-fir-hlfir

Author: Daniel Chen (DanielCChen)

Changes

This PR is to fix issue #88889 .
Because the type of an actual argument of an array expression of character has type of hlfir::ExprType, we need to transform it to fir::SequenceType before calling getBoxTypeWithNewShape.
Calling fir::ExprType::getShape inside of getBoxTypeWithNewShape will introduce a circular dependency on FIRDialect and HLFIRDialect libraries.


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

1 Files Affected:

  • (modified) flang/lib/Lower/ConvertCall.cpp (+7-3)
diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp
index c6f7d3410ad5cf..32c114865f92c7 100644
--- a/flang/lib/Lower/ConvertCall.cpp
+++ b/flang/lib/Lower/ConvertCall.cpp
@@ -1184,12 +1184,16 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
   // actual argument shape information. A descriptor with the dummy shape
   // information will be created later when all actual arguments are ready.
   mlir::Type dummyTypeWithActualRank = dummyType;
-  if (auto baseBoxDummy = mlir::dyn_cast<fir::BaseBoxType>(dummyType))
+  if (auto baseBoxDummy = mlir::dyn_cast<fir::BaseBoxType>(dummyType)) {
     if (baseBoxDummy.isAssumedRank() ||
         arg.testTKR(Fortran::common::IgnoreTKR::Rank) ||
-        arg.isSequenceAssociatedDescriptor())
+        arg.isSequenceAssociatedDescriptor()) {
+      mlir::Type actualTy =
+          hlfir::getFortranElementOrSequenceType(actual.getType());
       dummyTypeWithActualRank =
-          baseBoxDummy.getBoxTypeWithNewShape(actual.getType());
+          baseBoxDummy.getBoxTypeWithNewShape(actualTy);
+    }
+  }
   // Preserve the actual type in the argument preparation in case IgnoreTKR(t)
   // is set (descriptors must be created with the actual type in this case, and
   // copy-in/copy-out should be driven by the contiguity with regard to the

Copy link

github-actions bot commented Apr 25, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

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 for the fix!

@DanielCChen DanielCChen merged commit d617316 into llvm:main May 2, 2024
@DanielCChen
Copy link
Contributor Author

Thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants