Skip to content

Commit d20a094

Browse files
authored
Merge pull request #1903 from Shaikh-Ubaid/asr_verify_arr_dims
ASRVerify: Require signed integer array dimensions
2 parents b729d70 + a75d763 commit d20a094

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/libasr/asr_utils.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ static inline ASR::ttype_t *type_get_past_array(ASR::ttype_t *f)
115115
}
116116
}
117117

118+
static inline ASR::ttype_t *type_get_past_const(ASR::ttype_t *f)
119+
{
120+
if (ASR::is_a<ASR::Const_t>(*f)) {
121+
ASR::Const_t *e = ASR::down_cast<ASR::Const_t>(f);
122+
LCOMPILERS_ASSERT(!ASR::is_a<ASR::Const_t>(*e->m_type));
123+
return e->m_type;
124+
} else {
125+
return f;
126+
}
127+
}
128+
118129
static inline ASR::Variable_t* EXPR2VAR(const ASR::expr_t *f)
119130
{
120131
return ASR::down_cast<ASR::Variable_t>(symbol_get_past_external(

src/libasr/asr_verify.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,22 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor>
10151015
BaseWalkVisitor<VerifyVisitor>::visit_ArrayConstant(x);
10161016
}
10171017

1018+
void visit_dimension(const dimension_t &x) {
1019+
if (x.m_start) {
1020+
require_with_loc(ASR::is_a<ASR::Integer_t>(
1021+
*ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_start))),
1022+
"Start dimension must be a signed integer", x.loc);
1023+
visit_expr(*x.m_start);
1024+
}
1025+
1026+
if (x.m_length) {
1027+
require_with_loc(ASR::is_a<ASR::Integer_t>(
1028+
*ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_length))),
1029+
"Length dimension must be a signed integer", x.loc);
1030+
visit_expr(*x.m_length);
1031+
}
1032+
}
1033+
10181034
void visit_Array(const Array_t& x) {
10191035
visit_ttype(*x.m_type);
10201036
require(x.n_dims != 0, "Array type cannot have 0 dimensions.")

0 commit comments

Comments
 (0)