[flang-commits] [PATCH] D132156: [flang][runtime] Fix return value for MINVAL/MAXVAL for CHARACTER(kind > 1)
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Thu Aug 18 11:18:04 PDT 2022
klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
CharacterExtremumAccumulator::GetResult() needs to use byte counts, not wide
character counts, when calling memcpy() & memset().
https://reviews.llvm.org/D132156
Files:
flang/runtime/extrema.cpp
Index: flang/runtime/extrema.cpp
===================================================================
--- flang/runtime/extrema.cpp
+++ flang/runtime/extrema.cpp
@@ -419,11 +419,16 @@
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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132156.453720.patch
Type: text/x-patch
Size: 884 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220818/114e61e9/attachment.bin>
More information about the flang-commits
mailing list