On Thu, Jan 30, 2025 at 10:59 AM Jakub Jelinek <ja...@redhat.com> wrote:
>
> On Thu, Jan 30, 2025 at 10:48:43AM +0100, Richard Biener via Gcc wrote:
> > On Thu, Jan 30, 2025 at 10:01 AM Dmitry Antipov <dmanti...@yandex.ru> wrote:
> > >
> > > With (probably) -Wmaybe-uninitialized and/or -Wextra, shouldn't the 
> > > compiler emit
> > > warning about possibly uninitialized 'y' passed to 'ddd()' in the example 
> > > below?
> > >
> > > struct T {
> > >    int a;
> > >    int b;
> > > };
> > >
> > > extern int bbb (struct T *, int *);
> > > extern int ccc (struct T *, int *);
> > > extern int ddd (struct T *, int);
> > >
> > > int
> > > aaa (struct T *t)
> > > {
> > >    int x = 0, y;         /* 'y' is uninitialized */
> > >
> > >    if (t->a)             /* if this condition is true */
> > >      goto l;
> > >
> > >    x += bbb (t, &y);
> >
> > We consider bbb to likely initialize 'y', so do not diagnose the use
> > on the ddd call
> > below.
>
> That is not the problem, sure, if bbb or ccc is called, we shouldn't warn.
> But neither of those could be called.
> Before uninit1 pass we have
>   # .MEM_10 = VDEF <.MEM_8(D)>
>   _11 = bbb (t_9(D), &y);
> ...
>   # .MEM_6 = PHI <.MEM_8(D)(7), .MEM_10(3)>
> ...
>   # .MEM_12 = VDEF <.MEM_6>
>   _13 = ccc (t_9(D), &y);
> ...
>   # .MEM_7 = PHI <.MEM_6(8), .MEM_12(5)>
>   # VUSE <.MEM_7>
>   y.0_3 = y;
> So, uninit1 should be able to see that there is a path through the cfg in
> which y is uninitialized.  Maybe we do this unitialized memory test only for
> the trivial cases where it is always uninitialized and not walk the PHIs
> if there could be one.

uninit does not diagnose "maybe uninit" memory, only cases where no
path initializes the variable (memory handling is not wired in into the "PHI"
handling of SSA undefs).

Richard.

>
>         Jakub
>

Reply via email to