https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95818
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c |middle-end
Resolution|--- |INVALID
CC| |msebor at gcc dot gnu.org
Status|WAITING |RESOLVED
--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
This instance of the warning looks familiar but I can't reproduce it with my
build of the kernel. The code in the test case isn't valid (it triggers both
-Wstrict-aliasing and -Wuninitialized), and I don't think it's safe either.
Only the leading 48 bits of the struct are initialized (by GCC; the program
initializes just 35 bits) but the access is to the full 64 bits. Clearing the
whole struct by calling memset avoids the -Wuninitialized.
A small test case that reproduces both warnings is below.
$ cat z.c && gcc -O2 -S -Wall -fdump-tree-uninit=/dev/stdout z.c
struct S
{
int a;
short i: 1;
};
void f (long);
void g (void)
{
struct S s;
s.a = 0;
s.i = 1;
f (*(long*)&s);
}
z.c: In function ‘g’:
z.c:14:7: warning: dereferencing type-punned pointer will break strict-aliasing
rules [-Wstrict-aliasing]
14 | f (*(long*)&s);
| ^~~~~~~~~
z.c:14:3: warning: ‘s’ is used uninitialized [-Wuninitialized]
14 | f (*(long*)&s);
| ^~~~~~~~~~~~~~
z.c:11:12: note: ‘s’ declared here
11 | struct S s;
| ^
;; Function g (g, funcdef_no=0, decl_uid=1937, cgraph_uid=1, symbol_order=0)
g ()
{
struct S s;
long int _1;
<bb 2> [local count: 1073741824]:
s.a = 0;
s.i = -1;
_1 = MEM[(long int *)&s];
f (_1); [tail call]
s ={v} {CLOBBER};
return;
}