This is an archive of the discontinued LLVM Phabricator instance.

[flang][runtime] ensure character compares to blank are unsigned
ClosedPublic

Authored by jeanPerier on Sep 12 2022, 6:41 AM.

Details

Summary

CompareToBlankPadding was doing signed compare on architecture where
char is signed. This caused 'abc'//char(128) > 'abc' to evaluate
to false at runtime instead of true.

Diff Detail

Event Timeline

jeanPerier created this revision.Sep 12 2022, 6:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 12 2022, 6:41 AM
Herald added a subscriber: jdoerfert. · View Herald Transcript
jeanPerier requested review of this revision.Sep 12 2022, 6:41 AM
PeteSteinfeld accepted this revision.Sep 12 2022, 8:53 AM

Other than my comment about repeated code, all build, tests, and looks good.

flang/runtime/character.cpp
25–30

You could avoid some repeated code here:

UNSIGNED_CHAR ux = *reinterpret_cast<const UNSIGNED_CHAR *>(x);
if (ux < blank) {
  return -1;
}
if (ux > blank) {
This revision is now accepted and ready to land.Sep 12 2022, 8:53 AM