From 58da39ccb94597e05aba9f457de6257d8ddbe39f Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Fri, 22 Sep 2023 23:14:55 +0530 Subject: [PATCH] PASS: Handle bounds for arr mem in struct --- src/libasr/asr_utils.h | 3 +-- src/libasr/pass/pass_utils.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index 3880ce25d2..9284ca6c97 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -698,8 +698,7 @@ static inline ASR::symbol_t *get_asr_owner(const ASR::expr_t *expr) { return ASRUtils::get_asr_owner(ASR::down_cast(expr)->m_name); } default: { - throw LCompilersException("Cannot find the ASR owner of underlying symbol of expression " - + std::to_string(expr->type)); + return nullptr; } } return nullptr; diff --git a/src/libasr/pass/pass_utils.cpp b/src/libasr/pass/pass_utils.cpp index 50169d9093..18fa18c1e4 100644 --- a/src/libasr/pass/pass_utils.cpp +++ b/src/libasr/pass/pass_utils.cpp @@ -560,7 +560,25 @@ namespace LCompilers { ASR::expr_t* get_bound(ASR::expr_t* arr_expr, int dim, std::string bound, Allocator& al) { + ASR::ttype_t* x_mv_type = ASRUtils::expr_type(arr_expr); + ASR::dimension_t* m_dims; + int n_dims = ASRUtils::extract_dimensions_from_ttype(x_mv_type, m_dims); + bool is_data_only_array = ASRUtils::is_fixed_size_array(m_dims, n_dims) && ASRUtils::get_asr_owner(arr_expr) && + ASR::is_a(*ASRUtils::get_asr_owner(arr_expr)); ASR::ttype_t* int32_type = ASRUtils::TYPE(ASR::make_Integer_t(al, arr_expr->base.loc, 4)); + if (is_data_only_array) { + const Location& loc = arr_expr->base.loc; + ASR::expr_t* zero = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loc, 0, int32_type)); + ASR::expr_t* one = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loc, 1, int32_type)); + if( bound == "ubound" ) { + return ASRUtils::EXPR(ASR::make_IntegerBinOp_t( + al, arr_expr->base.loc, m_dims[dim - 1].m_length, ASR::binopType::Sub, one, int32_type, nullptr)); + } + if ( m_dims[dim - 1].m_start != nullptr ) { + return m_dims[dim - 1].m_start; + } + return zero; + } ASR::expr_t* dim_expr = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, arr_expr->base.loc, dim, int32_type)); ASR::arrayboundType bound_type = ASR::arrayboundType::LBound; if( bound == "ubound" ) {