From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by sourceware.org (Postfix) with ESMTPS id 5D601384D1B0 for ; Wed, 29 Jun 2022 21:14:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5D601384D1B0 Received: by mail-io1-xd2d.google.com with SMTP id d3so769862ioi.9 for ; Wed, 29 Jun 2022 14:14:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:from :subject:to:cc:references:content-language:in-reply-to :content-transfer-encoding; bh=kfiCnE8pCdb1WoBhfBN94SpCCm8ZruMMKgoJiQOXJRA=; b=j6sAHq+jzVsKJ2UoVXY5uDgJcFlD69dwCcGrFad5tTzVAZX3XG1TFDU38FvHHPE6nl lgtrpYqVIfIWO1ciKOf3bfxTeRv9q9Lbas3M6K1GfS2Gag1+cgUICo3UWXkWAPm9QH+P ruq9yYBMp5POFm/s11tPIkl9A9NghziL+ZrBBImaEvD/TQylKM7jU367UKXPz3nH7/xt sp4ZlvJseaRonFnzOI2+RV6oFgQmP8gOVQrgzc0fAbNvPxftq9oZIgBlpTAjwJ9Bl8Nw TJJV85cWJSu8IvCHe3bOWYL2KCearA5/LH8OFKqLCaWcjzH+/M4ENvWeHcfg3aKwEfmw i38g== X-Gm-Message-State: AJIora86Euu5p30k0eroAATxQHNb7YYhZrtN+vCP77bAR3J+DYb4Ek0N NPu3l8Wv1YPPhVZEa7Q+cLg= X-Google-Smtp-Source: AGRyM1ullhtBbJIdVW7MIefpmf2dHLjNnXUGn35g+gyXz/I7UemKfUO83f/ZkPMAlfzBlBo2OIJTsA== X-Received: by 2002:a05:6602:3298:b0:675:7d23:6643 with SMTP id d24-20020a056602329800b006757d236643mr2608591ioz.143.1656537287570; Wed, 29 Jun 2022 14:14:47 -0700 (PDT) Received: from [192.168.0.41] (184-96-231-56.hlrn.qwest.net. [184.96.231.56]) by smtp.gmail.com with ESMTPSA id y41-20020a02952c000000b00339e1b107d9sm7736837jah.60.2022.06.29.14.14.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jun 2022 14:14:47 -0700 (PDT) Message-ID: Date: Wed, 29 Jun 2022 15:14:46 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 From: Martin Sebor Subject: Re: [GCC 13][PATCH] PR101836: Add a new option -fstrict-flex-array[=n] and use it in __builtin_object_size To: Qing Zhao , Jakub Jelinek Cc: gcc-patches Paul A Clarke via , kees Cook References: <45936DE9-4099-4ED2-8B2B-6956A2FB493D@oracle.com> <5281C7CE-2677-4FE3-8ED3-C5B378685DCB@oracle.com> <2DDA999B-58B1-4390-9E2E-C4D68C0FD913@oracle.com> <865160D2-76C2-4B90-BD42-0CA676E6D3F0@oracle.com> <529B0DDA-852A-4E32-AF69-67080A7FEFD6@oracle.com> Content-Language: en-US In-Reply-To: <529B0DDA-852A-4E32-AF69-67080A7FEFD6@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, NICE_REPLY_A, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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-List-Received-Date: Wed, 29 Jun 2022 21:14:52 -0000 On 6/28/22 13:01, Qing Zhao wrote: > > >> On Jun 28, 2022, at 2:49 PM, Jakub Jelinek wrote: >> >> On Tue, Jun 28, 2022 at 06:29:01PM +0000, Qing Zhao wrote: >>> >>> >>>> On Jun 28, 2022, at 2:22 PM, Jakub Jelinek wrote: >>>> >>>> On Tue, Jun 28, 2022 at 06:15:58PM +0000, Qing Zhao wrote: >>>>>> Because the flag just tells whether some array shouldn't be treated as (poor man's) >>>>>> flexible array member. We still need to find out if some FIELD_DECL is to >>>>>> be treated like a flexible array member, which is a minority of >>>>>> COMPONENT_REFs. >>>>>> struct S { int a; char b[0]; int c; } s; >>>>>> struct T { int d; char e[]; }; >>>>>> struct U { int f; struct T g; int h; } u; >>>>>> Neither s.b nor u.g.e is to be treated like flexible array member, >>>>>> no matter what -fstrict-flex-array= option is used. >>>>> >>>>> Then, to resolve this issue, we might need a opposite flag DECL_IS_FLEXARRAY in FIELD_DECL? >>>>> >>>>> The default is FALSE for all FIELD_DECL. >>>> >>>> Doesn't matter whether it is positive or negative, you still need to analyze >>>> it. See the above example. If you have struct T t; and test t.e, then it >>>> is flexarray. But u.g.e is not, even when the COMPONENT_REF refers to the >>>> same FIELD_DECL. In the t.e case e is the very last field, in the latter >>>> case u.g.e is the last field in struct T, but struct U has the h field after >>> >>> So, do you mean that the current FE analysis will not be able to decide whether a specific array field is at the end of the enclosing structure? >>> Only the middle end can decide this ? >> >> Well, anything that analyzes it, can be in the FE or middle-end, but there >> is no place to store it for later. > > Then I am a little confused: > > If the FE can decide wether an array field is at the end of the enclosing structure, then combined with whether it’s a [0], [1] or [], and which level of -fstrict-flex-array, > > The FE should be able to decide whether this array field is a flexible array member or not, then set the flag DECL_IS_FLEXARRAY (or DECL_NOT_FLEXARRAY). > > The new flag is the place to store such info, right? > Do I miss anything here? I think the problem is that there is just one FIELD_DECL for member M of a given type T but there can be more than one instance of that member, one in each struct that has a subobject of T as its own member. Whether M is or isn't a (valid) flexible array member varies between the two instances. Martin