Skip to content

Commit 58da39c

Browse files
committed
PASS: Handle bounds for arr mem in struct
1 parent c396abc commit 58da39c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/libasr/asr_utils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,7 @@ static inline ASR::symbol_t *get_asr_owner(const ASR::expr_t *expr) {
698698
return ASRUtils::get_asr_owner(ASR::down_cast<ASR::FunctionCall_t>(expr)->m_name);
699699
}
700700
default: {
701-
throw LCompilersException("Cannot find the ASR owner of underlying symbol of expression "
702-
+ std::to_string(expr->type));
701+
return nullptr;
703702
}
704703
}
705704
return nullptr;

src/libasr/pass/pass_utils.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,25 @@ namespace LCompilers {
560560

561561
ASR::expr_t* get_bound(ASR::expr_t* arr_expr, int dim, std::string bound,
562562
Allocator& al) {
563+
ASR::ttype_t* x_mv_type = ASRUtils::expr_type(arr_expr);
564+
ASR::dimension_t* m_dims;
565+
int n_dims = ASRUtils::extract_dimensions_from_ttype(x_mv_type, m_dims);
566+
bool is_data_only_array = ASRUtils::is_fixed_size_array(m_dims, n_dims) && ASRUtils::get_asr_owner(arr_expr) &&
567+
ASR::is_a<ASR::StructType_t>(*ASRUtils::get_asr_owner(arr_expr));
563568
ASR::ttype_t* int32_type = ASRUtils::TYPE(ASR::make_Integer_t(al, arr_expr->base.loc, 4));
569+
if (is_data_only_array) {
570+
const Location& loc = arr_expr->base.loc;
571+
ASR::expr_t* zero = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loc, 0, int32_type));
572+
ASR::expr_t* one = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loc, 1, int32_type));
573+
if( bound == "ubound" ) {
574+
return ASRUtils::EXPR(ASR::make_IntegerBinOp_t(
575+
al, arr_expr->base.loc, m_dims[dim - 1].m_length, ASR::binopType::Sub, one, int32_type, nullptr));
576+
}
577+
if ( m_dims[dim - 1].m_start != nullptr ) {
578+
return m_dims[dim - 1].m_start;
579+
}
580+
return zero;
581+
}
564582
ASR::expr_t* dim_expr = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, arr_expr->base.loc, dim, int32_type));
565583
ASR::arrayboundType bound_type = ASR::arrayboundType::LBound;
566584
if( bound == "ubound" ) {

0 commit comments

Comments
 (0)