continue;
}
+ if (pd->u.array.static_p)
+ spec += 's';
+
if (TREE_CODE (nelts) == INTEGER_CST)
{
/* Skip all constant bounds except the most significant one.
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;
}
--- /dev/null
+/* 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" }
+}
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; }