Skip to content

Commit

Permalink
ASRVerify: Require signed integer array dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaikh-Ubaid committed Jun 13, 2023
1 parent b729d70 commit a75d763
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/libasr/asr_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ static inline ASR::ttype_t *type_get_past_array(ASR::ttype_t *f)
}
}

static inline ASR::ttype_t *type_get_past_const(ASR::ttype_t *f)
{
if (ASR::is_a<ASR::Const_t>(*f)) {
ASR::Const_t *e = ASR::down_cast<ASR::Const_t>(f);
LCOMPILERS_ASSERT(!ASR::is_a<ASR::Const_t>(*e->m_type));
return e->m_type;
} else {
return f;
}
}

static inline ASR::Variable_t* EXPR2VAR(const ASR::expr_t *f)
{
return ASR::down_cast<ASR::Variable_t>(symbol_get_past_external(
Expand Down
16 changes: 16 additions & 0 deletions src/libasr/asr_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,22 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor>
BaseWalkVisitor<VerifyVisitor>::visit_ArrayConstant(x);
}

void visit_dimension(const dimension_t &x) {
if (x.m_start) {
require_with_loc(ASR::is_a<ASR::Integer_t>(
*ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_start))),
"Start dimension must be a signed integer", x.loc);
visit_expr(*x.m_start);
}

if (x.m_length) {
require_with_loc(ASR::is_a<ASR::Integer_t>(
*ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_length))),
"Length dimension must be a signed integer", x.loc);
visit_expr(*x.m_length);
}
}

void visit_Array(const Array_t& x) {
visit_ttype(*x.m_type);
require(x.n_dims != 0, "Array type cannot have 0 dimensions.")
Expand Down

0 comments on commit a75d763

Please sign in to comment.