Cleanup output format warnings (#904)

Use `PRIxxx` related macros to format the output strings so as to clear
compile warnings, e.g. PRIu32, PRId32, PRIX32, PRIX64 and so on.
And add the related macro definitions in platform_common.h if they
are not defined, as some compilers might not support them.
This commit is contained in:
Huang Qi 2021-12-20 15:51:36 +08:00 committed by GitHub
parent a41c1ad85c
commit 4cc4625a2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 74 additions and 26 deletions

View File

@ -357,7 +357,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
if (error_buf != NULL)
snprintf(error_buf, error_buf_size,
"Load relocation section failed: "
"invalid relocation type %d.",
"invalid relocation type %" PRIu32 ".",
reloc_type);
return false;
}

View File

@ -417,7 +417,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
char *endptr = NULL;
bh_assert(argv[i] != NULL);
if (argv[i][0] == '\0') {
snprintf(buf, sizeof(buf), "invalid input argument %d", i);
snprintf(buf, sizeof(buf), "invalid input argument %" PRId32, i);
wasm_runtime_set_exception(module_inst, buf);
goto fail;
}
@ -554,8 +554,8 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
break;
}
if (endptr && *endptr != '\0' && *endptr != '_') {
snprintf(buf, sizeof(buf), "invalid input argument %d: %s", i,
argv[i]);
snprintf(buf, sizeof(buf), "invalid input argument %" PRId32 ": %s",
i, argv[i]);
wasm_runtime_set_exception(module_inst, buf);
goto fail;
}
@ -573,7 +573,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
switch (type->types[type->param_count + j]) {
case VALUE_TYPE_I32:
{
os_printf("0x%x:i32", argv1[k]);
os_printf("0x%" PRIx32 ":i32", argv1[k]);
k++;
break;
}

View File

@ -2490,12 +2490,12 @@ aot_load_const_from_table(AOTCompContext *comp_ctx, LLVMValueRef base,
switch (value_type) {
case VALUE_TYPE_F32:
/* Store the raw int bits of f32 const as a hex string */
snprintf(buf, sizeof(buf), "f32#%08X", value->i32);
snprintf(buf, sizeof(buf), "f32#%08" PRIX32, value->i32);
const_ptr_type = F32_PTR_TYPE;
break;
case VALUE_TYPE_F64:
/* Store the raw int bits of f64 const as a hex string */
snprintf(buf, sizeof(buf), "f64#%016" PRIx64, value->i64);
snprintf(buf, sizeof(buf), "f64#%016" PRIX64, value->i64);
const_ptr_type = F64_PTR_TYPE;
break;
default:

View File

@ -3733,8 +3733,9 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
if (argc < function->param_cell_num) {
char buf[128];
snprintf(buf, sizeof(buf),
"invalid argument count %u, must be no smaller than %u", argc,
function->param_cell_num);
"invalid argument count %" PRIu32
", must be no smaller than %" PRIu32,
argc, (uint32)function->param_cell_num);
wasm_set_exception(module_inst, buf);
return;
}

View File

@ -769,7 +769,7 @@ exit_wrapper(wasm_exec_env_t exec_env, int32 status)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
char buf[32];
snprintf(buf, sizeof(buf), "env.exit(%i)", status);
snprintf(buf, sizeof(buf), "env.exit(%" PRId32 ")", status);
wasm_runtime_set_exception(module_inst, buf);
}
@ -1012,7 +1012,7 @@ abort_wrapper(wasm_exec_env_t exec_env, int32 code)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
char buf[32];
snprintf(buf, sizeof(buf), "env.abort(%i)", code);
snprintf(buf, sizeof(buf), "env.abort(%" PRId32 ")", code);
wasm_runtime_set_exception(module_inst, buf);
}
@ -1021,7 +1021,7 @@ abortStackOverflow_wrapper(wasm_exec_env_t exec_env, int32 code)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
char buf[32];
snprintf(buf, sizeof(buf), "env.abortStackOverflow(%i)", code);
snprintf(buf, sizeof(buf), "env.abortStackOverflow(%" PRId32 ")", code);
wasm_runtime_set_exception(module_inst, buf);
}
@ -1030,7 +1030,7 @@ nullFunc_X_wrapper(wasm_exec_env_t exec_env, int32 code)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
char buf[32];
snprintf(buf, sizeof(buf), "env.nullFunc_X(%i)", code);
snprintf(buf, sizeof(buf), "env.nullFunc_X(%" PRId32 ")", code);
wasm_runtime_set_exception(module_inst, buf);
}

View File

