Skip to content
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

enh: make_array_size_t_util to support IntrinsicArrayFunction #5346

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -522,6 +522,7 @@ RUN(NAME arrays_55 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc)
# TODO: the below test case doesn't work unless "EXPERIMENTAL SIMPLIFIER"
# is enabled i.e. works on `simplifier_pass` branch
# RUN(NAME arrays_56 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc)
RUN(NAME arrays_57 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc)
RUN(NAME global_allocatable_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc)
RUN(NAME global_allocatable_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc)
RUN(NAME global_array_pointer_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc)
21 changes: 21 additions & 0 deletions integration_tests/arrays_57.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
program arrays_57

real :: A(2,2) = reshape([1.0,2.0,3.0,4.0], [2,2])
call trans(A)
print *, A
if ( any(abs( A - 12.91 ) > 1e-6) ) error stop

contains

subroutine trans(A)
real, intent(inout) :: A(2, 2)
A = matprod(transpose(A))
end subroutine

function matprod(x) result(k)
real,intent(in) :: x(:,:)
real :: k(size(x, 1), size(x, 2))
k = 12.91
end function

end program
11 changes: 11 additions & 0 deletions src/libasr/asr_utils.h
Original file line number Diff line number Diff line change
@@ -2586,6 +2586,17 @@ static inline ASR::asr_t* make_ArraySize_t_util(
break;
}
}
} else if ( ASR::is_a<ASR::IntrinsicArrayFunction_t>(*a_v) && for_type ) {
ASR::IntrinsicArrayFunction_t* af = ASR::down_cast<ASR::IntrinsicArrayFunction_t>(a_v);
for ( size_t i = 0; i < af->n_args; i++ ) {
if ( ASRUtils::is_array(ASRUtils::expr_type(af->m_args[i])) ) {
a_v = af->m_args[i];
if ( ASR::is_a<ASR::ArrayPhysicalCast_t>(*a_v)) {
a_v = ASR::down_cast<ASR::ArrayPhysicalCast_t>(a_v)->m_arg;
}
break;
}
}
} else if( is_binop_expr(a_v) && for_type ) {
if( ASR::is_a<ASR::Var_t>(*extract_member_from_binop(a_v, 1)) ) {
return make_ArraySize_t_util(al, a_loc, extract_member_from_binop(a_v, 1), a_dim, a_type, a_value, for_type);
Loading