-
-
Notifications
You must be signed in to change notification settings - Fork 234
Fix MATMUL: respect --realloc-lhs-arrays flag #9089
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 MATMUL: respect --realloc-lhs-arrays flag #9089
Conversation
|
... still have to wait how this plays with #9039 , let's merge it after that one. |
| real, allocatable :: A(:,:), B(:,:), C(:,:) | ||
| real :: expected | ||
|
|
||
| allocate(A(3, 4), B(4, 2), C(3, 2)) |
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.
Let's also add a test where C is not allocated, and ensure it works with --realloc-lhs-arrays, and that it gives a runtime error without i.
baebadb to
72e8757
Compare
|
Added
The integration test runs with the flag. The error case is verified manually but not added as a reference test due to test framework complications with runtime errors. |
|
Update: Both tests now added as requested:
Both tests pass locally. |
HarshitaKalani
left a comment
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.
Looks good to me. Thanks!
Remove unconditional allocation from instantiate_MatMul. Previously, MATMUL would allocate the result array inside the generated function regardless of the --realloc-lhs-arrays flag setting. This violated LFortran's stricter-by-default behavior where allocatable LHS arrays must be pre-allocated unless --realloc-lhs-arrays is specified. Now MATMUL respects the flag like regular array assignment: - Without flag: error if LHS is not allocated - With flag: auto-(re)allocate LHS as needed Add matmul_03 integration test covering pre-allocated result case. Fixes: lfortran#9086
Addresses review comment: test that matmul works when C is not pre-allocated, using --realloc-lhs-arrays flag. Without the flag, runtime error is raised as expected: Runtime Error: Array 'result' is indexed but not allocated.
Verifies that matmul to unallocated allocatable result gives: Runtime Error: Array 'result' is indexed but not allocated.
c1b3cb8 to
01e1adb
Compare
certik
left a comment
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.
Looks great, let's see if tests pass.
| @@ -0,0 +1,2 @@ | |||
| At 10:5 of file tests/errors/matmul_unallocated_01.f90 | |||
| Runtime Error: Array 'result' is indexed but not allocated. | |||
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.
I had to think a while about what this error means: I think we transform matmul to loops, then we index A, and that's where this error comes from. That's fine for now.
Fixes #9086.
Follow-up to #9050: remove unconditional allocation from
instantiate_MatMul. The allocation/reallocation of allocatable LHS should be handled by the assignment pass based on--realloc-lhs-arrays, not inside the intrinsic.Behavior now matches regular array assignment and other intrinsics.