https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124427
Bug ID: 124427
Summary: PPC: False positive -Wmaybe-uninitialized with GCC 15
while compiling powerpc kernel selftests
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: amachhiw at linux dot ibm.com
Target Milestone: ---
GCC 15 (tested on v15.2.1) reports the below false positive
'-Wmaybe-uninitialized'
warning in vphn_unpack_associativity() when building the powerpc selftests as
below:
# make -C tools/testing/selftests TARGETS="powerpc"
[...]
make: Entering directory '/home/linux/tools/testing/selftests/powerpc/vphn'
gcc -std=gnu99 -O2 -Wall -Werror -DGIT_VERSION='"v7.0-rc2-0-g11439c4635ed"'
-I/home/linux/tools/testing/selftests/powerpc/include -m64
-I/home/linux/tools/testing/selftests/powerpc/vphn test-vphn.c ../harness.c
-o /home/linux/tools/testing/selftests/powerpc/vphn/test-vphn
In file included from test-vphn.c:3:
In function ‘vphn_unpack_associativity’,
inlined from ‘test_one’ at test-vphn.c:371:2,
inlined from ‘test_vphn’ at test-vphn.c:399:9:
test-vphn.c:10:33: error: ‘be_packed’ may be used uninitialized
[-Werror=maybe-uninitialized]
10 | #define be16_to_cpup(x) bswap_16(*x)
| ^~~~~~~~
vphn.c:42:27: note: in expansion of macro ‘be16_to_cpup’
42 | u16 new = be16_to_cpup(field++);
| ^~~~~~~~~~~~
In file included from test-vphn.c:19:
vphn.c: In function ‘test_vphn’:
vphn.c:27:16: note: ‘be_packed’ declared here
27 | __be64 be_packed[VPHN_REGISTER_COUNT];
| ^~~~~~~~~
cc1: all warnings being treated as errors
When vphn_unpack_associativity() is called from hcall_vphn(), this error is not
seen during compilation because GCC 15 seems to consider 'retbuf' always
populated from the hypervisor which is eventually referred by 'be_packed'.
However, GCC 15's dataflow analysis can’t prove the same before the first
dereference when vphn_unpack_associativity() is called from test_one() with
pre-initialized array of 'struct test'. This results in a false positive
warning
which is promoted to an error under '-Werror'.
Also, please note that this problem is not seen when the compilation is
performed with GCC 13 and 14.
Steps to recreate:
------------------
1. Clone upstream Linux
2. Run the below command to build powerpc selftests:
make -C tools/testing/selftests TARGETS="powerpc"