forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flang][hlfir] address char_convert issues as mentioned in llvm#64315
- Loading branch information
1 parent
5c4d35d
commit 077ce5a
Showing
2 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
! Test lowering of character concatenation to HLFIR | ||
! RUN: bbc -emit-hlfir -o - %s 2>&1 | FileCheck %s | ||
|
||
subroutine charconvert1(c,n) | ||
character(*,4),intent(in) :: c(:) | ||
integer,intent(in) :: n | ||
interface | ||
subroutine callee(c) | ||
character(*),intent(in) :: c(:) | ||
end subroutine callee | ||
end interface | ||
call show([character(n)::c]) | ||
end subroutine charconvert1 | ||
|
||
! CHECK-LABEL: func.func @_QPcharconvert1 | ||
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFcharconvert1Ec"} : (!fir.box<!fir.array<?x!fir.char<4,?>>>) -> (!fir.box<!fir.array<?x!fir.char<4,?>>>, !fir.box<!fir.array<?x!fir.char<4,?>>>) | ||
! CHECK: ^bb0(%[[ARG2:.*]]: index): | ||
! CHECK: %[[VAL_37:.*]] = fir.box_elesize %[[VAL_2]]#1 : (!fir.box<!fir.array<?x!fir.char<4,?>>>) -> index | ||
! CHECK: %[[C4_4:.*]] = arith.constant 4 : index | ||
! CHECK: %[[VAL_38:.*]] = arith.divsi %[[VAL_37]], %[[C4_4]] : index | ||
! CHECK: %[[VAL_39:.*]] = hlfir.designate %[[VAL_2]]#0 (%[[ARG2]]) typeparams %[[VAL_38]] : (!fir.box<!fir.array<?x!fir.char<4,?>>>, index, index) -> !fir.boxchar<4> | ||
! CHECK: %[[C4_5:.*]] = arith.constant 4 : index | ||
! CHECK: %[[VAL_40:.*]] = arith.muli %[[VAL_38]], %[[C4_5]] : index | ||
! CHECK: %[[VAL_41:.*]] = fir.alloca !fir.char<1,?>(%[[VAL_40]] : index) | ||
! CHECK: %[[VAL_42:.*]]:2 = fir.unboxchar %[[VAL_39]] : (!fir.boxchar<4>) -> (!fir.ref<!fir.char<4,?>>, index) | ||
! CHECK: fir.char_convert %[[VAL_42]]#0 for %[[VAL_38:.*]] to %[[VAL_41]] : !fir.ref<!fir.char<4,?>>, index, !fir.ref<!fir.char<1,?>> | ||
! CHECK: %[[VAL_43:.*]]:2 = hlfir.declare %[[VAL_41]] typeparams %[[VAL_38]] {uniq_name = "ctor.temp"} : (!fir.ref<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>) | ||
! CHECK: hlfir.yield_element %[[VAL_43]]#0 : !fir.boxchar<1> | ||
! CHECK: } | ||
|
||
subroutine test2(x) | ||
integer,intent(in) :: x | ||
character(kind=4) :: cx | ||
cx = achar(x) | ||
end subroutine test2 | ||
! CHECK-LABEL: func.func @_QPtest2 | ||
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<i32> | ||
! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.char<1> | ||
! CHECK: %[[C1:.*]] = arith.constant 1 : index | ||
! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.char<4> {bindc_name = "cx", uniq_name = "_QFtest2Ecx"} | ||
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_1]] typeparams %[[C1]] {uniq_name = "_QFtest2Ecx"} : (!fir.ref<!fir.char<4>>, index) -> (!fir.ref<!fir.char<4>>, !fir.ref<!fir.char<4>>) | ||
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[ARG0]] {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFtest2Ex"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i32> | ||
! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i32) -> i64 | ||
! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (i64) -> i8 | ||
! CHECK: %[[VAL_7:.*]] = fir.undefined !fir.char<1> | ||
! CHECK: %[[VAL_8:.*]] = fir.insert_value %[[VAL_7]], %[[VAL_6]], [0 : index] : (!fir.char<1>, i8) -> !fir.char<1> | ||
! CHECK: fir.store %[[VAL_8:.*]] to %[[VAL_0]] : !fir.ref<!fir.char<1>> | ||
! CHECK: %[[FALSE:.*]] = arith.constant false | ||
! CHECK: %[[VAL_9:.*]] = hlfir.as_expr %[[VAL_0]] move %[[FALSE]] : (!fir.ref<!fir.char<1>>, i1) -> !hlfir.expr<!fir.char<1>> | ||
! CHECK: %[[C1_0:.*]] = arith.constant 1 : index | ||
! CHECK: %[[VAL_10:.*]] = fir.alloca !fir.char<4,?>(%[[C1_0]] : index) | ||
! CHECK: fir.char_convert %[[VAL_0:.*]] for %[[C1_0]] to %[[VAL_10]] : !fir.ref<!fir.char<1>>, index, !fir.ref<!fir.char<4,?>> | ||
! CHECK: %[[VAL_11:.*]]:2 = hlfir.declare %[[VAL_10]] typeparams %[[C1_0]] {uniq_name = "ctor.temp"} : (!fir.ref<!fir.char<4,?>>, index) -> (!fir.boxchar<4>, !fir.ref<!fir.char<4,?>>) | ||
! CHECK: %[[C1_I64:.*]] = arith.constant 1 : i64 | ||
! CHECK: %[[VAL_12:.*]] = hlfir.set_length %[[VAL_11]]#0 len %[[C1_I64]] : (!fir.boxchar<4>, i64) -> !hlfir.expr<!fir.char<4>> | ||
! CHECK: hlfir.assign %[[VAL_12:.*]] to %[[VAL_2]]#0 : !hlfir.expr<!fir.char<4>>, !fir.ref<!fir.char<4>> | ||
! CHECK: hlfir.destroy %[[VAL_9:.*]] : !hlfir.expr<!fir.char<1>> | ||
! CHECK: return | ||
! CHECK: } |