Skip to content

[flang] accept character type in fir::changeTypeShape #131892

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
Mar 19, 2025

Conversation

jeanPerier
Copy link
Contributor

@jeanPerier jeanPerier commented Mar 18, 2025

There is no reason for character element type to be forbidden in this helper.
The assert was firing in character pointer assignment in FORALL after #130772 added a usage of this helper.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Mar 18, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 18, 2025

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

Author: None (jeanPerier)

Changes

There is no reason for character element type to be forbidden in this helper.
The assert was firing in character pointer assignment in FORALL after #130772 added a usage of this helper.


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

2 Files Affected:

  • (modified) flang/lib/Optimizer/Dialect/FIRType.cpp (+2-1)
  • (modified) flang/test/HLFIR/order_assignments/forall-pointer-assignment-scheduling.f90 (+15)
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index dc0bee9b060c9..f3f969ba401e5 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -1326,7 +1326,8 @@ changeTypeShape(mlir::Type type,
       })
       .Default([&](mlir::Type t) -> mlir::Type {
         assert((fir::isa_trivial(t) || llvm::isa<fir::RecordType>(t) ||
-                llvm::isa<mlir::NoneType>(t)) &&
+                llvm::isa<mlir::NoneType>(t) ||
+                llvm::isa<fir::CharacterType>(t)) &&
                "unexpected FIR leaf type");
         if (newShape)
           return fir::SequenceType::get(*newShape, t);
diff --git a/flang/test/HLFIR/order_assignments/forall-pointer-assignment-scheduling.f90 b/flang/test/HLFIR/order_assignments/forall-pointer-assignment-scheduling.f90
index cb5bff1020b3a..fc2ef5248e410 100644
--- a/flang/test/HLFIR/order_assignments/forall-pointer-assignment-scheduling.f90
+++ b/flang/test/HLFIR/order_assignments/forall-pointer-assignment-scheduling.f90
@@ -85,6 +85,21 @@ subroutine test_need_to_save_lhs_and_rhs(n, a)
 ! CHECK-NEXT: conflict: R/W
 ! CHECK-NEXT: run 1 save    : forall/region_assign1/lhs
 ! CHECK-NEXT: run 2 evaluate: forall/region_assign1
+
+subroutine test_character_no_conflict(c)
+ type tc
+    character(10), pointer :: p
+ end type
+ character(10), target :: c(10)
+ integer(8) :: i
+ type(tc) a(10)
+ forall(i=1:10)
+   a(i)%p => c(i)
+ end forall
+end subroutine
+! CHECK: ------------ scheduling forall in _QMforall_pointersPtest_character_no_conflict ------------
+! CHECK-NEXT: run 1 evaluate: forall/region_assign1
+
 end module
 
 ! End to end test provided for debugging purpose (not run by lit).

Copy link
Contributor

@akuhlens akuhlens left a comment

Choose a reason for hiding this comment

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

TY!

@jeanPerier jeanPerier merged commit b8271ec into llvm:main Mar 19, 2025
14 checks passed
@jeanPerier jeanPerier deleted the fix_change_shape branch March 19, 2025 09:01
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.

4 participants