Bug 511972 - valgrind-3.26.0 tests fail to build on upcomig gcc-16: unrecognized command-line option '-Wno-alloc-size-larger-than=18446744073709551615'
Summary: valgrind-3.26.0 tests fail to build on upcomig gcc-16: unrecognized command-l...
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (other bugs)
Version First Reported In: 3.26 GIT
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Paul Floyd
URL:
Keywords:
: 511974 (view as bug list)
Depends on:
Blocks:
 
Reported: 2025-11-11 22:04 UTC by Sergei Trofimovich
Modified: 2025-11-12 22:25 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
0001-bug-511972-check-for-both-W-and-Wno-warning-forms-gc.patch (1.20 KB, patch)
2025-11-11 22:09 UTC, Sergei Trofimovich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2025-11-11 22:04:50 UTC
SUMMARY

gcc-16 added extra validation to `-Wno-` options comared to `-W` options in https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=5b276d38c2fdd7df3d167755940da2038e049308

As a result `-Walloc-size-larger-than=18446744073709551615` is not valid flag while `-Wno-alloc-size-larger-than=18446744073709551615` is invalid and the build fails as:

gcc -DHAVE_CONFIG_H -I. -I../..  -I../.. -I../../include -I../../coregrind -I../../include -I../../VEX/pub -I../../VEX/pub -DVGA_amd64=1 -DVGO_linux=1 -DVGP_amd64_linux=1 -DVGPV_amd64_linux_vanilla=1    -Winline -Wall -Wshadow -Wno-long-long -g -fno-stack-protector   -m64 -Wno-unused-result -Wno-alloc-size-larger-than=18446744073709551615  -MT bug155125-bug155125.o -MD -MP -MF .deps/bug155125-bug155125.Tpo -c -o bug155125-bug155125.o `test -f 'bug155125.c' || echo './'`bug155125.c
gcc: error: unrecognized command-line option '-Wno-alloc-size-larger-than=18446744073709551615'

STEPS TO REPRODUCE
1. install `gcc` from `master`
2. $ ./configure CC=gcc-16 CXX=g++-16
3. $ make check

OBSERVED RESULT

Build fails with `gcc: error: unrecognized command-line option '-Wno-alloc-size-larger-than=18446744073709551615'`

EXPECTED RESULT

Build should succeed.

SOFTWARE/OS VERSIONS
compiler: gcc from master branch

ADDITIONAL INFORMATION

The bug happens because `configure.ac` only probes `-Walloc-size-larger-than=18446744073709551615` option and assumes `-Wno-alloc-size-larger-than=18446744073709551615` would work automatically:

From configure.ac:

```
AC_DEFUN([AC_GCC_WARNING_SUBST_NO],[
  AC_MSG_CHECKING([if gcc accepts -W$1])
  safe_CFLAGS=$CFLAGS
  CFLAGS="-W$1 -Werror" dnl <---------------- probe -W ===============
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[;]])], [
  AC_SUBST([$2], [-Wno-$1])  dnl <---------------- assume -Wno- =========
  AC_MSG_RESULT([yes])], [
  AC_SUBST([$2], [])
  AC_MSG_RESULT([no])])
  CFLAGS=$safe_CFLAGS
])
...

AC_GCC_WARNING_SUBST_NO([alloc-size-larger-than=18446744073709551615], [FLAG_W_NO_ALLOC_SIZE_LARGER_THAN])
```

It used to work until https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=5b276d38c2fdd7df3d167755940da2038e049308

A simple workaround to check both forms of the flag restores the build for me:

```diff
--- a/configure.ac
+++ b/configure.ac
@@ -2538,7 +2538,7 @@ fi
 AC_DEFUN([AC_GCC_WARNING_SUBST_NO],[
   AC_MSG_CHECKING([if gcc accepts -W$1])
   safe_CFLAGS=$CFLAGS
-  CFLAGS="-W$1 -Werror"
+  CFLAGS="-W$1 -Wno-$1 -Werror"
   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[;]])], [
   AC_SUBST([$2], [-Wno-$1])
   AC_MSG_RESULT([yes])], [
```
Comment 1 Sergei Trofimovich 2025-11-11 22:09:22 UTC
Created attachment 186714 [details]
0001-bug-511972-check-for-both-W-and-Wno-warning-forms-gc.patch

0001-bug-511972-check-for-both-W-and-Wno-warning-forms-gc.patch implements `-W` / `-Wno-` option probing.
Comment 2 Sam James 2025-11-11 23:41:37 UTC
*** Bug 511974 has been marked as a duplicate of this bug. ***
Comment 3 Paul Floyd 2025-11-12 08:25:24 UTC
Does that now mean that GCC generates "alloc size larger than" warnings because it no longer supports '-Wno-alloc-size-larger-than=18446744073709551615 ?
Comment 4 Mark Wielaard 2025-11-12 10:16:42 UTC
This feels like a regression in GCC. Why wouldn't it accept the -Wno variant that is accepted pre-gcc-16?
Might it just get fixed in GCC 16 (which is still a couple of months away) if we just report it against GCC?
Comment 5 Paul Floyd 2025-11-12 20:50:15 UTC
I've changed the -Wno-alloc-size-larger-than=18446744073709551615 options to -Walloc-size-larger-than=18446744073709551616, which is more than the value that we are using (usually -1 converted to size_t). Seems to work with clang 19 and gcc 14.

commit 51c5973d9d1f096b9472df75638f2a53324fafed (HEAD -> master, origin/master, origin/HEAD)
Author: Paul Floyd <pjfloyd@wanadoo.fr>
Date:   Wed Nov 12 21:46:23 2025 +0100

    Bug 511972 - valgrind-3.26.0 tests fail to build on upcomig gcc-16: unrecognized command-line option '-Wno-alloc-size-larger-than=18446744073709551615'
    
    Initial patch from Sergei Trofimovich, thanks.
Comment 6 Sergei Trofimovich 2025-11-12 22:08:08 UTC
(In reply to Mark Wielaard from comment #4)
> This feels like a regression in GCC. Why wouldn't it accept the -Wno variant
> that is accepted pre-gcc-16?
> Might it just get fixed in GCC 16 (which is still a couple of months away)
> if we just report it against GCC?

I think the change is intentional, but not sure. Added a comment to https://gcc.gnu.org/PR122243#c16.
Comment 7 Sergei Trofimovich 2025-11-12 22:25:05 UTC
(In reply to Paul Floyd from comment #3)
> Does that now mean that GCC generates "alloc size larger than" warnings
> because it no longer supports
> '-Wno-alloc-size-larger-than=18446744073709551615 ?

Yeah, the original change resurfaced the warnings again. Your change still keeps it suppressed \o/

(In reply to Paul Floyd from comment #5)
> I've changed the -Wno-alloc-size-larger-than=18446744073709551615 options to
> -Walloc-size-larger-than=18446744073709551616, which is more than the value
> that we are using (usually -1 converted to size_t). Seems to work with clang
> 19 and gcc 14.
> 
> commit 51c5973d9d1f096b9472df75638f2a53324fafed (HEAD -> master,
> origin/master, origin/HEAD)

Works for `gcc-16` as well. No alloc-size related warnings. Thank you!

The only new warning in `gcc-16` (unrelated to `-Wno-`) is:

new_override.cpp:21:16: warning: variable 'j' set but not used [-Wunused-but-set-variable=]
   21 |   volatile int j = 0;
      |                ^

An effect of https://gcc.gnu.org/PR44677 ( https://gcc.gnu.org/r16-2258-g0eac9cfee8cb0b21d ).