Message ID | 20211012183347.385794-1-siddhesh@gotplt.org |
---|---|
State | Dropped |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E0A0A385840B for <patchwork@sourceware.org>; Tue, 12 Oct 2021 18:34:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from brown.birch.relay.mailchannels.net (brown.birch.relay.mailchannels.net [23.83.209.23]) by sourceware.org (Postfix) with ESMTPS id 089233858D3C for <gcc-patches@gcc.gnu.org>; Tue, 12 Oct 2021 18:34:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 089233858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 1BDB4682005; Tue, 12 Oct 2021 18:34:05 +0000 (UTC) Received: from pdx1-sub0-mail-a82.g.dreamhost.com (100-96-133-192.trex.outbound.svc.cluster.local [100.96.133.192]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 903FE681F24; Tue, 12 Oct 2021 18:34:04 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a82.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.133.192 (trex/6.4.3); Tue, 12 Oct 2021 18:34:05 +0000 X-MC-Relay: Junk X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Shelf-Robust: 4defa0d37b2ee585_1634063644906_3371523186 X-MC-Loop-Signature: 1634063644906:1765312997 X-MC-Ingress-Time: 1634063644906 Received: from pdx1-sub0-mail-a82.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a82.g.dreamhost.com (Postfix) with ESMTP id 9294989D78; Tue, 12 Oct 2021 11:34:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gotplt.org; h=from:to:cc :subject:date:message-id:mime-version:content-transfer-encoding; s=gotplt.org; bh=tvU1S3qhf52Sp7HGuqk3PY1iv0o=; b=Fso43Rpxfr2D+r 3eF+ByRmZ5NIJAZQMjunm9SaAylvXgxFcI15Ht7g439+8e0q/CZRCXvv24sviYBX un/uLdHRIdhEdTX+d0JBgGpvep3yAx5/sxfan3oPjjAHJwLbxP5DOYHuQ6eMzeDM MGFtOkg5kgOmaTLP58YrfkqHVqIMQ= Received: from rhbox.redhat.com (unknown [1.186.121.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a82.g.dreamhost.com (Postfix) with ESMTPSA id 6456C89D72; Tue, 12 Oct 2021 11:33:59 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a82 From: Siddhesh Poyarekar <siddhesh@gotplt.org> To: gcc-patches@gcc.gnu.org Subject: [PATCH] Warray-bounds: Warn only for generic address spaces Date: Wed, 13 Oct 2021 00:03:47 +0530 Message-Id: <20211012183347.385794-1-siddhesh@gotplt.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3037.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SBL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Cc: msebor@redhat.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
Warray-bounds: Warn only for generic address spaces
|
|
Commit Message
Siddhesh Poyarekar
Oct. 12, 2021, 6:33 p.m. UTC
The warning is falsely triggered for THREAD_SELF in glibc when
accessing TCB through the segment register.
gcc/ChangeLog:
* gimple-array-bounds.cc
(array_bounds_checker::check_mem_ref): Bail out for
non-generic address spaces.
gcc/testsuite/ChangeLog:
* gcc.target/i386/addr-space-3.c: New test case.
Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
---
gcc/gimple-array-bounds.cc | 3 +++
gcc/testsuite/gcc.target/i386/addr-space-3.c | 5 +++++
2 files changed, 8 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/i386/addr-space-3.c
Comments
On 10/12/21 12:33 PM, Siddhesh Poyarekar wrote: > The warning is falsely triggered for THREAD_SELF in glibc when > accessing TCB through the segment register. Thanks for looking into it! The Glibc warning is being tracked in PR 102630. The root cause behind it is in compute_objsize_r in pointer-query.cc (which is used by -Warray-bounds as well as other warnings). I just posted a patch for it the other day; it's waiting for approval (though as Joseph noted, I need to adjust the test and either make it target-independent or move it under i386). Martin PS Noticing gcc.target/i386/addr-space-2.c makes me wish -Warray-bounds were enabled by default, like other out-of-bounds warnings, and reminds me that it should be able to run even at -O1 (and -O0). > > gcc/ChangeLog: > > * gimple-array-bounds.cc > (array_bounds_checker::check_mem_ref): Bail out for > non-generic address spaces. > > gcc/testsuite/ChangeLog: > > * gcc.target/i386/addr-space-3.c: New test case. > > Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org> > --- > gcc/gimple-array-bounds.cc | 3 +++ > gcc/testsuite/gcc.target/i386/addr-space-3.c | 5 +++++ > 2 files changed, 8 insertions(+) > create mode 100644 gcc/testsuite/gcc.target/i386/addr-space-3.c > > diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc > index 0517e5ddd8e..36fc1dbe3f8 100644 > --- a/gcc/gimple-array-bounds.cc > +++ b/gcc/gimple-array-bounds.cc > @@ -432,6 +432,9 @@ array_bounds_checker::check_mem_ref (location_t location, tree ref, > if (aref.offset_in_range (axssize)) > return false; > > + if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (axstype))) > + return false; > + > if (TREE_CODE (aref.ref) == SSA_NAME) > { > gimple *def = SSA_NAME_DEF_STMT (aref.ref); > diff --git a/gcc/testsuite/gcc.target/i386/addr-space-3.c b/gcc/testsuite/gcc.target/i386/addr-space-3.c > new file mode 100644 > index 00000000000..4bd940e696a > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/addr-space-3.c > @@ -0,0 +1,5 @@ > +/* Verify that __seg_fs/gs marked variables do not trigger an array bounds > + warning. */ > +/* { dg-do compile */ > +/* { dg-options "-O2 -Warray-bounds" } */ > +#include "addr-space-2.c" >
On 10/13/21 00:36, Martin Sebor wrote: > On 10/12/21 12:33 PM, Siddhesh Poyarekar wrote: >> The warning is falsely triggered for THREAD_SELF in glibc when >> accessing TCB through the segment register. > > Thanks for looking into it! The Glibc warning is being tracked > in PR 102630. The root cause behind it is in compute_objsize_r > in pointer-query.cc (which is used by -Warray-bounds as well as > other warnings). I just posted a patch for it the other day; > it's waiting for approval (though as Joseph noted, I need to > adjust the test and either make it target-independent or move > it under i386). Ahh, targetm.addr_space.zero_address_valid was what I was looking for and didn't find. Your fix looks good to me module moving the test out into gcc.target/i386. Thanks, Siddhesh
On Tue, Oct 12, 2021 at 8:34 PM Siddhesh Poyarekar <siddhesh@gotplt.org> wrote: > > The warning is falsely triggered for THREAD_SELF in glibc when > accessing TCB through the segment register. I think this is a more generic bug - the warning is also bogus if the general address space is involved. Martin? > gcc/ChangeLog: > > * gimple-array-bounds.cc > (array_bounds_checker::check_mem_ref): Bail out for > non-generic address spaces. > > gcc/testsuite/ChangeLog: > > * gcc.target/i386/addr-space-3.c: New test case. > > Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org> > --- > gcc/gimple-array-bounds.cc | 3 +++ > gcc/testsuite/gcc.target/i386/addr-space-3.c | 5 +++++ > 2 files changed, 8 insertions(+) > create mode 100644 gcc/testsuite/gcc.target/i386/addr-space-3.c > > diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc > index 0517e5ddd8e..36fc1dbe3f8 100644 > --- a/gcc/gimple-array-bounds.cc > +++ b/gcc/gimple-array-bounds.cc > @@ -432,6 +432,9 @@ array_bounds_checker::check_mem_ref (location_t location, tree ref, > if (aref.offset_in_range (axssize)) > return false; > > + if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (axstype))) > + return false; > + > if (TREE_CODE (aref.ref) == SSA_NAME) > { > gimple *def = SSA_NAME_DEF_STMT (aref.ref); > diff --git a/gcc/testsuite/gcc.target/i386/addr-space-3.c b/gcc/testsuite/gcc.target/i386/addr-space-3.c > new file mode 100644 > index 00000000000..4bd940e696a > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/addr-space-3.c > @@ -0,0 +1,5 @@ > +/* Verify that __seg_fs/gs marked variables do not trigger an array bounds > + warning. */ > +/* { dg-do compile */ > +/* { dg-options "-O2 -Warray-bounds" } */ > +#include "addr-space-2.c" > -- > 2.31.1 >
On 10/13/21 13:50, Richard Biener wrote: > On Tue, Oct 12, 2021 at 8:34 PM Siddhesh Poyarekar <siddhesh@gotplt.org> wrote: >> >> The warning is falsely triggered for THREAD_SELF in glibc when >> accessing TCB through the segment register. > > I think this is a more generic bug - the warning is also bogus if the > general address space is involved. I agree, Martin pointed me to a different fix that he posted earlier: https://patchwork.sourceware.org/project/gcc/patch/806cc630-86ef-2e3f-f72b-68bab2cd3e86@gmail.com/ Thanks, Siddhesh
diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc index 0517e5ddd8e..36fc1dbe3f8 100644 --- a/gcc/gimple-array-bounds.cc +++ b/gcc/gimple-array-bounds.cc @@ -432,6 +432,9 @@ array_bounds_checker::check_mem_ref (location_t location, tree ref, if (aref.offset_in_range (axssize)) return false; + if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (axstype))) + return false; + if (TREE_CODE (aref.ref) == SSA_NAME) { gimple *def = SSA_NAME_DEF_STMT (aref.ref); diff --git a/gcc/testsuite/gcc.target/i386/addr-space-3.c b/gcc/testsuite/gcc.target/i386/addr-space-3.c new file mode 100644 index 00000000000..4bd940e696a --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/addr-space-3.c @@ -0,0 +1,5 @@ +/* Verify that __seg_fs/gs marked variables do not trigger an array bounds + warning. */ +/* { dg-do compile */ +/* { dg-options "-O2 -Warray-bounds" } */ +#include "addr-space-2.c"