Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Klausler <pklausler@nvidia.com>2022-08-18 20:31:13 +0300
committerPeter Klausler <pklausler@nvidia.com>2022-08-19 00:26:26 +0300
commitcd117fa04b620c9ce4d63ca4d475aa3ec5a1a122 (patch)
tree7a8f9cd5e13f4373eb66f432c9197b8a596ce8c2 /flang/runtime
parent92afe8021352ef33a282046d404a1f14140f96f9 (diff)
[flang][runtime] Fix return value for MINVAL/MAXVAL for CHARACTER(kind > 1)
CharacterExtremumAccumulator::GetResult() needs to use byte counts, not wide character counts, when calling memcpy() & memset(). Differential Revision: https://reviews.llvm.org/D132156
Diffstat (limited to 'flang/runtime')
-rw-r--r--flang/runtime/extrema.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/flang/runtime/extrema.cpp b/flang/runtime/extrema.cpp
index 709a032911d4..8290ad3c56c4 100644
--- a/flang/runtime/extrema.cpp
+++ b/flang/runtime/extrema.cpp
@@ -419,11 +419,16 @@ public:
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) {