From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 7B6DD3858D3C; Wed, 1 Mar 2023 09:51:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B6DD3858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677664276; bh=aljssBO15/BGNDmdyl4P9y0L94R/nwUpN03inhmSeAo=; h=From:To:Subject:Date:From; b=D4vyX3qPnm2l7hL6KvGkDiYL4WQ6xENB3KJnIGRbg/8N4ruXjwEXasvAMFlDkPraL cxBuDC0y6nh74oxyK8yUXLR/Xy07FvadRABIXABPRssdN0aB8VyrGe2pZ0qVJ+RZBa KsI1NlkQyYgYmVbkbZxkXVfhed+xCAar+iXJrKgw= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6389] ubsan: Add another testcase for [0] array in the middle of struct [PR108894] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 520403f324a6ed8b527f39239709dd0841b992e2 X-Git-Newrev: f72c8918416f67aad907752f1892c19eda12eecb Message-Id: <20230301095116.7B6DD3858D3C@sourceware.org> Date: Wed, 1 Mar 2023 09:51:16 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f72c8918416f67aad907752f1892c19eda12eecb commit r13-6389-gf72c8918416f67aad907752f1892c19eda12eecb Author: Jakub Jelinek Date: Wed Mar 1 10:49:38 2023 +0100 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 PR sanitizer/108894 * c-c++-common/ubsan/bounds-16.c: New test. Diff: --- gcc/testsuite/c-c++-common/ubsan/bounds-16.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 00000000000..0c27ff9cce4 --- /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]; +}