Skip to content

Commit d7afa4c

Browse files
Enable -Wdouble-promotion by default and fix related warnings (#4603)
- fix float to double implicit conversion - add isnanf and signbitf macros, map them to existing double version when float versions are absent - enable -Wdouble-promotion by default - define isnan as macro for platform use core\sahred\platform\common\math.c
1 parent 0d3b5ca commit d7afa4c

File tree

14 files changed

+84
-34
lines changed

14 files changed

+84
-34
lines changed

build-scripts/warnings.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ else ()
2020
$<$<COMPILE_LANGUAGE:C>:-Wincompatible-pointer-types>
2121
$<$<COMPILE_LANGUAGE:C>:-Wimplicit-function-declaration>
2222
)
23+
add_compile_options (
24+
-Wdouble-promotion
25+
)
2326
# waivers
2427
add_compile_options (
2528
-Wno-unused

core/iwasm/aot/aot_intrinsic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ float64
152152
aot_intrinsic_fmin_f64(float64 a, float64 b)
153153
{
154154
if (isnan(a) || isnan(b))
155-
return NAN;
155+
return (float64)NAN;
156156
else if (a == 0 && a == b)
157157
return signbit(a) ? a : b;
158158
else
@@ -174,7 +174,7 @@ float64
174174
aot_intrinsic_fmax_f64(float64 a, float64 b)
175175
{
176176
if (isnan(a) || isnan(b))
177-
return NAN;
177+
return (float64)NAN;
178178
else if (a == 0 && a == b)
179179
return signbit(a) ? b : a;
180180
else

core/iwasm/aot/aot_runtime.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4607,16 +4607,16 @@ aot_dump_perf_profiling(const AOTModuleInstance *module_inst)
46074607
os_printf(
46084608
" func %s, execution time: %.3f ms, execution count: %" PRIu32
46094609
" times, children execution time: %.3f ms\n",
4610-
func_name, perf_prof->total_exec_time / 1000.0f,
4610+
func_name, perf_prof->total_exec_time / 1000.0,
46114611
perf_prof->total_exec_cnt,
4612-
perf_prof->children_exec_time / 1000.0f);
4612+
perf_prof->children_exec_time / 1000.0);
46134613
else
46144614
os_printf(" func %" PRIu32
46154615
", execution time: %.3f ms, execution count: %" PRIu32
46164616
" times, children execution time: %.3f ms\n",
4617-
i, perf_prof->total_exec_time / 1000.0f,
4617+
i, perf_prof->total_exec_time / 1000.0,
46184618
perf_prof->total_exec_cnt,
4619-
perf_prof->children_exec_time / 1000.0f);
4619+
perf_prof->children_exec_time / 1000.0);
46204620
}
46214621
}
46224622

@@ -4632,7 +4632,7 @@ aot_summarize_wasm_execute_time(const AOTModuleInstance *inst)
46324632
AOTFuncPerfProfInfo *perf_prof =
46334633
(AOTFuncPerfProfInfo *)inst->func_perf_profilings + i;
46344634
ret += (perf_prof->total_exec_time - perf_prof->children_exec_time)
4635-
/ 1000.0f;
4635+
/ 1000.0;
46364636
}
46374637

46384638
return ret;
@@ -4651,7 +4651,7 @@ aot_get_wasm_func_exec_time(const AOTModuleInstance *inst,
46514651
AOTFuncPerfProfInfo *perf_prof =
46524652
(AOTFuncPerfProfInfo *)inst->func_perf_profilings + i;
46534653
return (perf_prof->total_exec_time - perf_prof->children_exec_time)
4654-
/ 1000.0f;
4654+
/ 1000.0;
46554655
}
46564656
}
46574657

core/iwasm/compilation/aot_compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ set_local_gc_ref(AOTCompFrame *frame, int n, LLVMValueRef value, uint8 ref_type)
668668

669669
#define I32_CONST(v) LLVMConstInt(I32_TYPE, v, true)
670670
#define I64_CONST(v) LLVMConstInt(I64_TYPE, v, true)
671-
#define F32_CONST(v) LLVMConstReal(F32_TYPE, v)
671+
#define F32_CONST(v) LLVMConstReal(F32_TYPE, (double)(v))
672672
#define F64_CONST(v) LLVMConstReal(F64_TYPE, v)
673673
#define I8_CONST(v) LLVMConstInt(INT8_TYPE, v, true)
674674

core/iwasm/compilation/simd/simd_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ simd_build_splat_const_float_vector(const AOTCompContext *comp_ctx,
137137
return NULL;
138138
}
139139

