On 18/05/26 10:55 PM, Amit Machhiwal wrote:
GCC 16 has tightened const-correctness checking and now correctly
rejects attempts to modify or assign const-qualified pointers without
proper qualification. This series fixes two such violations that cause
build failures with GCC 16 when using -Werror=discarded-qualifiers.

Both patches follow the same approach: changing local variables to
const-qualified types and using GLib string functions (g_strdup,
g_strndup, g_strstr_len, g_getenv) that work correctly with const
strings, eliminating the need for in-place modifications.

Changes in v3:
- Harsh: g_strndup will abort the program in case of OOM eventually making it a
   dead code. Additionally, typecase (suffix - cname). Also, unlikely() is not
   needed.
     - Remove error handling (GLib functions abort on allocation failure)
     - Remove unlikely() macro (provides no benefit in initialization code)
     - Typecast (suffix - cname)
- Update the commit messages accordingly
- v2: https://lore.kernel.org/all/[email protected]/

Changes in v2:
- Avoid pointer aliasing
- Handle memory allocation failure error
- v1: https://lore.kernel.org/all/[email protected]

Tested on:
- GCC 16.1.1 (no warnings with -Werror=discarded-qualifiers)
- GCC 15.2.1 (backward compatible)

Amit Machhiwal (2):
   target/ppc/kvm: Fix const violation when trimming CPU alias suffix
   tests/qtest/libqtest: Fix const violation in qtest_verbose()

  target/ppc/kvm.c       | 11 +++++------
  tests/qtest/libqtest.c |  9 ++++-----
  2 files changed, 9 insertions(+), 11 deletions(-)


base-commit: ac6721b88df944ade0048822b2b74210f543d656

Hi Amit,

I have tested this patch and it has fixed the qemu build failure. Here is my analysis:

[root@localhost build]# gcc --version
gcc (GCC) 16.1.1 20260501 (Red Hat 16.1.1-1)


Before applying the patch, when I tried to build qemu it failed:


[1431/2891] Compiling C object tests/qtest/libqos/libqos.a.p/.._libqtest.c.o
FAILED: [code=1] tests/qtest/libqos/libqos.a.p/.._libqtest.c.o
cc -m64 -mlittle-endian -Itests/qtest/libqos/libqos.a.p -Itests/qtest/libqos -I../tests/qtest/libqos -I. -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-6 -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -fno-link-libatomic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -ftrivial-auto-var-init=zero -fzero-init-padding-bits=all -fzero-call-used-regs=used-gpr -fstack-protector-strong -Wempty-body -Wendif-labels -Wexpansion-to-defined -Wformat-overflow=2 -Wformat-security -Wformat-y2k -Wignored-qualifiers -Wimplicit-fallthrough=2 -Winit-self -Wmissing-format-attribute -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls -Wshadow=local -Wstrict-prototypes -Wtype-limits -Wundef -Wvla -Wwrite-strings -Wno-missing-include-dirs -Wno-psabi -Wno-shift-negative-value -isystem /root/qemu/linux-headers -isystem linux-headers -iquote . -iquote /root/qemu -iquote /root/qemu/include -iquote /root/qemu/host/include/ppc64 -iquote /root/qemu/host/include/generic -iquote /root/qemu/tcg/ppc64 -pthread -fPIE -MD -MQ tests/qtest/libqos/libqos.a.p/.._libqtest.c.o -MF tests/qtest/libqos/libqos.a.p/.._libqtest.c.o.d -o tests/qtest/libqos/libqos.a.p/.._libqtest.c.o -c ../tests/qtest/libqtest.c
../tests/qtest/libqtest.c: In function ‘qtest_verbose’:
../tests/qtest/libqtest.c:2175:15: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
 2175 |         found = strstr(log, domain);
      |               ^
cc1: all warnings being treated as errors
ninja: build stopped: subcommand failed.
make: *** [Makefile:170: run-ninja] Error 1



After applying the patch, building qemu worked perfectly fine.

Please feel free to add:

Tested-by: Anushree Mathur <[email protected]>

Thank you,
Anushree Mathur


Reply via email to