aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/attribs.c1
-rw-r--r--gcc/c/c-decl.c6
-rw-r--r--gcc/testsuite/gcc.dg/Wnonnull-5.c53
-rw-r--r--gcc/testsuite/gcc.dg/Wvla-parameter-2.c4
4 files changed, 60 insertions, 4 deletions
diff --git a/gcc/attribs.c b/gcc/attribs.c
index 3bdb2ff..a6f6b70 100644
--- a/gcc/attribs.c
+++ b/gcc/attribs.c
@@ -2109,6 +2109,7 @@ init_attr_rdwr_indices (rdwr_map *rwm, tree attrs)
is followed by a comma and a dollar sign its bound is
on the list. Otherwise it's a VLA with an unspecified
bound. */
+ acc.static_p = p[-2] == 's';
acc.minsize = HOST_WIDE_INT_M1U;
}
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 81b9adb..1673b95 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -5784,6 +5784,9 @@ get_parm_array_spec (const struct c_parm *parm, tree attrs)
continue;
}
+ if (pd->u.array.static_p)
+ spec += 's';
+
if (TREE_CODE (nelts) == INTEGER_CST)
{
/* Skip all constant bounds except the most significant one.
@@ -5796,9 +5799,8 @@ get_parm_array_spec (const struct c_parm *parm, tree attrs)
return attrs;
char buf[40];
- const char *code = pd->u.array.static_p ? "s" : "";
unsigned HOST_WIDE_INT n = tree_to_uhwi (nelts);
- sprintf (buf, "%s%llu", code, (unsigned long long)n);
+ sprintf (buf, "%llu", (unsigned long long)n);
spec += buf;
break;
}
diff --git a/gcc/testsuite/gcc.dg/Wnonnull-5.c b/gcc/testsuite/gcc.dg/Wnonnull-5.c
new file mode 100644
index 0000000..ef6ed54
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wnonnull-5.c
@@ -0,0 +1,53 @@
+/* PR middle-end/97552 - missing waning passing null to a VLA argument
+ declared [static]
+ { dg-do compile }
+ { dg-options "-Wall" } */
+
+#define A(...) __attribute__ ((__VA_ARGS__))
+
+void fptr_array (int(*)[0]);
+
+void fstatic_array (int[static 0]);
+void A (nonnull) fnonnull_static_array (int [static 0]);
+
+void fvla (int n, int [n]);
+void A (nonnull) fnonnull_vla (int n, int [n]);
+
+void fstatic_vla (int n, int [static n]);
+void A (nonnull) fnonnull_static_vla (int n, int [static n]);
+
+
+void test_null (void)
+{
+ fptr_array (0);
+ fptr_array (&(int[0]){ });
+
+ fstatic_array (0); // { dg-warning "\\\[-Wnonnull" }
+ fnonnull_static_array (0); // { dg-warning "\\\[-Wnonnull" }
+
+ fvla (0, 0);
+ fnonnull_vla (0, 0); // { dg-warning "\\\[-Wnonnull" }
+
+ fstatic_vla (0, 0); // { dg-warning "\\\[-Wnonnull" }
+ fnonnull_static_vla (0, 0); // { dg-warning "\\\[-Wnonnull" }
+}
+
+
+#pragma GCC optimize ("1")
+
+void test_null_optimized (void)
+{
+ int (*pa)[0] = 0;
+ fptr_array (pa);
+
+ int *p = 0;
+
+ fstatic_array (p); // { dg-warning "\\\[-Wnonnull" }
+ fnonnull_static_array (p); // { dg-warning "\\\[-Wnonnull" }
+
+ fvla (0, p);
+ fnonnull_vla (0, p); // { dg-warning "\\\[-Wnonnull" }
+
+ fstatic_vla (0, p); // { dg-warning "\\\[-Wnonnull" }
+ fnonnull_static_vla (0, p); // { dg-warning "\\\[-Wnonnull" }
+}
diff --git a/gcc/testsuite/gcc.dg/Wvla-parameter-2.c b/gcc/testsuite/gcc.dg/Wvla-parameter-2.c
index ba93241..01728e7 100644
--- a/gcc/testsuite/gcc.dg/Wvla-parameter-2.c
+++ b/gcc/testsuite/gcc.dg/Wvla-parameter-2.c
@@ -67,9 +67,9 @@ void a2pampan (int (*(*(*[2])[n1])[n2]));
int f2ia1_1 (int n, int [n][n]); // { sg-message "previously declared as 'int\\\[n]\\\[n]' with bound argument 1" }
int f2ia1_1 (int n, int[static n][n]);
int f2ia1_1 (int n, int a[static n][n]) { return sizeof *a; }
-int f2ia1_1 (int n, int[static n + 1][n]); // { dg-warning "argument 2 of type 'int\\\[n \\\+ 1]\\\[n]' declared with mismatched bound 'n \\\+ 1'" }
+int f2ia1_1 (int n, int[static n + 1][n]); // { dg-warning "argument 2 of type 'int\\\[static *n \\\+ 1]\\\[n]' declared with mismatched bound 'n \\\+ 1'" }
-int f2ias1_1 (int n, int [static n][n]); // { dg-message "previously declared as 'int\\\[n]\\\[n]' with bound argument 1" }
+int f2ias1_1 (int n, int [static n][n]); // { dg-message "previously declared as 'int\\\[static +n]\\\[n]' with bound argument 1" }
int f2ias1_1 (int n, int[n][n]);
int f2ias1_1 (int n, int a[++n][n]) // { dg-warning "argument 2 of type 'int\\\[\\\+\\\+n]\\\[n]' declared with mismatched bound ' ?\\+\\+n'" }
{ return sizeof *a; }