Message ID | ZcpVz7goxYjQLYwY@tucnak |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp63500dyb; Mon, 12 Feb 2024 09:31:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVubMP1LZfSgD55PNJoGmONk5noDDgUT8JjcrlA0N1cuEVKAS/1arHDL1aiYQNaYVkccneclgRswRk8TjMsYhH07RteXg== X-Google-Smtp-Source: AGHT+IHYSC35UbnVawCzHGxW7DIfPEICo6E9ImcF69VJCbeKCEL8uf6Rdj9SLdwgRvqKacEOywAN X-Received: by 2002:a05:620a:b05:b0:785:ec1f:df6f with SMTP id t5-20020a05620a0b0500b00785ec1fdf6fmr1702843qkg.9.1707759115148; Mon, 12 Feb 2024 09:31:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707759115; cv=pass; d=google.com; s=arc-20160816; b=1CVH6/QW7iYVYjTLLslSC1k1jr+Uz57vnlf7K1+JcAMYvr+HJnY4I3APoFOGw+XNNm h9PDZN8tbeacUYlTIzKLhgjzgCRMMNp/rEG91qhuj2X2cwc2FVixFlvnI0JuYkYkblxC 2hhfxc/fkjeYS6CSgZi9Ip4XyJJdRo1MIhvYbF3f2vaviLoD8yqWdzs9xQ0Zax9XDMcC 7yT2nuB4Maldlvy76zGW0ChPbiNFQt7yhCKZSEs90dkNdv1QdhgI+b6EDoijnb7tP86J uYx/7abLSHrITUSyCIDfkIRN7zxHFLbv6swO2zlBmUbj2cbfLBxhfGuZlT7w2Kb3BksV 3vYA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=xWAYAAm8BKjeiMaa4xUIFyLdMhkiwKQUGSolm6KmNqk=; fh=6mb+psu4UphudVYwrtNz/7gHNWXkqJKYtkacinUOlGw=; b=QIzXk2EOJ8MXuTASbWfABHVERLc/HU+xitWz/ET0YDbquoXU1VHamQJgJo/bG/Li6N TkytWEk/U1xqzT3h15vARfVqlKWLAlWeCqwsyAHsJhGu92M4kkMc9OG1AEso9BPn2jvA lJF/uHDO/NKAgtxpQJ1tn0xSb4yoTAqgeidGWKwLMLA+zZP1BLGihUSZrpVzOis9NdgO zDfwuLngLtyVsdkaEoD/qpHYT5a+cuLLr6ttPnphkqyoPOxHL84eKfEQ+sbW+PaW+UWc 5FPhNLT72JpHRgEYQrDvrjC+Qrl5ZZiPMe9ZYw6o0QPWNBkzogkGDbwlaMcL/KNjlqlt EJyg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bef50N3l; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCVj/mORrR0LI9inaWODqFsKyWSGi6P7NmOOdEZFMDdAse3xxKCWsmoA4BuJ2qD04/9Y7P+JNiz1pUgqWuPZ3AB/4TB0mw== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a9-20020a05620a124900b0078553972245si6235575qkl.266.2024.02.12.09.31.55 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 09:31:55 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bef50N3l; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D6DD93858408 for <ouuuleilei@gmail.com>; Mon, 12 Feb 2024 17:31:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 7CCED385841C for <gcc-patches@gcc.gnu.org>; Mon, 12 Feb 2024 17:31:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7CCED385841C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7CCED385841C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707759064; cv=none; b=OJ36HPiQZP0I3FrttLwcRfqPN3QaIh6M6/WO2vJVfkT85U/WcRo2HRUi6NOQAO36GNC6iblMb+BeBxC4BXvR+IRDFmLvZJDu+w970WsmEyPuoniguCsEk/39CaFuOFO3tRffKz0iGx8yJaSklhqbuk9Nlu5UOyeiVq7o34Z7olc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707759064; c=relaxed/simple; bh=g1haf7hJisU7o5PqdHCi2vieoaF7IrAwyngTSzzlsD8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=bl+03rGCC2VzCn0A6LdThR3B+zF/lJnQcxY046h8CpGCWNzt/7keQrzspS+1c3EWaeWy1EAqr0WOqzSHulsnHC4uUJtRkYT4/nwxhFkDrct9obfg7oDSyFqQw9P7MpQy2dinHciYRSl9EAAdeVmw/yey08j6J4Vcxuc13B+6GYM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707759063; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=xWAYAAm8BKjeiMaa4xUIFyLdMhkiwKQUGSolm6KmNqk=; b=bef50N3lLo+ga/hcSoEYtP8daLHMC4CJX1aIu04pyee0CN4p2Aj2e6+lbK4QL29aZw4Gqw IsV+itc4/S75m/JM+p+xoG+3A8vt+4ZkF4jdx8spEsDTRN2tTY7ffW74dEJUx3bHKI6ykg BWWBEauOWhPUt47AIZ+msm/4ZzJeifo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-624-cItsS3STP2a_27bRRm1iHQ-1; Mon, 12 Feb 2024 12:30:59 -0500 X-MC-Unique: cItsS3STP2a_27bRRm1iHQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6E64D85A596; Mon, 12 Feb 2024 17:30:59 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2ECCC1C060AF; Mon, 12 Feb 2024 17:30:59 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 41CHUuxn2671556 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 12 Feb 2024 18:30:56 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 41CHUtcJ2671555; Mon, 12 Feb 2024 18:30:55 +0100 Date: Mon, 12 Feb 2024 18:30:55 +0100 From: Jakub Jelinek <jakub@redhat.com> To: Richard Biener <rguenther@suse.de>, "Joseph S. Myers" <josmyers@redhat.com>, Jason Merrill <jason@redhat.com> Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] attribs: Don't canonicalize lookup_scoped_attribute_spec argument [PR113674] Message-ID: <ZcpVz7goxYjQLYwY@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham 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.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Reply-To: Jakub Jelinek <jakub@redhat.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790715221645839336 X-GMAIL-MSGID: 1790715221645839336 |
Series |
attribs: Don't canonicalize lookup_scoped_attribute_spec argument [PR113674]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Jakub Jelinek
Feb. 12, 2024, 5:30 p.m. UTC
Hi! The C and C++ FEs when parsing attributes already canonicalize them (i.e. if they start with __ and end with __ substrings, we remove those). lookup_attribute already verifies in gcc_assert that the first character of name is not an underscore, and even lookup_scoped_attribute_spec doesn't attempt to canonicalize the namespace it is passed. But for some historic reason it was canonicalizing the name argument, which misbehaves when an attribute starts with ____ and ends with ____. I believe it is just wrong to try to canonicalize lookup_scope_attribute_spec name attribute, it should have been canonicalized already, in other spots where it is called it is already canonicalized before. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-02-12 Jakub Jelinek <jakub@redhat.com> PR c++/113674 * attribs.cc (extract_attribute_substring): Remove. (lookup_scoped_attribute_spec): Don't call it. * c-c++-common/Wattributes-3.c: New test. Jakub
Comments
On Mon, Feb 12, 2024 at 06:30:55PM +0100, Jakub Jelinek wrote: > Hi! > > The C and C++ FEs when parsing attributes already canonicalize them > (i.e. if they start with __ and end with __ substrings, we remove those). > lookup_attribute already verifies in gcc_assert that the first character > of name is not an underscore, and even lookup_scoped_attribute_spec doesn't > attempt to canonicalize the namespace it is passed. But for some historic > reason it was canonicalizing the name argument, which misbehaves when > an attribute starts with ____ and ends with ____. > I believe it is just wrong to try to canonicalize > lookup_scope_attribute_spec name attribute, it should have been > canonicalized already, in other spots where it is called it is already > canonicalized before. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Looks fine. extract_attribute_substring was added in https://gcc.gnu.org/pipermail/gcc-patches/2007-July/221563.html but with no tests. I see that without it gcc.dg/attr-noinline.c was failing, but that hasn't been the case for many years now. So I don't know why it would be necessary to keep it. Marek
On Mon, Feb 12, 2024 at 01:15:55PM -0500, Marek Polacek wrote: > On Mon, Feb 12, 2024 at 06:30:55PM +0100, Jakub Jelinek wrote: > > The C and C++ FEs when parsing attributes already canonicalize them > > (i.e. if they start with __ and end with __ substrings, we remove those). > > lookup_attribute already verifies in gcc_assert that the first character > > of name is not an underscore, and even lookup_scoped_attribute_spec doesn't > > attempt to canonicalize the namespace it is passed. But for some historic > > reason it was canonicalizing the name argument, which misbehaves when > > an attribute starts with ____ and ends with ____. > > I believe it is just wrong to try to canonicalize > > lookup_scope_attribute_spec name attribute, it should have been > > canonicalized already, in other spots where it is called it is already > > canonicalized before. > > > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > Looks fine. extract_attribute_substring was added in > https://gcc.gnu.org/pipermail/gcc-patches/2007-July/221563.html > but with no tests. I see that without it gcc.dg/attr-noinline.c > was failing, but that hasn't been the case for many years now. So > I don't know why it would be necessary to keep it. I think it was added far before Martin's changes to canonicalize attributes in r8-2418. At that point attributes in the attributes lists weren't canonicalized, so it was necessary to canonicalize them before or during the lookups. Jakub
On 2/12/24 12:30, Jakub Jelinek wrote: > Hi! > > The C and C++ FEs when parsing attributes already canonicalize them > (i.e. if they start with __ and end with __ substrings, we remove those). > lookup_attribute already verifies in gcc_assert that the first character > of name is not an underscore, and even lookup_scoped_attribute_spec doesn't > attempt to canonicalize the namespace it is passed. But for some historic > reason it was canonicalizing the name argument, which misbehaves when > an attribute starts with ____ and ends with ____. > I believe it is just wrong to try to canonicalize > lookup_scope_attribute_spec name attribute, it should have been > canonicalized already, in other spots where it is called it is already > canonicalized before. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK. > 2024-02-12 Jakub Jelinek <jakub@redhat.com> > > PR c++/113674 > * attribs.cc (extract_attribute_substring): Remove. > (lookup_scoped_attribute_spec): Don't call it. > > * c-c++-common/Wattributes-3.c: New test. > > --- gcc/attribs.cc.jj 2024-01-03 11:51:39.392622088 +0100 > +++ gcc/attribs.cc 2024-02-12 12:50:00.660458907 +0100 > @@ -116,15 +116,6 @@ get_gnu_namespace () > return gnu_namespace_cache; > } > > -/* Return base name of the attribute. Ie '__attr__' is turned into 'attr'. > - To avoid need for copying, we simply return length of the string. */ > - > -static void > -extract_attribute_substring (struct substring *str) > -{ > - canonicalize_attr_name (str->str, str->length); > -} > - > /* Insert SPECS into its namespace. IGNORED_P is true iff all unknown > attributes in this namespace should be ignored for the purposes of > -Wattributes. The function returns the namespace into which the > @@ -398,7 +389,6 @@ lookup_scoped_attribute_spec (const_tree > > attr.str = IDENTIFIER_POINTER (name); > attr.length = IDENTIFIER_LENGTH (name); > - extract_attribute_substring (&attr); > return attrs->attribute_hash->find_with_hash (&attr, > substring_hash (attr.str, > attr.length)); > --- gcc/testsuite/c-c++-common/Wattributes-3.c.jj 2024-02-12 13:04:21.964502985 +0100 > +++ gcc/testsuite/c-c++-common/Wattributes-3.c 2024-02-12 13:06:32.659688900 +0100 > @@ -0,0 +1,13 @@ > +/* PR c++/113674 */ > +/* { dg-do compile { target { c || c++11 } } } */ > +/* { dg-options "" } */ > + > +[[____noreturn____]] int foo (int i) /* { dg-warning "'__noreturn__' attribute (directive )?ignored" } */ > +{ > + return i; > +} > + > +[[____maybe_unused____]] int bar (int i) /* { dg-warning "'__maybe_unused__' attribute (directive )?ignored" } */ > +{ > + return i; > +} > > Jakub >
--- gcc/attribs.cc.jj 2024-01-03 11:51:39.392622088 +0100 +++ gcc/attribs.cc 2024-02-12 12:50:00.660458907 +0100 @@ -116,15 +116,6 @@ get_gnu_namespace () return gnu_namespace_cache; } -/* Return base name of the attribute. Ie '__attr__' is turned into 'attr'. - To avoid need for copying, we simply return length of the string. */ - -static void -extract_attribute_substring (struct substring *str) -{ - canonicalize_attr_name (str->str, str->length); -} - /* Insert SPECS into its namespace. IGNORED_P is true iff all unknown attributes in this namespace should be ignored for the purposes of -Wattributes. The function returns the namespace into which the @@ -398,7 +389,6 @@ lookup_scoped_attribute_spec (const_tree attr.str = IDENTIFIER_POINTER (name); attr.length = IDENTIFIER_LENGTH (name); - extract_attribute_substring (&attr); return attrs->attribute_hash->find_with_hash (&attr, substring_hash (attr.str, attr.length)); --- gcc/testsuite/c-c++-common/Wattributes-3.c.jj 2024-02-12 13:04:21.964502985 +0100 +++ gcc/testsuite/c-c++-common/Wattributes-3.c 2024-02-12 13:06:32.659688900 +0100 @@ -0,0 +1,13 @@ +/* PR c++/113674 */ +/* { dg-do compile { target { c || c++11 } } } */ +/* { dg-options "" } */ + +[[____noreturn____]] int foo (int i) /* { dg-warning "'__noreturn__' attribute (directive )?ignored" } */ +{ + return i; +} + +[[____maybe_unused____]] int bar (int i) /* { dg-warning "'__maybe_unused__' attribute (directive )?ignored" } */ +{ + return i; +}