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

83 views
Skip to first unread message

David Favro

unread,
Sep 1, 2025, 2:15:31 PM (6 days ago) Sep 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 PM (6 days ago) Sep 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 PM (6 days ago) Sep 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 PM (6 days ago) Sep 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 AM (5 days ago) Sep 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
Reply all
Reply to author
Forward
0 new messages