diff --git a/flang/runtime/character.cpp b/flang/runtime/character.cpp --- a/flang/runtime/character.cpp +++ b/flang/runtime/character.cpp @@ -20,11 +20,13 @@ template inline int CompareToBlankPadding(const CHAR *x, std::size_t chars) { + using UNSIGNED_CHAR = std::make_unsigned_t; + const auto blank{static_cast(' ')}; for (; chars-- > 0; ++x) { - if (*x < ' ') { + if (*reinterpret_cast(x) < blank) { return -1; } - if (*x > ' ') { + if (*reinterpret_cast(x) > blank) { return 1; } } diff --git a/flang/unittests/Runtime/CharacterTest.cpp b/flang/unittests/Runtime/CharacterTest.cpp --- a/flang/unittests/Runtime/CharacterTest.cpp +++ b/flang/unittests/Runtime/CharacterTest.cpp @@ -171,6 +171,8 @@ std::make_tuple("abc", "def", 3, 3, -1), std::make_tuple("ab ", "abc", 3, 2, 0), std::make_tuple("abc", "abc", 2, 3, -1), + std::make_tuple("ab\xff", "ab ", 3, 2, 1), + std::make_tuple("ab ", "ab\xff", 2, 3, -1), }, { std::make_tuple(u"abc", u"abc", 3, 3, 0),