Skip to content

Commit 8b1988d

Browse files
authored
Merge pull request #2501 from Shaikh-Ubaid/fix_const_step_in_loop
Fix const step in loop
2 parents 20b93b4 + b26d942 commit 8b1988d

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ RUN(NAME loop_04 LABELS cpython llvm c)
509509
RUN(NAME loop_05 LABELS cpython llvm c)
510510
RUN(NAME loop_06 LABELS cpython llvm c NOFAST)
511511
RUN(NAME loop_07 LABELS cpython llvm c)
512+
RUN(NAME loop_08 LABELS cpython llvm c)
512513
RUN(NAME if_01 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
513514
RUN(NAME if_02 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
514515
RUN(NAME if_03 FAIL LABELS cpython llvm c NOFAST)

integration_tests/loop_08.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from lpython import i32, Const
2+
3+
def main0():
4+
i: i32
5+
n: Const[i32] = 10
6+
M2: Const[i32] = 2
7+
y: i32 = 0
8+
for i in range(0, n, M2): # each M2 block in A cols and B rows # !!!!!!!!!!!!!!
9+
y = y + 2
10+
print(y)
11+
assert(y == 10)
12+
13+
main0()

src/libasr/pass/pass_utils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,8 @@ namespace LCompilers {
893893
if( comp == -1 ) {
894894
int increment;
895895
bool not_constant_inc = false;
896-
if (!ASRUtils::is_integer(*ASRUtils::expr_type(c))) {
896+
if (!ASRUtils::is_integer(*ASRUtils::type_get_past_const(
897+
ASRUtils::expr_type(c)))) {
897898
throw LCompilersException("Do loop increment type should be an integer");
898899
}
899900
if (c->type == ASR::exprType::IntegerConstant) {

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5301,7 +5301,8 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
53015301
head.m_start = loop_start;
53025302
head.m_increment = inc;
53035303

5304-
if( !ASR::is_a<ASR::Integer_t>(*ASRUtils::expr_type(inc)) ) {
5304+
if( !ASR::is_a<ASR::Integer_t>(*ASRUtils::type_get_past_const(
5305+
ASRUtils::expr_type(inc))) ) {
53055306
throw SemanticError("For loop increment type should be Integer.", loc);
53065307
}
53075308
ASR::expr_t *inc_value = ASRUtils::expr_value(inc);

0 commit comments

Comments
 (0)