aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2021-05-12 15:57:34 -0600
committerMartin Sebor <msebor@redhat.com>2021-05-12 15:59:19 -0600
commitdb514f98a383b2ebdcfe74feb80f98f406cec174 (patch)
treeac7442ae51067e1cab7ec36c1cec7b428c7249d0
parentd902a1b57606536982a1001670f998de685eaf7c (diff)
downloadgcc-db514f98a383b2ebdcfe74feb80f98f406cec174.zip
gcc-db514f98a383b2ebdcfe74feb80f98f406cec174.tar.gz
gcc-db514f98a383b2ebdcfe74feb80f98f406cec174.tar.bz2
Add test for PR middle-end/100571.
gcc/testsuite: PR middle-end/100571 * gcc.dg/Wstringop-overflow-67.c: New test.
-rw-r--r--gcc/testsuite/gcc.dg/Wstringop-overflow-67.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-67.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-67.c
new file mode 100644
index 0000000..7b8f3f0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-67.c
@@ -0,0 +1,92 @@
+/* PR middle-end/100571 - bogus -Wstringop-overflow with VLA of elements
+ larger than byte
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+__attribute__ ((access (read_only, 1, 2))) void fro (int *, int);
+__attribute__ ((access (write_only, 1, 2))) void fwo (int *, int);
+__attribute__ ((access (read_write, 1, 2))) void frw (int *, int);
+
+extern __SIZE_TYPE__ n;
+
+void alloca_ro (void)
+{
+ int *a = __builtin_alloca (n * sizeof *a);
+ a[0] = 0;
+ fro (a, n);
+}
+
+void alloca_wo (void)
+{
+ int *a = __builtin_alloca (n * sizeof *a);
+ fwo (a, n);
+}
+
+void alloca_rw (void)
+{
+ int *a = __builtin_alloca (n * sizeof *a);
+ a[0] = 0;
+ frw (a, n);
+}
+
+
+void calloc_ro (void)
+{
+ int *a = __builtin_calloc (n, sizeof *a);
+ fro (a, n);
+}
+
+void calloc_wo (void)
+{
+ int *a = __builtin_calloc (n, sizeof *a);
+ fwo (a, n);
+}
+
+void calloc_rw (void)
+{
+ int *a = __builtin_calloc (n, sizeof *a);
+ a[0] = 0;
+ frw (a, n);
+}
+
+
+void malloc_ro (void)
+{
+ int *a = __builtin_malloc (n * sizeof *a);
+ a[0] = 0;
+ fro (a, n);
+}
+
+void malloc_wo (void)
+{
+ int *a = __builtin_malloc (n * sizeof *a);
+ fwo (a, n);
+}
+
+void malloc_rw (void)
+{
+ int *a = __builtin_malloc (n * sizeof *a);
+ a[0] = 0;
+ frw (a, n);
+}
+
+
+void vla_ro (void)
+{
+ int a[n];
+ a[0] = 0;
+ fro (a, n);
+}
+
+void vla_wo (void)
+{
+ int a[n];
+ fwo (a, n);
+}
+
+void vla_rw (void)
+{
+ int a[n];
+ a[0] = 0;
+ frw (a, n);
+}