140-
if (!(element = LLVMConstReal(element_type, element_value))) {
140+
if (!(element = LLVMConstReal(element_type, (double)element_value))) {
141141
HANDLE_FAILURE("LLVMConstReal");
142142
goto fail;
143143
}

core/iwasm/fast-jit/fe/jit_emit_numberic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ static float64
15641564
f64_min(float64 a, float64 b)
15651565
{
15661566
if (isnan(a) || isnan(b))
1567-
return NAN;
1567+
return (float64)NAN;
15681568
else if (a == 0 && a == b)
15691569
return signbit(a) ? a : b;
15701570
else
@@ -1575,7 +1575,7 @@ static float64
15751575
f64_max(float64 a, float64 b)
15761576
{
15771577
if (isnan(a) || isnan(b))
1578-
return NAN;
1578+
return (float64)NAN;
15791579
else if (a == 0 && a == b)
15801580
return signbit(a) ? b : a;
15811581
else

core/iwasm/fast-jit/jit_dump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jit_dump_reg(JitCompContext *cc, JitReg reg)
4040

4141
case JIT_REG_KIND_F32:
4242
if (jit_reg_is_const(reg))
43-
os_printf("%f", jit_cc_get_const_F32(cc, reg));
43+
os_printf("%f", (double)jit_cc_get_const_F32(cc, reg));
4444
else
4545
os_printf("f%d", no);
4646
break;

core/iwasm/interpreter/wasm_interp_classic.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static inline float64
223223
f64_min(float64 a, float64 b)
224224
{
225225
if (isnan(a) || isnan(b))
226-
return NAN;
226+
return (float64)NAN;
227227
else if (a == 0 && a == b)
228228
return signbit(a) ? a : b;
229229
else
@@ -234,7 +234,7 @@ static inline float64
234234
f64_max(float64 a, float64 b)
235235
{
236236
if (isnan(a) || isnan(b))
237-
return NAN;
237+
return (float64)NAN;
238238
else if (a == 0 && a == b)
239239
return signbit(a) ? b : a;
240240
else
@@ -1685,7 +1685,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
16851685
goto got_exception;
16861686
}
16871687

1688-
HANDLE_OP(WASM_OP_NOP) { HANDLE_OP_END(); }
1688+
HANDLE_OP(WASM_OP_NOP)
1689+
{
1690+
HANDLE_OP_END();
1691+
}
16891692

16901693
#if WASM_ENABLE_EXCE_HANDLING != 0
16911694
HANDLE_OP(WASM_OP_RETHROW)
@@ -5622,7 +5625,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
56225625
HANDLE_OP(WASM_OP_I32_REINTERPRET_F32)
56235626
HANDLE_OP(WASM_OP_I64_REINTERPRET_F64)
56245627
HANDLE_OP(WASM_OP_F32_REINTERPRET_I32)
5625-
HANDLE_OP(WASM_OP_F64_REINTERPRET_I64) { HANDLE_OP_END(); }
5628+
HANDLE_OP(WASM_OP_F64_REINTERPRET_I64)
5629+
{
5630+
HANDLE_OP_END();
5631+
}
56265632

56275633
HANDLE_OP(WASM_OP_I32_EXTEND8_S)
56285634
{
@@ -5697,7 +5703,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
56975703
true);
56985704
break;
56995705
case WASM_OP_I64_TRUNC_SAT_U_F64:
5700-
DEF_OP_TRUNC_SAT_F64(-1.0f, 18446744073709551616.0,
5706+
DEF_OP_TRUNC_SAT_F64(-1.0, 18446744073709551616.0,
57015707
false, false);
57025708
break;
57035709
#if WASM_ENABLE_BULK_MEMORY != 0

core/iwasm/interpreter/wasm_interp_fast.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static inline float64
164164
f64_min(float64 a, float64 b)
165165
{
166166
if (isnan(a) || isnan(b))
167-
return NAN;
167+
return (float64)NAN;
168168
else if (a == 0 && a == b)
169169
return signbit(a) ? a : b;
170170
else
@@ -175,7 +175,7 @@ static inline float64
175175
f64_max(float64 a, float64 b)
176176
{
177177
if (isnan(a) || isnan(b))
178-
return NAN;
178+
return (float64)NAN;
179179
else if (a == 0 && a == b)
180180
return signbit(a) ? b : a;
181181
else

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3744,16 +3744,16 @@ wasm_dump_perf_profiling(const WASMModuleInstance *module_inst)
37443744
os_printf(
37453745
" func %s, execution time: %.3f ms, execution count: %" PRIu32
37463746
" times, children execution time: %.3f ms\n",
3747-
func_name, func_inst->total_exec_time / 1000.0f,
3747+
func_name, func_inst->total_exec_time / 1000.0,
37483748
func_inst->total_exec_cnt,
3749-
func_inst->children_exec_time / 1000.0f);
3749+
func_inst->children_exec_time / 1000.0);
37503750
else
37513751
os_printf(" func %" PRIu32
37523752
", execution time: %.3f ms, execution count: %" PRIu32
37533753
" times, children execution time: %.3f ms\n",
3754-
i, func_inst->total_exec_time / 1000.0f,
3754+
i, func_inst->total_exec_time / 1000.0,
37553755
func_inst->total_exec_cnt,
3756-
func_inst->children_exec_time / 1000.0f);
3756+
func_inst->children_exec_time / 1000.0);
37573757
}
37583758
}
37593759

@@ -3765,7 +3765,7 @@ wasm_summarize_wasm_execute_time(const WASMModuleInstance *inst)
37653765
unsigned i;
37663766
for (i = 0; i < inst->e->function_count; i++) {
37673767
WASMFunctionInstance *func = inst->e->functions + i;
3768-
ret += (func->total_exec_time - func->children_exec_time) / 1000.0f;
3768+
ret += (func->total_exec_time - func->children_exec_time) / 1000.0;
37693769
}
37703770

37713771
return ret;
@@ -3780,7 +3780,7 @@ wasm_get_wasm_func_exec_time(const WASMModuleInstance *inst,
37803780
char *name_in_wasm = get_func_name_from_index(inst, i);
37813781
if (name_in_wasm && strcmp(name_in_wasm, func_name) == 0) {
37823782
WASMFunctionInstance *func = inst->e->functions + i;
3783-
return (func->total_exec_time - func->children_exec_time) / 1000.0f;
3783+
return (func->total_exec_time - func->children_exec_time) / 1000.0;
37843784
}
37853785
}
37863786

0 commit comments

Comments
 (0)