-
-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: rewrite initialization, increment and condition for replace_doloop
#3911
base: main
Are you sure you want to change the base?
Conversation
…oop` The transformation set `i = a-c` initially, was incorrect because it effectively changes the starting value of the loop variable `i`. Fixes lfortran#3902
Seems like the below program with the PR's changes would never end: program main
implicit none
integer(4) :: k
k = 1
do while (k <= 4)
if (k == 3) then
cycle
end if
print *, "variable i =", k
k = k + 1
end do
end program main |
I think we did this intentionally, I do not know the reason atm. I commented way to fix #3902 there, basically this is old convention of writing codes, we encountered in SciPy and hence introduced |
@@ -8,6 +8,7 @@ program doloop_04 | |||
j = j + i | |||
end do | |||
if (j /= 25) error stop | |||
if (i /= 11) error stop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all these changes will work with --use-loop-variable-after-loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, I did initially wonder what the purpose of use_loop_variable_after_loop
in replace_doloop
is.
Maybe the possibility of abrupt ending (via @certik can you please confirm? If that's the case, I think there is nothing to do here, as we probably need to use |
I'm curious for if above is the reason, isn't it possible to increment the loop variable before appending the |
The transformation set
i = a-c
initially, was incorrect because it effectively changes the starting value of the loop variablei
.Fixes #3902