From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 3C3B83858D33 for ; Tue, 7 Feb 2023 23:37:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C3B83858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.97,279,1669104000"; d="scan'208";a="96151119" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 07 Feb 2023 15:37:16 -0800 IronPort-SDR: dX8rgcgGsnrXerqoloDPWJSeypp8zOkmt56eKYsCFGwi3LQuCcNWKHLKS4wI3fhx08VPj24sp/ B6CI0FFiLtZ7WzmptSZw5OugzaWqrIZdcoREWBblOoEp90EYcam0FKz5dtTeF/G0TJ5qVseCx1 7u5VsV9szHfYoWmk9BQJwPn7tMdgBdaQnnbU5UAJSc/Ow2JM5IQpLj3v1og4W2TWdiQKHkWkJN C29Q/CQYEGTvXPz4Du48kEIzJw7x6pyU+56hMbuvKhnyAQdxTry8DlpBXl/5ZIflML45N+YNgg 0sc= Date: Tue, 7 Feb 2023 23:37:07 +0000 From: Joseph Myers To: Qing Zhao CC: Richard Biener , "gcc-patches@gcc.gnu.org" , "siddhesh@gotplt.org" , "keescook@chromium.org" Subject: Re: [PATCH 1/2] Handle component_ref to a structre/union field including flexible array member [PR101832] In-Reply-To: <91678405-D50E-405A-98FB-F3BA6888577E@oracle.com> Message-ID: References: <20230131141140.3610133-1-qing.zhao@oracle.com> <20230131141140.3610133-2-qing.zhao@oracle.com> <812910BC-870E-4432-870D-538024F1A510@oracle.com> <3B30CFBF-5004-41A4-940D-1F23C010403B@oracle.com> <4E515AA5-2069-497E-A301-EC8ED744E780@oracle.com> <367EBE15-1675-4D29-A9C2-A4A57FA4DB62@oracle.com> <2184ee29-9a36-e85-11c5-81c47aa22055@codesourcery.com> <91678405-D50E-405A-98FB-F3BA6888577E@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-3108.5 required=5.0 tests=BAYES_00,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, 7 Feb 2023, Qing Zhao via Gcc-patches wrote: > Then, this routine (flexible_array_type_p) is mainly for diagnostic purpose. > It cannot be used to determine whether the structure/union type recursively > include a flexible array member at the end. > > Is my understanding correct? My comments were about basic principles of what gets diagnosed, and the need for different predicates in different contexts; I wasn't trying to assert anything about how that maps onto what functions should be used in what contexts. > >> 2. Only C99 standard flexible array member be included, [0] and [1] are > >> not included, for example: > > > > Obviously we can't diagnose use of structures with [1] trailing members, > > because it's perfectly valid to embed those structures at any position > > inside other structures. And the same is the case for the [0] extension > > when it's used to mean "empty array" rather than "flexible array". > > With the -fstrict-flex-arrays available, we should be able to diagnose > the flexible array member per gnu extension (i.e [0] or [1]) the same as []. There are different sorts of diagnostic that might be involved. * Simply having [0] or [1] at the end of a structure embedded in another structure isn't appropriate to diagnose, because [0] and [1] have perfectly good meanings in such a context that aren't trying to be flexible array members at all. [0] might be an empty type (possibly one that wouldn't be empty when built with a different configuration). [1] might be the use of arrays in C to produce a passed-by-reference type. * Trying to use such an embedded [0] or [1] array as if it were a flexible array member - i.e. accessing any member of the [0] array, or any member other than the [0] member of the [1] array - *is* a sign of the problematic use as a flexible array member, that might be appropriate to diagnose. (Actually I'd guess the array index tends to be non-constant in accesses, and it would be odd to use a non-constant index when you mean that constant always to be 0, which it would need to be in the non-flexible case.) -- Joseph S. Myers joseph@codesourcery.com