Kacper Michajłow
6c91ac9cec
Add -fno-strict-float-cast-overflow complation flag
...
LuaJIT checks whether a Lua number can be represented as an integer by
casting the number (`double`) to an `int32_t` and comparing the result
to the original. While this approach works in practice, it is
technically UB according to the C standard. Because it's UB, compilers
are free to make optimizations that may not preserve the original intent
of the code. Clang/LLVM, in particular, takes advantage of this.
Consider the following code:
```c
int32_t k = lj_num2int(n);
if (n == (lua_Number)k)
...
```
Clang short-circuit this to do basically
```c
if (n == trunc(n))
...
```
It can do this because it assumes that `n` is either representable as an
`int32_t` or the behavior is undefined, which allows it to compare the
truncated `n` directly without needing to convert `k` back to a
`double`.
We could implement a C-compliant saturating cast from floating point to
integer ourselves, but that awkward, and more useless code, especially
since most FPUs already handle such conversions natively with
saturation.
Alternatively, we could use intrinsics or inline asm to ensure the
correct saturating conversion is used.
But there's a simpler option: we can ask the compiler to handle this
correctly for us.
This commit adds the `-fno-strict-float-cast-overflow` compilation flag, which:
> With the ‘no-strict’ option, Clang will saturate towards the smallest
and largest representable integer values instead. NaNs will be converted
to zero.
GCC does not currently exploit this UB as aggressively, so it's not an
issue there. MSVC also appears unaffected, though it provides built-in
functions for saturating conversions, if someone wants to use them
directly
https://learn.microsoft.com/cpp/intrinsics/saturation-conversion-functions
This commit fixes assumptions that LuaJIT makes in the code.
Fixes : #1351
2025-04-07 22:11:56 +02:00
Mike Pall
e0a7ea8a92
Merge branch 'master' into v2.1
2025-04-07 10:33:15 +02:00
Mike Pall
e76bb50d44
Fix error generation in load*.
...
Reported by Sergey Kaplun. #1353
2025-04-07 10:27:40 +02:00
Mike Pall
e9e4b6d302
Initialize unused value when specializing to cdata metatable.
...
Reported by jakitliang. #1354
2025-04-07 09:22:07 +02:00
Mike Pall
538a82133a
Change handling of nil value markers in template tables.
...
Reported by Bernhard M. Wiedemann. #1348 #1155
Fixes from Peter Cawley, Christian Clason, Lewis Russell.
2025-03-11 23:04:30 +01:00
Mike Pall
84cb21ffaf
REVERT: Change handling of nil value markers in template tables.
2025-03-10 02:56:07 +01:00
Mike Pall
4f2bb199fe
macOS: Fix Apple hardened runtime support and put behind build option.
...
Reported by vanc. #1334
2025-03-10 02:53:20 +01:00
Mike Pall
e3c70a7d81
macOS: Fix support for Apple hardened runtime.
...
Reported by Christian Clason. #1334
2025-03-10 00:05:08 +01:00
Mike Pall
7db2d1b12a
Fix handling of nil value markers in template tables.
...
Thanks to Peter Cawley. #1348 #1155
2025-03-09 23:11:05 +01:00
Mike Pall
e0551670c9
Merge branch 'master' into v2.1
2025-03-09 23:09:02 +01:00
Mike Pall
85c3f2fb6f
Avoid unpatching bytecode twice after a trace flush.
...
Reported by Sergey Kaplun. #1345
2025-03-09 23:04:23 +01:00
Mike Pall
eee16efa77
Fix state restore when recording __concat metamethod.
...
Reported by Sergey Kaplun. #1338 #1298
2025-03-09 21:28:17 +01:00
Mike Pall
4219efae43
Windows: Allow mixed builds with msvcbuild.bat.
...
Suggested by alex4814. #1341
2025-03-09 21:05:06 +01:00
Mike Pall
0254770582
macOS: Add suport for Apple hardened runtime.
...
Thanks to Peter Cawley. #1334
2025-03-09 20:45:22 +01:00
Mike Pall
f14556234c
Merge branch 'master' into v2.1
2025-03-09 16:25:34 +01:00
Mike Pall
d508715ab6
Add compatibility string coercion for fp:seek() argument.
...
Reported by Magnus Wibeck. #1343
2025-03-09 16:21:29 +01:00
Mike Pall
e27ee68817
Windows: Clarify installation directory layout.
...
Suggested by eabase. #1346
2025-03-09 16:10:22 +01:00
Mike Pall
55a42da36e
Remove Cygwin from docs, since it's not a supported target.
2025-03-09 16:09:36 +01:00
Mike Pall
423ac2144b
Improve CLI signal handling on POSIX.
2025-03-09 15:50:01 +01:00
Mike Pall
54dc2fa5d7
FFI: Add pre-declared int128_t, uint128_t, __int128 types.
...
Note: Only declaration and copy (interpreted only) are implemented.
2025-03-09 15:37:35 +01:00
Mike Pall
b1179ea5f7
Use dylib extension for iOS installs, too.
...
Reported by Andrey Filipenkov. #1336
2025-03-09 15:00:15 +01:00
Mike Pall
5eb9509468
Change handling of nil value markers in template tables.
...
Reported by Bernhard M. Wiedemann. #1348 #1155
2025-03-09 14:44:57 +01:00
Mike Pall
a4f56a459a
Merge branch 'master' into v2.1
2025-01-13 16:22:22 +01:00
Mike Pall
62e362afbb
Fix recording of BC_VARG.
...
Reported by Bachir Bendrissou.
2025-01-13 16:19:57 +01:00
Mike Pall
9d777346bc
Reject negative getfenv()/setfenv() levels to prevent compiler warning.
...
Thanks to Sergey Kaplun. #1329
2025-01-13 16:16:27 +01:00
Mike Pall
8358eb0cce
Merge branch 'master' into v2.1
2025-01-13 16:15:19 +01:00
Mike Pall
e8236561d4
Bump copyright date.
2025-01-13 15:59:10 +01:00
Mike Pall
f73e649a95
Merge branch 'master' into v2.1
2024-12-16 14:32:07 +01:00
Mike Pall
e2e0b1dd2d
Force fallback source name for stripped bytecode.
...
Reported by Lyrth. #1319
2024-12-16 14:30:10 +01:00
Mike Pall
cd8d0a437d
Remove dependency on <limits.h>.
...
Reported by yupengda002. #1318
2024-12-16 14:27:58 +01:00
Mike Pall
19878ec05c
Restore state when recording __concat metamethod throws OOM.
...
Reported by Sergey Kaplun. #1298 #1234
2024-11-28 18:07:58 +01:00
Mike Pall
35a4dd6f79
MIPS64: Fix pcall() error case.
...
Thanks to Sergey Kaplun. #1308
2024-11-28 16:33:18 +01:00
Mike Pall
4788e6f92a
Merge branch 'master' into v2.1
2024-11-28 16:28:51 +01:00
Mike Pall
811e448daa
Fix detection of inconsistent renames due to sunk values.
...
Thanks to Sergey Kaplun. #1295 #584
2024-11-28 16:26:10 +01:00
Mike Pall
fe71d0fb54
Windows: Allow amalgamated static builds with msvcbuild.bat.
...
Reported by Naman Dixit. #1289
2024-11-14 17:21:00 +01:00
Mike Pall
fca66335d1
Always close profiler output file.
...
Reported by Guilherme Batalheiro. #1304
2024-11-14 17:13:58 +01:00
Mike Pall
9ce8f1ff8e
Fix override of INSTALL_LJLIBD in the presence of DESTDIR.
...
Reported by faithanalog. #1239 #1303
2024-11-14 17:09:07 +01:00
Mike Pall
69bbf3c1b0
Fix bit op coercion for shifts in DUALNUM builds.
...
Reported by Junlong Li. Followup to #1273
2024-11-13 09:18:32 +01:00
Mike Pall
97813fb924
macOS: Remove obsolete -single_module flag.
...
Thanks to dundargoc. #1284
2024-10-02 13:59:42 +02:00
Mike Pall
b2915e9ab5
macOS: Workaround for buggy XCode 15.0 - 15.2 linker.
...
Thanks to Carlo Cabrera. #1283
2024-10-02 12:12:56 +02:00
Mike Pall
2240d84464
macOS: Fix macOS 15 / Clang 16 build.
...
Note: The -Wl,-no_deduplicate workaround is NOT needed anymore.
Thanks to fxcoudert, corsix, clason, baconpaul, mvf. #1275 #1266
2024-10-02 02:06:25 +02:00
Mike Pall
f5fd22203e
Fix bit op coercion in DUALNUM builds.
...
Thanks to Sergey Kaplun. #1273
2024-09-29 16:46:29 +02:00
Mike Pall
0ae532c9aa
Merge branch 'master' into v2.1
2024-09-29 16:11:15 +02:00
Mike Pall
5141cbc20c
Fix compiliation of getmetatable() for UDTYPE_IO_FILE.
...
Reported by Sergey Bronnikov. #1279
2024-09-29 16:03:37 +02:00
Mike Pall
c63a160706
Remove ancient RtlUnwindEx workaround for MinGW64.
...
Thanks to Kacper Michajłow. #1272
2024-09-29 15:33:32 +02:00
Mike Pall
87ae18af97
Drop unused function wrapper.
...
Follow-up to #1247 .
2024-09-04 14:32:08 +02:00
Mike Pall
f725e44cda
Merge branch 'master' into v2.1
2024-08-24 17:14:51 +02:00
Mike Pall
e45fd4cb71
Fix limit check in narrow_conv_backprop().
...
Thanks to Sergey Kaplun. #1262
2024-08-24 17:11:45 +02:00
Mike Pall
9bb6b35f7f
Always use IRT_NIL for IR_TBAR.
...
Thanks to Peter Cawley. #1258
2024-08-24 17:03:17 +02:00
Mike Pall
c68711cc87
ARM64: Use ldr literal to load FP constants.
...
Thanks to Peter Cawley. #1255
2024-08-21 11:31:29 +02:00