From 799471d16f8255285a19c9ce8d7ca5675c6ce390 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Mon, 9 Aug 2021 02:53:40 +0430 Subject: [PATCH] Meta: Don't roundtrip floats for i64/i32 hex literals in wasm tests --- Meta/generate-libwasm-spec-test.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Meta/generate-libwasm-spec-test.py b/Meta/generate-libwasm-spec-test.py index 4f894dfe06..0b5b1b83a2 100644 --- a/Meta/generate-libwasm-spec-test.py +++ b/Meta/generate-libwasm-spec-test.py @@ -238,6 +238,16 @@ def genarg(spec): def gen(): x = spec['value'] + if spec['type'] in ('i32', 'i64'): + if x.startswith('0x'): + if spec['type'] == 'i32': + # cast back to i32 to get the correct sign + return str(struct.unpack('>i', struct.pack('>Q', int(x, 16))[4:])[0]) + + # cast back to i64 to get the correct sign + return str(struct.unpack('>q', struct.pack('>Q', int(x, 16)))[0]) + return x + if x == 'nan': return 'NaN' if x == '-nan': @@ -274,9 +284,6 @@ def genarg(spec): if x.startswith('-nan'): return '-NaN' return x - if spec['type'] == 'i32': - # cast back to i32 to get the correct sign - return str(struct.unpack('>i', struct.pack('>q', int(x))[4:])[0]) return str(x)