-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flang] Fix issues with STORAGE_SIZE and characters (#67561)
Semantics was replacing storage_size(func()) by the length specification expression of func result (if any), which brought meaningless symbols. Update FunctionRef::GetType to not copy its length parameter from the procedure designator symbol if it is not a constant expression. Note that the deferred aspect can and must be preserved because it matters for POINTER function results (semantics test added to ensure this). Update lowering code to deal with characters in storage_size: simply always call createBox to ensure the BoxEleSizeOp is legal. This will take care of dereferencing pointers/allocatables if needed (what the load was intended for in the previous code).
- Loading branch information
1 parent
db777db
commit 8c12707
Showing
7 changed files
with
112 additions
and
6 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
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
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,33 @@ | ||
! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s | ||
subroutine test_storage_size(n) | ||
interface | ||
function return_char(l) | ||
integer :: l | ||
character(l) :: return_char | ||
end function | ||
end interface | ||
integer n | ||
!CHECK: PRINT *, storage_size(return_char(n)) | ||
print*, storage_size(return_char(n)) | ||
!CHECK: PRINT *, sizeof(return_char(n)) | ||
print*, sizeof(return_char(n)) | ||
end subroutine | ||
|
||
module pdts | ||
type t(l) | ||
integer, len :: l | ||
character(l) :: c | ||
end type | ||
contains | ||
function return_pdt(n) | ||
type(t(n)) :: return_pdt | ||
end function | ||
subroutine test(k) | ||
! NOTE: flang design for length parametrized derived type | ||
! is to use allocatables for the automatic components. Hence, | ||
! their size is independent from the length parameters and is | ||
! a compile time constant. | ||
!CHECK: PRINT *, 192_4 | ||
print *, storage_size(return_pdt(k)) | ||
end subroutine | ||
end module |
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,30 @@ | ||
! Test storage_size with characters | ||
! RUN: bbc -emit-hlfir %s -o - | FileCheck %s | ||
|
||
! check-label: func.func @_QPtest_storage_size | ||
subroutine test_storage_size(n) | ||
interface | ||
function return_char(l) | ||
integer :: l | ||
character(l) :: return_char | ||
end function | ||
end interface | ||
integer n | ||
print*, storage_size(return_char(n)) | ||
! CHECK: %[[val_16:.*]] = fir.call @_QPreturn_char(%[[res_addr:[^,]*]], %[[res_len:[^,]*]], {{.*}}) | ||
! CHECK: %[[res:.*]]:2 = hlfir.declare %[[res_addr]] typeparams %[[res_len]] | ||
! CHECK: %[[val_18:.*]] = fir.embox %[[res]]#1 typeparams %[[res_len]] : (!fir.ref<!fir.char<1,?>>, index) -> !fir.box<!fir.char<1,?>> | ||
! CHECK: %[[val_19:.*]] = fir.box_elesize %[[val_18]] : (!fir.box<!fir.char<1,?>>) -> i32 | ||
! CHECK: %[[val_20:.*]] = arith.constant 8 : i32 | ||
! CHECK: %[[val_21:.*]] = arith.muli %[[val_19]], %[[val_20]] : i32 | ||
! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[val_21]]) | ||
end subroutine | ||
|
||
function return_char(l) | ||
integer :: l | ||
character(l) :: return_char | ||
end function | ||
|
||
call test_storage_size(42) | ||
print *, 42*8 | ||
end |
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