aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2023-03-01 10:49:38 +0100
committerJakub Jelinek <jakub@redhat.com>2023-03-01 10:49:38 +0100
commitf72c8918416f67aad907752f1892c19eda12eecb (patch)
tree1c1c88a83a60d329501f76cdab9159a84d319b87
parent520403f324a6ed8b527f39239709dd0841b992e2 (diff)
downloadgcc-f72c8918416f67aad907752f1892c19eda12eecb.zip
gcc-f72c8918416f67aad907752f1892c19eda12eecb.tar.gz
gcc-f72c8918416f67aad907752f1892c19eda12eecb.tar.bz2
ubsan: Add another testcase for [0] array in the middle of struct [PR108894]
I think it is useful to cover also this, rather than just arrays at the flexible array member positions. 2023-03-01 Jakub Jelinek <jakub@redhat.com> PR sanitizer/108894 * c-c++-common/ubsan/bounds-16.c: New test.
-rw-r--r--gcc/testsuite/c-c++-common/ubsan/bounds-16.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/ubsan/bounds-16.c b/gcc/testsuite/c-c++-common/ubsan/bounds-16.c
new file mode 100644
index 0000000..0c27ff9
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/bounds-16.c
@@ -0,0 +1,15 @@
+/* PR sanitizer/108894 */
+/* { dg-do run } */
+/* { dg-options "-fsanitize=bounds -fsanitize-recover=bounds" } */
+/* { dg-output "index 1 out of bounds for type 'int \\\[\[*0-9x]*\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*index 0 out of bounds for type 'int \\\[\[*0-9x]*\\\]'" } */
+
+struct S { int a; int b[0]; int c; } s;
+
+int
+main ()
+{
+ int *volatile p = &s.b[0];
+ p = &s.b[1];
+ int volatile q = s.b[0];
+}