https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95848
Bug ID: 95848
Summary: missing -Wuninitialized passing structs by value
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
In the test case below, -Wuninitialized only detects the first instances of
using an uninitialized struct. It does not detect passing it as an argument by
value.
$ cat q.c && gcc -O2 -S -Wall q.c
struct S { int i; };
struct S sf (void)
{
struct S s;
return s; // -Wuninitialized (good)
}
void fp (const struct S*);
void g (void)
{
struct S s;
fp (&s); // -Wuninitialized (good)
}
void fs (struct S);
void h (void)
{
struct S s;
fs (s); // missing -Wuninitialized
}
q.c: In function ‘sf’:
q.c:6:10: warning: ‘s’ is used uninitialized [-Wuninitialized]
6 | return s; // -Wuninitialized (good)
| ^
q.c:5:12: note: ‘s’ declared here
5 | struct S s;
| ^
q.c: In function ‘g’:
q.c:14:3: warning: ‘s’ may be used uninitialized [-Wmaybe-uninitialized]
14 | fp (&s); // -Wuninitialized (good)
| ^~~~~~~
q.c:9:6: note: by argument 1 of type ‘const struct S *’ to ‘fp’ declared here
9 | void fp (const struct S*);
| ^~
q.c:13:12: note: ‘s’ declared here
13 | struct S s;
| ^