From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E7AC938425B4 for ; Fri, 29 Apr 2022 14:12:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E7AC938425B4 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-631-rsbBAKWzPne6Lzb97ikFIQ-1; Fri, 29 Apr 2022 10:12:39 -0400 X-MC-Unique: rsbBAKWzPne6Lzb97ikFIQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B262C1C0738B for ; Fri, 29 Apr 2022 14:12:38 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.17.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9433140FF694; Fri, 29 Apr 2022 14:12:38 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: fix ICE on invalid attributes [PR96637] Date: Fri, 29 Apr 2022 10:12:33 -0400 Message-Id: <20220429141233.41897-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham 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: Fri, 29 Apr 2022 14:12:42 -0000 This patch fixes crashes with invalid attributes. Arguably it could make sense to assert seen_error() too. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk = GCC 13? PR c++/96637 gcc/ChangeLog: * attribs.cc (decl_attributes): Check error_mark_node. gcc/cp/ChangeLog: * decl2.cc (cp_check_const_attributes): Check error_mark_node. gcc/testsuite/ChangeLog: * g++.dg/parse/error64.C: New test. --- gcc/attribs.cc | 3 +++ gcc/cp/decl2.cc | 2 ++ gcc/testsuite/g++.dg/parse/error64.C | 4 ++++ 3 files changed, 9 insertions(+) create mode 100644 gcc/testsuite/g++.dg/parse/error64.C diff --git a/gcc/attribs.cc b/gcc/attribs.cc index b219f878042..ff157dcf81c 100644 --- a/gcc/attribs.cc +++ b/gcc/attribs.cc @@ -700,6 +700,9 @@ decl_attributes (tree *node, tree attributes, int flags, in the same order as in the source. */ for (tree attr = attributes; attr; attr = TREE_CHAIN (attr)) { + if (attr == error_mark_node) + continue; + tree ns = get_attribute_namespace (attr); tree name = get_attribute_name (attr); tree args = TREE_VALUE (attr); diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index d2b29208ed5..c3ff1962a75 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -1537,6 +1537,8 @@ cp_check_const_attributes (tree attributes) /* As we implement alignas using gnu::aligned attribute and alignas argument is a constant expression, force manifestly constant evaluation of aligned attribute argument. */ + if (attr == error_mark_node) + continue; bool manifestly_const_eval = is_attribute_p ("aligned", get_attribute_name (attr)); for (arg = TREE_VALUE (attr); arg && TREE_CODE (arg) == TREE_LIST; diff --git a/gcc/testsuite/g++.dg/parse/error64.C b/gcc/testsuite/g++.dg/parse/error64.C new file mode 100644 index 00000000000..87848a58c27 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/error64.C @@ -0,0 +1,4 @@ +// PR c++/96637 +// { dg-do compile } + +void foo(int[] alignas[1] alignas(1)){} // { dg-error "" } base-commit: 9ae8b993cd362e8aea4f65580aaf1453120207f2 -- 2.35.1