On 10/23/20 7:41 AM, Uecker, Martin wrote:


I tested a recent GCC from git and noticed a couple
of new warnings for VLA parameters.

(Martin, I assume this is your work. First, let me
say: thank you! I think this is really important.)

Here is some feedback from running this on an
existing code base. See below for comments and
toy examples. The capital letters refer to
specific warnings.

Best,
Martin



-Wvla-parameter

A and B: I think the warning is a bit too strict.
These types are compatible, just one of them is
incomplete.

C: this seems to be bug as the types are
identical.

Yes, it's a bug.  I opened pr97548 for it.  It probably won't be
trivial to fix.


-Wstringop-overflow / -Wnonnull

D and F: Without 'static' I am not sure why this
is not allowed to be a null pointer (as in E and G).

I agree it should be.  It seems to be allowed on trunk.  The warning
inadvertently skips the 'static' part for VLAs.  I've raised pr97552
as a reminder to fix that.

Thanks for testing!

Martin

#include <stdlib.h>

void f1(int n, int x[n]);

void f1(int n, int x[]) { };
// A: warning: argument 2 of type ‘int[]’ declared as an ordinary array

void f2(int n, int x[]);

void f2(int n, int x[n]) { };
// B: argument 2 of type ‘int[n]’ declared as a variable length array

void f3(int n, int x[n + 1]);

void f3(int n, int x[n + 1]) { };
// C: argument 2 of type ‘int[n + 1]’ declared with mismatched bound ‘n
+ 1’

void f4(int n, int x[static n]) { };

void foo(void)
{
   int x[] = { };
   f1(0, x);
   f1(1, x);
// D: ‘f1’ accessing 4 bytes in a region of size 0

   f4(0, x);
   f4(1, x):
// E: ‘f4’ accessing 4 bytes in a region of size
0

   f1(0, NULL);
   f1(1, NULL);
// F: argument 1 of variable length array ‘int[n]’ is null but the
corresponding bound argument 2 value is 1

   f4(0, NULL);
   f4(1, NULL);
// G: argument 1 of variable length array ‘int[n]’ is null but the
corresponding bound argument 2 value is 1
}


Reply via email to