From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by sourceware.org (Postfix) with ESMTPS id 4F89F3858C60 for ; Tue, 12 Oct 2021 19:06:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4F89F3858C60 Received: by mail-qv1-xf2a.google.com with SMTP id o13so303452qvm.4 for ; Tue, 12 Oct 2021 12:06:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=OgOwdtOdEXOjEG6Acbb4Walh5Jg5fWRv82EVHq5d6jk=; b=egxWkubXCUO4JwCqstzcM0tkW9LQ7hxKjIYFAMrTzxx7JnHI8fEyh40m4Rl3ghPezS 0z79MZ4cQ+9MGjeroJzoJbQcfSiSKtciS2B5eON+O/sr+2vLuyzK6PjqIGQgctyTMZ92 8qTwnfZzGi7kx+BWCmP+I2ct+LtDxVpISaOgolUDb/eQ9Tlio3vZ9ll6RtKbmMFIZb6R 4Z1aJpsBPTGdHFQsYP3f5oQNptNrhRG+w0rxpq1neCipas83IXK4p387tnYRzNjgT5LZ 0fiDhkHXhR70n3T5Pasr7ZvpxvRaaTKw3mJeLUE86uk2qIIp3326sGEDnUyszwdn2OvI bRfQ== X-Gm-Message-State: AOAM533n+23UBUiqlRpHf37mNKg68Q43bF5a/bFsBPXFci43kdZbxMi2 hGSNRoOSYRt8BO86P/OGem4= X-Google-Smtp-Source: ABdhPJwbd0P1u+02HjigHemJTIGrYiuMzd5o0GVOen/jsA7DIqR56WZMn4NhZAkJ4vQh3+EHxtbXVg== X-Received: by 2002:a05:6214:27ca:: with SMTP id ge10mr31632131qvb.50.1634065565884; Tue, 12 Oct 2021 12:06:05 -0700 (PDT) Received: from [192.168.0.41] (184-96-250-116.hlrn.qwest.net. [184.96.250.116]) by smtp.gmail.com with ESMTPSA id b20sm7312898qtx.89.2021.10.12.12.06.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Oct 2021 12:06:05 -0700 (PDT) Subject: Re: [PATCH] Warray-bounds: Warn only for generic address spaces To: Siddhesh Poyarekar , gcc-patches@gcc.gnu.org Cc: msebor@redhat.com References: <20211012183347.385794-1-siddhesh@gotplt.org> From: Martin Sebor Message-ID: <7d64e765-0bbe-2ff1-be2e-323194e09450@gmail.com> Date: Tue, 12 Oct 2021 13:06:04 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20211012183347.385794-1-siddhesh@gotplt.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Oct 2021 19:06:08 -0000 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 > --- > 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" >