@ -722,7 +722,8 @@ void
gc_dump_heap_stats(gc_heap_t *heap)
{
os_printf("heap: %p, heap start: %p\n", heap, heap->base_addr);
os_printf("total free: %u, current: %u, highmark: %u\n",
os_printf("total free: %" PRIu32 ", current: %" PRIu32
", highmark: %" PRIu32 "\n",
heap->total_free_size, heap->current_size, heap->highmark_size);
os_printf("g_total_malloc=%lu, g_total_free=%lu, occupied=%lu\n",
g_total_malloc, g_total_free, g_total_malloc - g_total_free);
@ -765,9 +766,10 @@ gci_dump(gc_heap_t *heap)
return;
}
os_printf("#%d %08x %x %x %d %c %d\n", i,
(int32)((char *)cur - (char *)heap->base_addr), ut, p, mark,
inuse, (int32)hmu_obj_size(size));
os_printf("#%d %08" PRIx32 " %" PRIx32 " %d %d"
" %c %" PRId32 "\n",
i, (int32)((char *)cur - (char *)heap->base_addr), (int32)ut,
p, mark, inuse, (int32)hmu_obj_size(size));
#if BH_ENABLE_GC_VERIFY != 0
if (inuse == 'V') {
gc_object_prefix_t *prefix = (gc_object_prefix_t *)(cur + 1);

View File

@ -59,8 +59,8 @@ gc_init_with_pool(char *buf, gc_size_t buf_size)
gc_size_t heap_max_size;
if (buf_size < APP_HEAP_SIZE_MIN) {
os_printf("[GC_ERROR]heap init buf size (%u) < %u\n", buf_size,
APP_HEAP_SIZE_MIN);
os_printf("[GC_ERROR]heap init buf size (%" PRIu32 ") < %" PRIu32 "\n",
buf_size, (uint32)APP_HEAP_SIZE_MIN);
return NULL;
}
@ -93,7 +93,7 @@ gc_init_with_struct_and_pool(char *struct_buf, gc_size_t struct_buf_size,
}
if (struct_buf_size < sizeof(gc_handle_t)) {
os_printf("[GC_ERROR]heap init struct buf size (%u) < %zu\n",
os_printf("[GC_ERROR]heap init struct buf size (%" PRIu32 ") < %zu\n",
struct_buf_size, sizeof(gc_handle_t));
return NULL;
}
@ -104,8 +104,8 @@ gc_init_with_struct_and_pool(char *struct_buf, gc_size_t struct_buf_size,
}
if (pool_buf_size < APP_HEAP_SIZE_MIN) {
os_printf("[GC_ERROR]heap init buf size (%u) < %u\n", pool_buf_size,
APP_HEAP_SIZE_MIN);
os_printf("[GC_ERROR]heap init buf size (%" PRIu32 ") < %u\n",
pool_buf_size, APP_HEAP_SIZE_MIN);
return NULL;
}

View File

@ -104,6 +104,48 @@ typedef int64_t int64;
typedef void *(*thread_start_routine_t)(void *);
#ifndef PRId32
#define PRId32 "d"
#endif
#ifndef PRIi32
#define PRIi32 "i"
#endif
#ifndef PRIu32
#define PRIu32 "u"
#endif
#ifndef PRIx32
#define PRIx32 "x"
#endif
#ifndef PRIX32
#define PRIX32 "X"
#endif
#ifndef __PRI64_PREFIX
#if UINTPTR_MAX == UINT64_MAX
#define __PRI64_PREFIX "l"
#define __PRIPTR_PREFIX "l"
#else
#define __PRI64_PREFIX "ll"
#define __PRIPTR_PREFIX
#endif
#endif
#ifndef PRId64
#define PRId64 __PRI64_PREFIX "d"
#endif
#ifndef PRIu64
#define PRIu64 __PRI64_PREFIX "u"
#endif
#ifndef PRIx64
#define PRIx64 __PRI64_PREFIX "x"
#endif
#ifndef PRIX64
#define PRIX64 __PRI64_PREFIX "X"
#endif
#ifndef PRIXPTR
#define PRIXPTR __PRIPTR_PREFIX "X"
#endif
#ifdef __cplusplus
}
#endif

View File

@ -39,9 +39,11 @@ bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...)
s = t % 60;
mills = (uint32)(usec % 1000);
snprintf(buf, sizeof(buf), "%02u:%02u:%02u:%03u", h, m, s, mills);
snprintf(buf, sizeof(buf),
"%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ":%03" PRIu32, h, m, s,
mills);
os_printf("[%s - %X]: ", buf, (uint32)(uintptr_t)self);
os_printf("[%s - %" PRIXPTR "]: ", buf, (uintptr_t)self);
if (file)
os_printf("%s, line %d, ", file, line);
@ -71,8 +73,9 @@ bh_print_time(const char *prompt)
total_time_ms += curr_time_ms - last_time_ms;
os_printf("%-48s time of last stage: %u ms, total time: %u ms\n", prompt,
curr_time_ms - last_time_ms, total_time_ms);
os_printf("%-48s time of last stage: %" PRIu32 " ms, total time: %" PRIu32
" ms\n",
prompt, curr_time_ms - last_time_ms, total_time_ms);
last_time_ms = curr_time_ms;
}