[flang] Don't fold operation when shapes differ
authorLeandro Lupori <leandro.lupori@linaro.org>
Tue, 28 Mar 2023 14:28:56 +0000 (14:28 +0000)
committerLeandro Lupori <leandro.lupori@linaro.org>
Fri, 31 Mar 2023 12:13:14 +0000 (09:13 -0300)
commit5e5176adb1834b215412a90acadfa0d14c18de8f
tree37453dd34167d37425a7d59f64c60aa41824fdba
parent942b403ff1a412778c9fb97bd53b44e35b544b0e
[flang] Don't fold operation when shapes differ

When folding a binary operation between two array constructors, it
is necessary to check if each value contained in the left operand
has the same rank and shape as the one on the right.
Otherwise, lowering would end up with an operation between values
of different ranks/shapes, which could result in a crash.

For instance, the following code was crashing the compiler:
integer :: x(4), y(2, 2), z(4)

z = (/x/) + (/y/)

Fixes #60229

Reviewed By: klausler, jeanPerier

Differential Revision: https://reviews.llvm.org/D147181
flang/lib/Evaluate/fold-implementation.h
flang/test/Evaluate/rewrite01.f90
flang/test/Lower/array-expression.f90