[flang-commits] [flang] [flang][lowering] fix vector subscripts in character elemental procedures (PR #156661)
via flang-commits
flang-commits at lists.llvm.org
Fri Sep 5 02:39:00 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>
----------------
jeanPerier wrote:
It is a valid concern, thanks for catching this.
I updated the patch to address this by completely skipping the actual argument addressing when creating the mock arguments. There is no need to do so, and using the normal argument preparation comes with other side effects like copying VALUE arguments which is both wasted time in general and invalid for the zero size array case.
https://github.com/llvm/llvm-project/pull/156661
More information about the flang-commits
mailing list