Skip to content

Commit

Permalink
[flang][runtime] Fix return value for MINVAL/MAXVAL for CHARACTER(kin…
Browse files Browse the repository at this point in the history
…d > 1)

CharacterExtremumAccumulator::GetResult() needs to use byte counts, not wide
character counts, when calling memcpy() & memset().

Differential Revision: https://reviews.llvm.org/D132156
  • Loading branch information
klausler committed Aug 18, 2022
1 parent 92afe80 commit cd117fa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions flang/runtime/extrema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,16 @@ template <int KIND, bool IS_MAXVAL> class CharacterExtremumAccumulator {
void Reinitialize() { extremum_ = nullptr; }
template <typename A> void GetResult(A *p, int /*zeroBasedDim*/ = -1) const {
static_assert(std::is_same_v<A, Type>);
std::size_t byteSize{array_.ElementBytes()};
if (extremum_) {
std::memcpy(p, extremum_, charLen_);
std::memcpy(p, extremum_, byteSize);
} else {
// empty array: result is all zero-valued characters
std::memset(p, 0, charLen_);
// empty array
if constexpr (KIND == 1) { // ASCII
*p = IS_MAXVAL ? 0 : 127; // 127 required by standard
} else {
std::memset(p, IS_MAXVAL ? 0 : 255, byteSize);
}
}
}
bool Accumulate(const Type *x) {
Expand Down

0 comments on commit cd117fa

Please sign in to comment.