Honor type_spec in reshape ArrayConstructor lowering
F2018 §7.8: a typed array constructor '[T :: ...]' has element type T
regardless of the element expressions' types. The reshape lowering at
lower_reshape_array_expr_descriptor inferred elem_ty solely via
first_array_constructor_type_info, which examines the first value
expression. For 'reshape([real(dp) :: 1, 2, 3, 4], [2, 2])' the values
are integer literals (4 bytes), so the materialised descriptor was
elem_size=4 instead of 8.
The malformed elem_size propagated through the reshape result; when
passed to an assumed-shape dummy 'a(:,:)' and used as SOURCE= in an
ALLOCATE, afs_prepare_array_copy saw 'dest.elem_size != source.elem_size'
(8 != 4), freed the freshly-allocated dest buffer, zeroed base_addr,
and the next read of 'amat(1,1)' SEGV'd. Surfaced across stdlib's det /
determinant / eig / qr clusters whose examples invoke
'det(reshape([real(dp)::1,2,3,4], [2,2]))'.
Consult type_spec first; fall back to first-element inference only when
no type_spec is present.
regardless of the element expressions' types. The reshape lowering at
lower_reshape_array_expr_descriptor inferred elem_ty solely via
first_array_constructor_type_info, which examines the first value
expression. For 'reshape([real(dp) :: 1, 2, 3, 4], [2, 2])' the values
are integer literals (4 bytes), so the materialised descriptor was
elem_size=4 instead of 8.
The malformed elem_size propagated through the reshape result; when
passed to an assumed-shape dummy 'a(:,:)' and used as SOURCE= in an
ALLOCATE, afs_prepare_array_copy saw 'dest.elem_size != source.elem_size'
(8 != 4), freed the freshly-allocated dest buffer, zeroed base_addr,
and the next read of 'amat(1,1)' SEGV'd. Surfaced across stdlib's det /
determinant / eig / qr clusters whose examples invoke
'det(reshape([real(dp)::1,2,3,4], [2,2]))'.
Consult type_spec first; fall back to first-element inference only when
no type_spec is present.
Authored by
mfwolffe <wolffemf@dukes.jmu.edu>
- SHA
20fb85bb5e67aed3accc3356da6603346b499116- Parents
-
8e5daf7 - Tree
b86f7ff