Fix size calculation for reallocation for matmul of rank 2 a and rank 1 b.
Corrects Fortran matmul LHS reallocation size calculation for specific rank combinations.
This commit fixes a bug in the Fortran front-end’s matmul operation that affected the size calculation for reallocating the left-hand side (LHS) expression when it is allocatable. The fix specifically addresses the case where a rank-2 array is multiplied by a rank-1 array, ensuring the LHS is resized correctly.
In Details
The matmul_lhs_realloc function in gcc/fortran/frontend-passes.cc incorrectly calculated the reallocation size for the LHS of a matmul operation when a rank-2 array (A2) was multiplied by a rank-1 array (B1). This commit corrects a single character in the size calculation logic for this specific A2B1 case, ensuring that the allocatable LHS is properly sized for the result of the matmul. A new test case, inline_matmul_28.f90, verifies this fix.
- matmul
- The matrix multiplication intrinsic function in Fortran.
- LHS
- Abbreviation for Left-Hand Side, referring to the expression on the left side of an assignment or operation.
- allocatable
- A Fortran attribute that allows an array or scalar to have its size determined and memory allocated at runtime.
- rank
- In Fortran, the rank of an array refers to the number of dimensions it has (e.g., a scalar is rank 0, a vector is rank 1, a matrix is rank 2).