Am Montag, dem 01.06.2026 um 19:31 +0200 schrieb Jakub Jelinek:
> On Sat, May 30, 2026 at 11:20:45PM +0200, Martin Uecker wrote:
> > Bootstrapped and regression tested on x86_64.
> >
> > c: fix false positive for -Wvla-parameter [PR98539]
> >
> > In case of VLAs tat are multi-dimensional arrays with unspecified sizes,
> > the test in the warning code did not work correctly. Fix this by
> > explicitely checking that there are specified or unspecified size
> > expressions to determine the presence of a VLA.
> >
> > PR c/98539
> >
> > gcc/c-family/ChangeLog:
> > * c-warn.cc (warn_parm_array_mismatch): Check number of size
> > expressions.
> >
> > gcc/testsuite/ChangeLog:
> > + gcc.dg/pr98539.c: New test.
> >
> > diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
> > index 07d15c0b09c..76cbc8d7366 100644
> > --- a/gcc/c-family/c-warn.cc
> > +++ b/gcc/c-family/c-warn.cc
> > @@ -3479,9 +3479,22 @@ warn_parm_array_mismatch (location_t origloc,
> > rdwr_map *cur_idx,
> > cura->ptrarg = parmpos;
> > }
> >
> > +
> > + unsigned newbnds = 0;
> > + unsigned newunspec = 0;
> > +
> > + if (newa->internal_p)
> > + newbnds = newa->vla_bounds (&newunspec) + newunspec;
> > +
> > + unsigned curbnds = 0;
> > + unsigned curunspec = 0;
> > +
> > + if (cura->internal_p)
> > + curbnds = cura->vla_bounds (&curunspec) + curunspec;
>
> Isn't this and the earlier line compile time UB (one + operand
> modifying {new,cur}unspec variable, another one reading it,
> so different result between
> {
> unsigned tmp = curunspec;
> curbnds = cura->vla_bounds (&curunspec) + tmp;
> }
> and
> {
> unsigned tmp = cura->vla_bounds (&curunspec);
> curbnds = tmp + curunspec;
> }
> ?
> So, shouldn't that be
> {
> curbnds = cura->vla_bounds (&curunspec);
> curbnds += curunspec;
> }
> ?
yes, I agree. The code already looked weird to me.
I will commit with this change.
Martin