From patchwork Mon Feb 12 17:30:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 199947 Return-Path: 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 (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 ; 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 ; 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 To: Richard Biener , "Joseph S. Myers" , Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] attribs: Don't canonicalize lookup_scoped_attribute_spec argument [PR113674] Message-ID: 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-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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek 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 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 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 --- 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; +}