Skip to content

Commit 4f3f5a7

Browse files
committed
Machine: resolve some printf format warnings for build on 32-bit systems.
The emulated CPU registers are declared as 64-bit in QtRVSim but there is used format "lx" in many places. But long is only 32-bit on x86 MAC OS 32-bit build. Signed-off-by: Pavel Pisa <[email protected]>
1 parent 4193079 commit 4f3f5a7

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

src/machine/core.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "execute/alu.h"
55
#include "utils.h"
66

7+
#include <cinttypes>
8+
79
LOG_CATEGORY("machine.core");
810

911
using namespace machine;
@@ -626,8 +628,8 @@ bool StopExceptionHandler::handle_exception(
626628
Address mem_ref_addr) {
627629
Q_UNUSED(core)
628630
DEBUG(
629-
"Exception cause %d instruction PC 0x%08lx next PC 0x%08lx jump branch PC 0x%08lx "
630-
"registers PC 0x%08lx mem ref 0x%08lx",
631+
"Exception cause %d instruction PC 0x%08" PRIx64 " next PC 0x%08" PRIx64 " jump branch PC 0x%08" PRIx64
632+
"registers PC 0x%08" PRIx64 " mem ref 0x%08" PRIx64,
631633
excause, inst_addr.get_raw(), next_addr.get_raw(), jump_branch_pc.get_raw(),
632634
regs->read_pc().get_raw(), mem_ref_addr.get_raw());
633635
return true;

src/machine/memory/backend/memory.test.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "machine/memory/memory_utils.h"
88
#include "tests/utils/integer_decomposition.h"
99

10+
#include <cinttypes>
11+
1012
using namespace machine;
1113

1214
// Default memory testing data. Some tests may use other values, where it
@@ -85,7 +87,7 @@ constexpr void prepare_data(
8587
auto result_value
8688
= (endian == BIG) ? (value << (stride * 8)) : (value >> (stride * 8));
8789
QTest::addRow(
88-
"endian=%s, address=0x%lx, stride=%ld, value=0x%lx", to_string(endian),
90+
"endian=%s, address=0x%lx, stride=%ld, value=0x%" PRIx64, to_string(endian),
8991
address, stride, value)
9092
<< endian << address << stride << IntegerDecomposition(value, endian)
9193
<< IntegerDecomposition(result_value, endian);
@@ -328,4 +330,4 @@ void TestMemory::memory_read_ctl() {
328330
}
329331
}
330332

331-
QTEST_APPLESS_MAIN(TestMemory)
333+
QTEST_APPLESS_MAIN(TestMemory)

src/machine/memory/cache/cache.test.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include <tests/utils/integer_decomposition.h>
1111

12+
#include <cinttypes>
13+
1214
using namespace machine;
1315
using std::array;
1416
using std::pair;
@@ -158,8 +160,8 @@ void TestCache::cache_correctness_data() {
158160
auto result_value
159161
= (endian == BIG) ? (value << (stride * 8)) : (value >> (stride * 8));
160162
QTest::addRow(
161-
"endian=%s, address=0x%lx, stride=%ld, "
162-
"value=0x%lx, cache_config={ %d, "
163+
"endian=%s, address=0x%" PRIx64 ", stride=%ld, "
164+
"value=0x%" PRIx64 ", cache_config={ %d, "
163165
"r=%d, wr=%d, s=%d, b=%d, a=%d }",
164166
to_string(endian), address, stride, value, cache_config.enabled(),
165167
cache_config.replacement_policy(), cache_config.write_policy(),

src/os_emulation/ossyscall.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,12 @@ bool OsSyscallExceptionHandler::handle_exception(
570570

571571
#if 1
572572
printf(
573-
"Exception cause %d instruction PC 0x%08lx next PC 0x%08lx jump branch "
574-
"PC 0x%08lx "
575-
"registers PC 0x%08lx mem ref 0x%08lx\n",
576-
excause, (unsigned long)inst_addr.get_raw(), (unsigned long)next_addr.get_raw(),
577-
(unsigned long)jump_branch_pc.get_raw(), (unsigned long)regs->read_pc().get_raw(),
578-
(unsigned long)mem_ref_addr.get_raw());
573+
"Exception cause %d instruction PC 0x%08" PRIx64 " next PC 0x%08" PRIx64 " jump branch "
574+
"PC 0x%08" PRIx64
575+
"registers PC 0x%08" PRIx64 " mem ref 0x%08" PRIx64 "\n",
576+
excause, inst_addr.get_raw(), next_addr.get_raw(),
577+
jump_branch_pc.get_raw(), regs->read_pc().get_raw(),
578+
mem_ref_addr.get_raw());
579579
#else
580580
(void)excause;
581581
(void)inst_addr;
@@ -607,7 +607,7 @@ bool OsSyscallExceptionHandler::handle_exception(
607607

608608
#if 1
609609
printf(
610-
"Syscall %s number %ld/0x%lx a1=%" PRIu64 " a2=%" PRIu64 " a3=%" PRIu64 " a4=%" PRIu64 "\n",
610+
"Syscall %s number %" PRId64 "/0x%" PRIx64 " a1=%" PRIu64 " a2=%" PRIu64 " a3=%" PRIu64 " a4=%" PRIu64 "\n",
611611
sdesc->name, syscall_num, syscall_num, a1.as_u64(), a2.as_u64(), a3.as_u64(), a4.as_u64());
612612

613613
#endif
@@ -787,7 +787,8 @@ int OsSyscallExceptionHandler::syscall_default_handler(
787787
const rv_syscall_desc_t *sdesc = &rv_syscall_args[syscall_num];
788788
#if 1
789789
printf(
790-
"Unimplemented syscall %s number %ld/0x%lx a1 %ld a2 %ld a3 %ld a4 %ld\n", sdesc->name,
790+
"Unimplemented syscall %s number %" PRId64 "/0x%" PRIx64 " a1 %" PRId64
791+
" a2 %" PRId64 " a3 %" PRId64 " a4 %" PRId64 "\n", sdesc->name,
791792
syscall_num, syscall_num, a1, a2, a3, a4);
792793

793794
#endif
@@ -1052,7 +1053,7 @@ int OsSyscallExceptionHandler::do_sys_openat(
10521053

10531054
result = 0;
10541055
if (int64_t(a1) != TARGET_AT_FDCWD) {
1055-
printf("Unimplemented openat argument a1 %ld", a1);
1056+
printf("Unimplemented openat argument a1 %" PRId64, a1);
10561057
if (unknown_syscall_stop) { emit core->stop_on_exception_reached(); }
10571058
return TARGET_ENOSYS;
10581059
}

0 commit comments

Comments
 (0)