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: 1897854 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bef50N3l; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TYWhv4p35z23hM for ; Tue, 13 Feb 2024 04:31:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7CA85385840B for ; Mon, 12 Feb 2024 17:31:25 +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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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; +}