Skip to content

Commit 768b91e

Browse files
authored
Merge pull request #26137 from linux-on-ibm-z/metadata-print-fix
Runtime: print type layout values correctly on big-endian systems
2 parents 354eb4d + 2f8b5ac commit 768b91e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

stdlib/public/runtime/Metadata.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "llvm/Support/PointerLikeTypeTraits.h"
3232
#include <algorithm>
3333
#include <cctype>
34+
#include <cinttypes>
3435
#include <condition_variable>
3536
#include <new>
3637
#include <unordered_set>
@@ -3897,10 +3898,15 @@ void _swift_debug_verifyTypeLayoutAttribute(Metadata *type,
38973898
size_t size,
38983899
const char *description) {
38993900
auto presentValue = [&](const void *value) {
3900-
if (size < sizeof(long long)) {
3901-
long long intValue = 0;
3902-
memcpy(&intValue, value, size);
3903-
fprintf(stderr, "%lld (%#llx)\n ", intValue, intValue);
3901+
if (size <= sizeof(uint64_t)) {
3902+
uint64_t intValue = 0;
3903+
auto ptr = reinterpret_cast<uint8_t *>(&intValue);
3904+
#if defined(__BIG_ENDIAN__)
3905+
ptr += sizeof(uint64_t) - size;
3906+
#endif
3907+
memcpy(ptr, value, size);
3908+
fprintf(stderr, "%" PRIu64 " (%#" PRIx64 ")\n", intValue, intValue);
3909+
fprintf(stderr, " ");
39043910
}
39053911
auto bytes = reinterpret_cast<const uint8_t *>(value);
39063912
for (unsigned i = 0; i < size; ++i) {

0 commit comments

Comments
 (0)