From patchwork Wed Mar 1 09:58:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 62834 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3540395wrd; Wed, 1 Mar 2023 01:59:16 -0800 (PST) X-Google-Smtp-Source: AK7set+cbCDOgRCGIAZervasrwiFu4z84KqMA18me7a2zdJJMJ+ZQANtgQ/F5QrvyP2ptipwCjDg X-Received: by 2002:aa7:dcd1:0:b0:4bd:6b93:1289 with SMTP id w17-20020aa7dcd1000000b004bd6b931289mr468263edu.15.1677664756273; Wed, 01 Mar 2023 01:59:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677664756; cv=none; d=google.com; s=arc-20160816; b=Nk1f1hlEYGKVXL0TKVx/FwffxZrwdmfCStQw/BFkyvKelEfdanhLCb1v/9B5WbQ7C4 vzJfBPWKwKv2b3ZZBgF36d0EN/oPMowvAKmxS3u3XpEylhnlOwm6vcinXMhD+VoT4Lde 94DzNClxcFRgS7FloubzhP9F0ge0D9dmG8xygAsfiyS4kxJ601vT1/ENyArmyzSE6E+E BNvc6R4qkavamzhK8uSW1BVphaRAfOVrvxPQJrn39OPZS96Jq/69pNUYaWc1wbpxhOQR 7Npy/8NaqwPHC3Lqjjvia4mMKl6ijH2SCmkARdtHca8brPLOtmeidTzE/HbgksOOzEaE R+Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:content-disposition:in-reply-to :mime-version:references:message-id:subject:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=/ShuZLPFznPGYmPHabaJoR8pVVO4WXRJQrI0/BUpSlM=; b=jW1BNB6lDQRSkLNZRlVvogs3lRtuRgWTXZU7IYDjP3ieSqXpSdKQP5WLZqQklNKL79 9WcYTRtrX8TsrA/KZEHB/21tWGKG8w5beedVJQVmVyQsUHQOs2BtHXsS2d20w9uU8OkR rB9H0JgQtT4yLCajQpqYDIkaUY4RtmASVKcRrr/Zy8vMQggeozr2vOyLtIrwcs2+cfSU V3fi8YV3R8TOhi0H+G4ZBfFPRZ4VN4ktrz95xZVc/RL2hdPt5DVpAsgdiBb+d6v3qDEq BCJoJNdE11NdKD+xcLpFLLtMBbMYoVorY0fs20mArKLsLlRPWg+kyqKPa+oxcPqHVhRO LBbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=s6fqhpqp; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d10-20020a50fe8a000000b004acd2b912b9si707962edt.211.2023.03.01.01.59.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 01:59:16 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=s6fqhpqp; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D5823858C5E for ; Wed, 1 Mar 2023 09:59:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D5823858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677664755; bh=/ShuZLPFznPGYmPHabaJoR8pVVO4WXRJQrI0/BUpSlM=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=s6fqhpqp2mriiAVTTPZJf0T6SLr8+lLENvRuoLr+KzHZmslml0d06uLKmBqQBXiK7 qmKoqYeo/gH0D35x5QR9rHiaejyOdM46EpAj3QcERTI54P02sl8seCTT81A2ftcW0k vYj3lEd+4TqG/lJDHaMnX+PdR/rL8xdg0kcc4okw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 8E9333858D33 for ; Wed, 1 Mar 2023 09:58:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E9333858D33 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-219-stMblNxXPmyXbRTpJLI7cg-1; Wed, 01 Mar 2023 04:58:25 -0500 X-MC-Unique: stMblNxXPmyXbRTpJLI7cg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A029485A5B1; Wed, 1 Mar 2023 09:58:24 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 078831121315; Wed, 1 Mar 2023 09:58:23 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3219wGGk1626176 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 1 Mar 2023 10:58:16 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3219wFSG1626175; Wed, 1 Mar 2023 10:58:15 +0100 Date: Wed, 1 Mar 2023 10:58:14 +0100 To: Qing Zhao , Richard Biener , "gcc-patches@gcc.gnu.org" Subject: [committed] ubsan: Add another testcase for [0] array in the middle of struct [PR108894] Message-ID: References: <50C5DFA0-F8A5-4E1A-8353-FBF3CABF3F4B@oracle.com> <9B0A086B-0C48-4038-AD6F-BD18DFBCAEF3@oracle.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759158999818416967?= X-GMAIL-MSGID: =?utf-8?q?1759158999818416967?= Hi! On Tue, Feb 28, 2023 at 10:59:03PM +0100, Jakub Jelinek via Gcc-patches wrote: > On Tue, Feb 28, 2023 at 07:19:40PM +0000, Qing Zhao wrote: > > Understood. > > So, your patch fixed this bug, and then [0] arrays are instrumented by default with this patch. > > > > > Well, it would complain about > > > struct S { int a; int b[0]; int c; } s; > > > ... &s.b[1] ... > > > for C++, but not for C. > > > > A little confused here: [0] arrays were instrumented by default for C++ if it’s not a trailing array, but not for C? > > Given say > 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]; > } And, when I wrote such a testcase, I thought it would be worth it to have it in the testsuite too. Tested on x86_64-linux -m32/-m64, committed to trunk as obvious: 2023-03-01 Jakub Jelinek PR sanitizer/108894 * c-c++-common/ubsan/bounds-16.c: New test. Jakub --- gcc/testsuite/c-c++-common/ubsan/bounds-16.c.jj 2023-03-01 10:35:29.751959193 +0100 +++ gcc/testsuite/c-c++-common/ubsan/bounds-16.c 2023-03-01 10:38:09.087645556 +0100 @@ -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]; +}