From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 06A7E3858D3C for ; Tue, 3 May 2022 22:32:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 06A7E3858D3C 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.91,196,1647331200"; d="scan'208";a="77902269" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 03 May 2022 14:32:48 -0800 IronPort-SDR: 43r8ThFfxWotekIhjagRkl8syfg9A4a+iv5XEq8Lkd0ZR3Ox/kHbozDA3t1X+RsVOGRQ+av/D0 k6NAo3H6YgXbgwyWLobV5JyEq8FP+rPEMOMf7sw3Wz8CVUu7+aPLMp3dc6IVtDccHHACQq7At/ LHyoCXJPYb6smm+iM/snWG7opm7trG5103AFm9HnJ1tGXGBUpuZxXEhaWK6rtjjjsT9wlW4hMO P61p6iXbWUwnXrxTb2Lx4An31qQVOhRMDqKS1Szpx6ZboUd2noK331OiTDnwHigsBJW/+2eBTL C/0= Date: Tue, 3 May 2022 22:32:44 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: David Faust CC: , Yonghong Song Subject: Re: [ping2][PATCH 0/8][RFC] Support BTF decl_tag and type_tag annotations In-Reply-To: Message-ID: References: <20220401194216.16469-1-david.faust@oracle.com> 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-05.mgc.mentorg.com (139.181.222.5) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-3113.5 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: Tue, 03 May 2022 22:32:52 -0000 On Mon, 2 May 2022, David Faust via Gcc-patches wrote: > Consider the following example: > > #define __typetag1 __attribute__((btf_type_tag("tag1"))) > #define __typetag2 __attribute__((btf_type_tag("tag2"))) > #define __typetag3 __attribute__((btf_type_tag("tag3"))) > > int __typetag1 * __typetag2 __typetag3 * g; > > The expected behavior is that 'g' is "a pointer with tags 'tag2' and 'tag3', > to a pointer with tag 'tag1' to an int". i.e.: That's not a correct expectation for either GNU __attribute__ or C2x [[]] attribute syntax. In either syntax, __typetag2 __typetag3 should apply to the type to which g points, not to g or its type, just as if you had a type qualifier there. You'd need to put the attributes (or qualifier) after the *, not before, to make them apply to the pointer type. See "Attribute Syntax" in the GCC manual for how the syntax is defined for GNU attributes and deduce in turn, for each subsequence of the tokens matching the syntax for some kind of declarator, what the type for "T D1" would be as defined there and in the C standard, as deduced from the type for "T D" for a sub-declarator D. > But GCC's attribute parsing produces a variable 'g' which is "a pointer with > tag 'tag1' to a pointer with tags 'tag2' and 'tag3' to an int", i.e. In GNU syntax, __typetag1 applies to the declaration, whereas in C2x syntax it applies to int. Again, if you wanted it to apply to the pointer type it would need to go after the * not before. If you are concerned with the fine details of what construct an attribute appertains to, I recommend using C2x syntax not GNU syntax. -- Joseph S. Myers joseph@codesourcery.com