This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fix an assert when RESHAPE() is called on empty strings
ClosedPublic

Authored by PeteSteinfeld on Jul 22 2020, 11:35 AM.

Details

Summary

When a constant array of empty strings goes through contant folding, the result
is something that contains no bytes. If this array is passed to the intrinsic
function RESHAPE(), we were not handling things correctly. I fixed this by
checking for an empty destination when calling the function CopyFrom() on an
array of strings.

I also added a test with a couple of different examples that trigger the
problem.

Diff Detail

Event Timeline

PeteSteinfeld created this revision.Jul 22 2020, 11:35 AM
Herald added a project: Restricted Project. · View Herald Transcript
PeteSteinfeld added a project: Restricted Project.Jul 22 2020, 11:36 AM
klausler added inline comments.Jul 22 2020, 11:45 AM
flang/lib/Evaluate/constant.cpp
257

This new 'if' statement might just hide bugs. Can copied be >= values_.size() and still be valid?

PeteSteinfeld marked an inline comment as done.Jul 22 2020, 12:06 PM
PeteSteinfeld added inline comments.
flang/lib/Evaluate/constant.cpp
257

Oops. This if is a left-over from an earlier attempt to fix this problem. It's unnecessary now, and I'll remove it.

Removed an unnecessary if condition.

klausler accepted this revision.Jul 22 2020, 12:14 PM
This revision is now accepted and ready to land.Jul 22 2020, 12:14 PM
This revision was automatically updated to reflect the committed changes.