-O3 triggers compiler warning [x86_64, Linux, gcc]

138 views
Skip to first unread message

David Favro

unread,
Sep 1, 2025, 2:15:31 PMSep 1
to lu...@googlegroups.com

Please forgive me if this has already been reported, and is considered safe to ignore.

x86_64, gcc version (Debian 14.2.0-19) 14.2.0.

Vanilla Lua dev head (commit 9a3940380a2a) compiles without warnings, however
changing `-O2` to `-O3` in the makefile causes the following warning:

```
gcc -Wall -O3 -Wfatal-errors -Wextra -Wshadow -Wundef -Wwrite-strings -Wredundant-decls -Wdisabled-optimization -Wdouble-promotion -Wmissing-declarations -Wconversion -Wstrict-overflow=2 -Wdeclaration-after-statement -Wmissing-prototypes -Wnested-externs -Wstrict-prototypes -Wc++-compat -Wold-style-definition -Wlogical-op -Wno-aggressive-loop-optimizations -std=c99 -DLUA_USE_LINUX -fno-stack-protector -fno-common -march=native -c -o ldo.o ldo.c

ldo.c: In function ‘luaD_reallocstack’:
ldo.c:303:5: warning: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow]
303 | int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) {
| ^~~~~~~~~~~~~~~~~
```

-- David

Roberto Ierusalimschy

unread,
Sep 1, 2025, 3:33:42 PMSep 1
to 'David Favro' via lua-l
> ldo.c: In function ‘luaD_reallocstack’:
> ldo.c:303:5: warning: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow]
> 303 | int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) {
> | ^~~~~~~~~~~~~~~~~

Can someone make sense of that? It seems there are no conditionals on
this line...

-- Roberto

David Favro

unread,
Sep 1, 2025, 4:33:03 PMSep 1
to lu...@googlegroups.com, Roberto Ierusalimschy
I also saw no apparent cause of the warning, and I still don't understand why it is emitted, but the release notes of gcc **8** at
https://gcc.gnu.org/gcc-8/changes.html#c-family
contain a cryptic message that
-Wstrict-overflow is deprecated and `-fsanitize=signed-integer-overflow` should be used in its place. While I don't understand this, especially why an option that is deprecated since 2018 and at least 5 releases ago, is still in the compiler and emitting warnings, I did try changing the options from -Wstrict-overflow=2 to -fsanitize=signed-integer-overflow and the warning disappeared.

Whether this would also prevent the flagging of some *true* overflow constructs, I have no idea.

Some more info at:
https://gcc.gnu.org/wiki/VerboseDiagnostics#assuming_signed_overflow_does_not_occur_when_simplifying_conditional_to_constant_.5B-Wstrict-overflow.5D

-- David

David Favro

unread,
Sep 1, 2025, 4:57:59 PMSep 1
to lu...@googlegroups.com


On September 1, 2025 8:32:58 PM UTC, David Favro <l...@meta-dynamic.com> wrote:

[snip]

>-Wstrict-overflow is deprecated and
>`-fsanitize=signed-integer-overflow`
>should be used in its place

Following up, looking into -fsanitize=* a little more, it may be more appropriate for debug than production builds. It adds run-time instrumentation into your executable, rather than static analysis. So, not at all a simple equivalent for a compile-time warning.

-- David

Roberto Ierusalimschy

unread,
Sep 2, 2025, 10:43:01 AMSep 2
to 'David Favro' via lua-l
The documentation you mentioned did not say that it "should be used in
its place". It compares -fsanitize=signed-integer-overflow with
-fno-strict-overflow, and then in the same sentence mentions that
-Wstrict-overflow is deprecated. Yes, it is confusing.

-- Roberto

Philippe Verdy

unread,
Sep 7, 2025, 12:50:01 PMSep 7
to lu...@googlegroups.com
Why using "int" instead of a "size_t" here? This is signifiant when compiling for 16-bit code (e.g. for use in DOS in x86 "real mode", e.g. if one wants to write a safe firmware update script with Lua to run from a bootable DOS flash disk with minimal memory footprint and stricter control of the hardware to avoid background effects, or some code in a small 8/16-bit microcontroller like Intel 8044/8081 when there are very strict real-time constraints, prohibiting using any background processes or kernel-level background threads performing undesired I/O).


--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lua-l+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/lua-l/20250902144255.GC1151265%40arraial.inf.puc-rio.br.
Reply all
Reply to author
Forward
0 new messages