From patchwork Fri Nov 3 19:12:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 161414 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1259483vqu; Fri, 3 Nov 2023 12:12:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGCKg4wRe1iPBALJvQKkSIimtiN7JK9zrpfdp1GlE+uj6MdLto+HqAp5z77stPmb4nfeuN5 X-Received: by 2002:a05:6214:1bcc:b0:65b:ed3:9a02 with SMTP id m12-20020a0562141bcc00b0065b0ed39a02mr29345499qvc.17.1699038762562; Fri, 03 Nov 2023 12:12:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1699038762; cv=pass; d=google.com; s=arc-20160816; b=lxfme20Dq4wkGzq2exGMKkATmEQlhvIaYTMzcVcDUk2buaIGEeHLlF3LedUms+uG+T XoN8aaowQ1V/ZslFWKs+kHYKy9jgjk3ivP8TAxFue8MQOPMg3OADk1i79cjOPkH1uEZv WdqfGLxgGCPGFiGH1yp2V7WQhkdL2OujjcM6deNYY/lf292+gGo6j3bpFLau4hmIYp7k 2ezyh7L4AxM7vzc+QZThegkGwc5tUCYzJdDjMgu8RvaQ2bBlgUMkJFxqDey6Jt3U+Z8P 5TERyJv5OHhfuRTvPZLZFutCtbDYD+MQreVeGU27Q7fHEyZkWBfi5EZzcxtrM4vriOtj ejCw== 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=WkvpnOqB54fAOj2dhJHoXUaLUTYxqtDrVxD5T21FUjM=; fh=m7+AFjtMHmY1VH/2i/gazAmSZUYZ+OGccUIZLGLtbCM=; b=X9b1iRdq+USoVu1gRC83YqdBmK2GupJkwq51Qksi0VA/iSTVI0AtKFaeASU53gAtAF LhTwODPkyJnxB7SpF37UhkL1OlaROFNchQ34mG2Bbni2o01PFDS994cINzCn2Tk9dnrN fpNxQhV+amrz0C21N1xm8rgpRGU132+NKAozrV+OJEHr3vgw5E9xj2T+AewA4kCZPI4z JJvJndh6+8Vw26OthwqZutxCqHKznY5oBXF+qf8N8dKqsJYUxXNJfanyGv82+asvrsgE NaH2W5mRx6SJcmnpjqG/PS2u0ehOhKYFM/L5niwKlos8xlA8eeRCCfxUpbKTpHqY1Uys yEqQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PD+QweZN; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b4-20020a056214114400b0065b12b1d559si1898032qvt.284.2023.11.03.12.12.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 12:12:42 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PD+QweZN; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 55F08385842A for ; Fri, 3 Nov 2023 19:12:42 +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 CBF7D3858D28 for ; Fri, 3 Nov 2023 19:12:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CBF7D3858D28 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 CBF7D3858D28 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=1699038740; cv=none; b=KpQMH9SJFGIlL8jnb+TG5o7/AyTC17ZuPJR9BGt53HhkPf7ZstVG6mTCRKXdZMHGlHthbgPC3A2lYWJNp5UBkal81Vv6zvGn2gHiX/aDZOO5kmwUAwONgqypAE6buHoG5Pc/qDR/fF+RKRhDNNNYrNFZLE72IZTqEWOXM9MRkfw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699038740; c=relaxed/simple; bh=0ymlqUArOqdVnqEJCMcuDT/unoNa5pvTGzPv2TT6Ai8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=HSEBhs5871iTojVU/fwHePczFPc2yYGTOo4+kTxlrswL5RaNOAM9ecWi5r2Ymbf/z67VknzhkiSjMnqWpK33CH8Azm/R8LaD3lUm1Ny71OilVDPTPaIvCFuUg1/AojAy7zlQ4NJBTF2NTT8PekLajzeoPzuK12hg0JIYG5xDbZg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699038729; 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=WkvpnOqB54fAOj2dhJHoXUaLUTYxqtDrVxD5T21FUjM=; b=PD+QweZNeZaULTwvKmqS43ZB6xx2eVTwDAaCMM6fN7Vzbeg5KtzavWcW48jqjz++aanEO4 BjMfDxRgsqdGdONeM98IHOC6GTdSi+HMTX4j04/77MZ8AfCSHjlRGKZGewIpRcgnC5rcEy 7qL4awmj4gBCkXqFWO2TmAb7jl6NHEs= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-298-7EVyg_cMOomEe93ZVXbKfA-1; Fri, 03 Nov 2023 15:12:08 -0400 X-MC-Unique: 7EVyg_cMOomEe93ZVXbKfA-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 020593812582; Fri, 3 Nov 2023 19:12:08 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 97C651C060BA; Fri, 3 Nov 2023 19:12:07 +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 3A3JC5JA3479845 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 3 Nov 2023 20:12:05 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3A3JC3Ff3479844; Fri, 3 Nov 2023 20:12:03 +0100 Date: Fri, 3 Nov 2023 20:12:03 +0100 From: Jakub Jelinek To: Jason Merrill , "Joseph S. Myers" , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] attribs: Fix ICE with -Wno-attributes= [PR112339] 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.9 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_H3, 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: 1781571269626784849 X-GMAIL-MSGID: 1781571269626784849 Hi! The following testcase ICEs, because with -Wno-attributes=foo::no_sanitize (but generally any other non-gnu namespace and some gnu well known attribute name within that other namespace) the FEs don't really parse attribute arguments of such attribute, but lookup_attribute_spec is non-NULL with NULL handler and such attributes are added to DECL_ATTRIBUTES or TYPE_ATTRIBUTES and then when e.g. middle-end does lookup_attribute on a particular attribute and expects the attribute to mean something and/or have a particular verified arguments, it can crash when seeing the foreign attribute in there instead. The following patch fixes that by never adding ignored attributes to DECL_ATTRIBUTES/TYPE_ATTRIBUTES, previously that was the case just for attributes in ignored namespace (where lookup_attribute_space returned NULL). We don't really know anything about those attributes, so shouldn't pretend we know something about them, especially when the arguments are error_mark_node or NULL instead of something that would have been parsed. And it would be really weird if we normally ignore say [[clang::unused]] attribute, but when people use -Wno-attributes=clang::unused we actually treated it as gnu::unused. All the user asked for is suppress warnings about that attribute being unknown. The first hunk is just playing safe, I'm worried people could -Wno-attributes=gnu:: and get various crashes with known GNU attributes not being actually parsed and recorded (or worse e.g. when we tweak standard attributes into GNU attributes and we wouldn't add those). The -Wno-attributes= documentation says that it suppresses warning about unknown attributes, so I think -Wno-attributes=gnu:: should prevent warning about say [[gnu::foobarbaz]] attribute, but not about [[gnu::unused]] because the latter is a known attribute. The routine would return true for any scoped attribute in the ignored namespace, with the change it ignores only unknown attributes in ignored namespace, known ones in there will be ignored only if they have max_length of -2 (e.g.. with -Wno-attributes=gnu:: -Wno-attributes=gnu::foobarbaz). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-11-03 Jakub Jelinek PR c/112339 * attribs.cc (attribute_ignored_p): Only return true for attr_namespace_ignored_p if as is NULL. (decl_attributes): Never add ignored attributes. * c-c++-common/ubsan/Wno-attributes-1.c: New test. Jakub --- gcc/attribs.cc.jj 2023-11-02 20:22:02.017016371 +0100 +++ gcc/attribs.cc 2023-11-03 08:45:32.688726738 +0100 @@ -579,9 +579,9 @@ attribute_ignored_p (tree attr) return false; if (tree ns = get_attribute_namespace (attr)) { - if (attr_namespace_ignored_p (ns)) - return true; const attribute_spec *as = lookup_attribute_spec (TREE_PURPOSE (attr)); + if (as == NULL && attr_namespace_ignored_p (ns)) + return true; if (as && as->max_length == -2) return true; } @@ -862,7 +862,10 @@ decl_attributes (tree *node, tree attrib } } - if (no_add_attrs) + if (no_add_attrs + /* Don't add attributes registered just for -Wno-attributes=foo::bar + purposes. */ + || attribute_ignored_p (attr)) continue; if (spec->handler != NULL) --- gcc/testsuite/c-c++-common/ubsan/Wno-attributes-1.c.jj 2023-11-03 08:44:13.752837201 +0100 +++ gcc/testsuite/c-c++-common/ubsan/Wno-attributes-1.c 2023-11-03 08:44:13.751837215 +0100 @@ -0,0 +1,9 @@ +/* PR c/112339 */ +/* { dg-do compile { target { c++11 || c } } } */ +/* { dg-options "-Wno-attributes=foo::no_sanitize -fsanitize=undefined" } */ +/* { dg-additional-options "-std=c2x" { target c } } */ + +[[foo::no_sanitize("bounds")]] void +foo (void) +{ +}