From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 9B157384F03B for ; Thu, 12 Aug 2021 16:58:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B157384F03B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: TU7ZIIsSYNznaE1bxaByaDVrw3l3G8oNDw0u+tNx2Zt+LmDV6AgEP89QnOxh3OHd58jSI5OOr7 6l6xGWmonOtnQ3mhgzAEvcj2h4sAkhSiF5b30EnJjV5pClGrgodwLxoJsloCB2wY28szfuSLab 1c2vmGcQMUIQgLJ9Czr/NWyO7xZTDdzle4eN5XHEfSKNZV276GRlhHGRJe08k76oiFJr2y13y5 XdA12uYoc8/VDP7thCkgvH2oBPyK28CTjTeYuG2/ems65x4C1I/LRqMIZyeUMmdSa3huRANE2R tKEdMgWapwb2jSNm3fZbFrqJ X-IronPort-AV: E=Sophos;i="5.84,316,1620720000"; d="scan'208";a="64590334" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 12 Aug 2021 08:58:46 -0800 IronPort-SDR: VY3A4P36ALpSUtMsCg9s6wotYh4dgEXN5V4WOkzdl0NW5EFj4zVQRhdXoBQT4wE2WYsFx3GpzN BaCLk+utpndDnh5rdZ+56kMw4l/PGYBgJ18YG2ha2jcZO30r0gf0g2b2R3DZDeRBGnOxoYTGkN HdIMCXG2TyLKaaNpYdgd2oW6l+s/WYlw5pJNG39bWU+P9yGl5HvuU/KJ0fGMLQKvQ2aVdxVDD3 S2eAETwo6oD1RdYDZYKMTqnwu9DX/mT4skiGhNOgxPvt0F75QgkbjGi8DaeEdrGeHE3xdkhgz5 z8Q= Date: Thu, 12 Aug 2021 16:58:40 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: "Uecker, Martin" CC: "gcc-patches@gcc.gnu.org" Subject: Re: [C PATCH] qualifiers of pointers to arrays in C2X [PR 98397] In-Reply-To: <5690541802513d86355283933c811c171410543e.camel@med.uni-goettingen.de> Message-ID: References: <5690541802513d86355283933c811c171410543e.camel@med.uni-goettingen.de> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-3119.1 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.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: Thu, 12 Aug 2021 16:58:48 -0000 On Mon, 24 May 2021, Uecker, Martin wrote: > - else if (VOID_TYPE_P (TREE_TYPE (type1)) > - && !TYPE_ATOMIC (TREE_TYPE (type1))) > - { > - if ((TREE_CODE (TREE_TYPE (type2)) == ARRAY_TYPE) > - && (TYPE_QUALS (strip_array_types (TREE_TYPE (type2))) > - & ~TYPE_QUALS (TREE_TYPE (type1)))) > - warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers, > - "pointer to array loses qualifier " > - "in conditional expression"); > - > - if (TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE) > + else if ((VOID_TYPE_P (TREE_TYPE (type1)) > + && !TYPE_ATOMIC (TREE_TYPE (type1))) > + || (VOID_TYPE_P (TREE_TYPE (type2)) > + && !TYPE_ATOMIC (TREE_TYPE (type2)))) Here you're unifying the two cases where one argument is (not a null pointer constant and) a pointer to qualified or unqualified void (and the other argument is not a pointer to qualified or unqualified void). The !TYPE_ATOMIC checks are because of the general rule that _Atomic is a type qualifier only syntactically, so _Atomic void doesn't count as qualified void for this purpose. > + { > + tree t1 = TREE_TYPE (type1); > + tree t2 = TREE_TYPE (type2); > + if (!VOID_TYPE_P (t1)) > + { > + /* roles are swapped */ > + t1 = t2; > + t2 = TREE_TYPE (type1); > + } But here you don't have a TYPE_ATOMIC check before swapping. So if t1 is _Atomic void and t2 is void, the types don't get swapped. > + /* for array, use qualifiers of element type */ > + if (flag_isoc2x) > + t2 = t2_stripped; > + result_type = build_pointer_type (qualify_type (t1, t2)); And then it looks to me like this will end up with _Atomic void * as the result type, when a conditional expression between _Atomic void * and void * should actually have type void *. If that's indeed the case, I think the swapping needs to occur whenever t1 is not *non-atomic* void, so that the condition for swapping matches the condition checked in the outer if. (And of course there should be a testcase for that.) I didn't see any other issues in this version of the patch. -- Joseph S. Myers joseph@codesourcery.com