This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fix "EQ" comparison of arrays
ClosedPublic

Authored by PeteSteinfeld on Nov 13 2020, 9:33 AM.

Details

Summary

When comparing arrays whose shapes do not conform, the contant folding
code ran into problems trying to get the value of an extent that did not
exist. There were actually two problems. First, the routine
"CheckConformance()" was returning "true" when the compiler was unable
to get the extent of an array. Second, the function
"ApplyElementwise()" was calling "CheckConformance()" prior to folding
the elements of two arrays, but it was ignoring the return value.

Diff Detail

Event Timeline

PeteSteinfeld created this revision.Nov 13 2020, 9:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 13 2020, 9:33 AM
PeteSteinfeld requested review of this revision.Nov 13 2020, 9:33 AM
PeteSteinfeld added a project: Restricted Project.Nov 13 2020, 9:34 AM
klausler accepted this revision.Nov 13 2020, 10:00 AM
klausler added inline comments.
flang/lib/Evaluate/shape.cpp
698

Might be more readable if restructured. Two possible ways:

for (int j{0}; j < n; ++j) {

auto leftDim{...}, rightDim{...};
if (!leftDim || !rightDim) { return false; }
if (*leftDim != *rightDim) { Say(...); return false; }

}

or

for (int j{0}; j < n; ++j) {

if (auto leftDim{...}) {
  if (auto rightDim{...}) {
    if (*leftDim == *rightDim) {
      continue;
    }
    Say(...);
  }
}
return false;

}

This revision is now accepted and ready to land.Nov 13 2020, 10:00 AM
PeteSteinfeld added inline comments.Nov 13 2020, 1:00 PM
flang/lib/Evaluate/shape.cpp
698

Thanks for the suggestions. I like the first one. I'll rework the code.

Reworked the code to check array shape conformance as suggested by Peter.

tskeith accepted this revision.Nov 13 2020, 2:31 PM
This revision was automatically updated to reflect the committed changes.