|
 |
006bc1 |
From f2779155495aee6583abaff4700a7acda80864ef Mon Sep 17 00:00:00 2001
|
|
 |
006bc1 |
From: Siddhesh Poyarekar <siddhesh@sourceware.org>
|
|
 |
006bc1 |
Date: Thu, 28 Mar 2019 10:50:23 +0530
|
|
 |
006bc1 |
Subject: [PATCH 72/72] Better behaviour for float to uint32_t conversions
|
|
 |
006bc1 |
|
|
 |
006bc1 |
This is the uint32_t part of the float to unsigned int conversions for
|
|
 |
006bc1 |
the interpreter. The cast ends up working correctly for x86 but not
|
|
 |
006bc1 |
for aarch64 since fcvtzu sets the result to zero on negative inputs.
|
|
 |
006bc1 |
Work slightly harder to make sure that negative number inputs behave
|
|
 |
006bc1 |
like x86.
|
|
 |
006bc1 |
|
|
 |
006bc1 |
This fixes the interpreter but not the JIT compiler, which errors out
|
|
 |
006bc1 |
during the narrowing pass.
|
|
 |
006bc1 |
---
|
|
 |
006bc1 |
src/lj_cconv.c | 8 +++++++-
|
|
 |
006bc1 |
1 file changed, 7 insertions(+), 1 deletion(-)
|
|
 |
006bc1 |
|
|
 |
006bc1 |
diff --git a/src/lj_cconv.c b/src/lj_cconv.c
|
|
 |
006bc1 |
index 13b8230..bf8f8e8 100644
|
|
 |
006bc1 |
--- a/src/lj_cconv.c
|
|
 |
006bc1 |
+++ b/src/lj_cconv.c
|
|
 |
006bc1 |
@@ -196,7 +196,13 @@ void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,
|
|
 |
006bc1 |
else if (dsize == 2) *(int16_t *)dp = (int16_t)i;
|
|
 |
006bc1 |
else *(int8_t *)dp = (int8_t)i;
|
|
 |
006bc1 |
} else if (dsize == 4) {
|
|
 |
006bc1 |
- *(uint32_t *)dp = (uint32_t)n;
|
|
 |
006bc1 |
+ /* Undefined behaviour. This is deliberately not a full check because we
|
|
 |
006bc1 |
+ * don't want to slow down compliant code. */
|
|
 |
006bc1 |
+ lua_assert(n >= -2147483649.0);
|
|
 |
006bc1 |
+ if (n > -1.0)
|
|
 |
006bc1 |
+ *(uint32_t *)dp = (uint32_t)n;
|
|
 |
006bc1 |
+ else
|
|
 |
006bc1 |
+ *(uint32_t *)dp = (uint32_t)(int32_t)n;
|
|
 |
006bc1 |
} else if (dsize == 8) {
|
|
 |
006bc1 |
if (!(dinfo & CTF_UNSIGNED))
|
|
 |
006bc1 |
*(int64_t *)dp = (int64_t)n;
|
|
 |
006bc1 |
--
|
|
 |
006bc1 |
2.20.1
|
|
 |
006bc1 |
|