This commit is contained in:
Sasha Szpakowski
2026-06-22 18:57:43 -03:00
parent c4192fe9ba
commit 774ba85a81
211 changed files with 1708 additions and 847 deletions
+6 -8
View File
@@ -1,6 +1,6 @@
/*
** C type conversions.
** Copyright (C) 2005-2025 Mike Pall. See Copyright Notice in luajit.h
** Copyright (C) 2005-2026 Mike Pall. See Copyright Notice in luajit.h
*/
#include "lj_obj.h"
@@ -197,18 +197,16 @@ void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,
else goto err_conv; /* NYI: long double. */
/* Then convert double to integer. */
/* The conversion must exactly match the semantics of JIT-compiled code! */
if (dsize < 4 || (dsize == 4 && !(dinfo & CTF_UNSIGNED))) {
int32_t i = (int32_t)n;
if (dsize < 8) {
int64_t i = lj_num2i64(n); /* Always convert via int64_t. */
if (dsize == 4) *(int32_t *)dp = i;
else if (dsize == 2) *(int16_t *)dp = (int16_t)i;
else *(int8_t *)dp = (int8_t)i;
} else if (dsize == 4) {
*(uint32_t *)dp = (uint32_t)n;
} else if (dsize == 8) {
if (!(dinfo & CTF_UNSIGNED))
*(int64_t *)dp = (int64_t)n;
else
if ((dinfo & CTF_UNSIGNED))
*(uint64_t *)dp = lj_num2u64(n);
else
*(int64_t *)dp = lj_num2i64(n);
} else {
goto err_conv; /* NYI: conversion to >64 bit integers. */
}