This is an archive of the discontinued LLVM Phabricator instance.

[flang] prevent undefined behavior in character MAXLOC folding
ClosedPublic

Authored by jeanPerier on Mar 28 2022, 8:54 AM.

Details

Summary

When folding MAXLOC/MINLOC, the current element being compared was moved twice
in row in case it became the new extremum. With intrinsic types, it
made no difference (std::move is a no-op for them), but for characters
where the string storage is actually moved, it caused the new extremum to
be set to the empty string, leading to wrong results.

Note: I could have left the first std::move relating to logical Findloc, but it
brings nothing and makes the code less auditable, so I also removed it.

Diff Detail

Event Timeline

jeanPerier created this revision.Mar 28 2022, 8:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2022, 8:54 AM
Herald added a subscriber: jdoerfert. · View Herald Transcript
jeanPerier requested review of this revision.Mar 28 2022, 8:54 AM

CHARACTER is an intrinsic type.

klausler accepted this revision.Mar 28 2022, 9:42 AM
This revision is now accepted and ready to land.Mar 28 2022, 9:42 AM
This revision was landed with ongoing or failed builds.Mar 29 2022, 12:34 AM
This revision was automatically updated to reflect the committed changes.

CHARACTER is an intrinsic type.

Thanks, I updated the commit message to state "numeric and logical types" instead.