[flang-commits] [flang] [flang][lowering] fix vector subscripts in character elemental procedures (PR #156661)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Wed Sep 3 08:47:38 PDT 2025
================
@@ -274,3 +275,48 @@ subroutine foo6(c)
! CHECK: }
end module
+
+subroutine bug_145151(c, vector_subscript)
+ interface
+ elemental function f(c_dummy)
+ character(*), intent(in) :: c_dummy
+ character(len(c_dummy, KIND=8)) :: f
+ end
+ end interface
+ integer(8) :: vector_subscript(100)
+ character(*) :: c(100)
+ c = f(c(vector_subscript))
+end subroutine
+! CHECK-LABEL: func.func @_QPbug_145151(
+! CHECK-SAME: %[[ARG0:.*]]: !fir.boxchar<1>
+! CHECK: %[[VAL_1:.*]]:2 = fir.unboxchar %[[ARG0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
+! CHECK: %[[VAL_2:.*]] = fir.convert %[[VAL_1]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<!fir.array<100x!fir.char<1,?>>>
+! CHECK: %[[VAL_3:.*]] = arith.constant 100 : index
+! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_3]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %{{.*}}"_QFbug_145151Ec"} : (!fir.ref<!fir.array<100x!fir.char<1,?>>>,
+! CHECK: %[[VAL_10:.*]]:2 = hlfir.declare %{{.*}}"_QFbug_145151Evector_subscript"} : (!fir.ref<!fir.array<100xi64>>,
+! CHECK: %[[VAL_11:.*]] = arith.constant 100 : index
+! CHECK: %[[VAL_12:.*]] = fir.shape %[[VAL_11]] : (index) -> !fir.shape<1>
+! CHECK: %[[VAL_13:.*]] = arith.constant 1 : index
+! CHECK: %[[VAL_14:.*]] = hlfir.designate %[[VAL_10]]#0 (%[[VAL_13]]) : (!fir.ref<!fir.array<100xi64>>, index) -> !fir.ref<i64>
+! CHECK: %[[VAL_15:.*]] = fir.load %[[VAL_14]] : !fir.ref<i64>
----------------
vzakhari wrote:
Thank you for the fix, Jean!
I am a bit concerned about this load from the subscripts array - what will happen here for the zero-sized assumed shape arrays (if it is even a valid example)?
https://github.com/llvm/llvm-project/pull/156661
More information about the flang-commits
mailing list