From patchwork Fri Nov 1 09:07:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Martin X-Patchwork-Id: 2005024 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=nasilyan.com header.i=@nasilyan.com header.a=rsa-sha256 header.s=tey23rxsjton5kop5bydp3vc5ylkyjkg header.b=t6WsCvzW; dkim=pass (1024-bit key; unprotected) header.d=amazonses.com header.i=@amazonses.com header.a=rsa-sha256 header.s=uku4taia5b5tsbglxyj6zym32efj7xqv header.b=GxWSV2Gy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Xfw5n1gzjz1xwF for ; Fri, 1 Nov 2024 20:08:59 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B01303858402 for ; Fri, 1 Nov 2024 09:08:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from a7-18.smtp-out.eu-west-1.amazonses.com (a7-18.smtp-out.eu-west-1.amazonses.com [54.240.7.18]) by sourceware.org (Postfix) with ESMTPS id 406EB3858C78 for ; Fri, 1 Nov 2024 09:08:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 406EB3858C78 Authentication-Results: sourceware.org; dmarc=fail (p=quarantine dis=none) header.from=nasilyan.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eu-west-1.amazonses.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 406EB3858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.240.7.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730452098; cv=none; b=VFcO/bOuBx9SobWb6n28+Cr2iauqFPwQ9DTz6DechKRZ0vvYADsC4X0Yp+KUZLi0bvTcl4v4Bx/WV1M2zcFZaW39OZAPNuodKrdHrFd4ta86KrjzCYYlZ62H3DdqkVGGZCcxYEeCW8p5i/2zCeG7YPLk1f9/jgOMWWxy7CbNgFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730452098; c=relaxed/simple; bh=UIhN6DCaRa2jWeCyoxhmpU21Xr4KXtRmBuuGJnDZdT8=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=ox3kacPXz2bZa6IRFRVBatbpb3JC3enUx+SQQdJo6RAwpV5+1bbH0uFihH2wXRy43wVDgfUIkakdpdwaM1Z6AAQnxV8ZRA+Up3qCAPMpovNICOrT41Pxy9SwLstVMiZz4kt6ia/cNaTixsE/ALKriO0OL3tQU7npEBc4b1Z3v80= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=tey23rxsjton5kop5bydp3vc5ylkyjkg; d=nasilyan.com; t=1730452079; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Transfer-Encoding; bh=UIhN6DCaRa2jWeCyoxhmpU21Xr4KXtRmBuuGJnDZdT8=; b=t6WsCvzWdOX6f7W+OVvOBl89RLqaHN5TTKtOU023kIM60s+PfDSNXzIOghkJLxvW E1tovO7+WbhOE3ZdMsquo8jB12lILLBfTsOhcGCY/OH+9KOuhIoUzgI00G9KqUuJT4B R2qcfc0xhj3JdyQ45KYjrw6ji6QhCsVxoB6iHDN0= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1730452079; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Transfer-Encoding:Feedback-ID; bh=UIhN6DCaRa2jWeCyoxhmpU21Xr4KXtRmBuuGJnDZdT8=; b=GxWSV2GyvJfpvJ8pEqpYPUf4UkaDdsXGMYt+JSM/XsaEawFoulnOhDOtN0hs1u5I NbBX+ogBeWcUawUU70j6TaaNtfR9RRCGZbeblXeSQl65D1vKUboaPf+o2n204Hlswsk bmB6Xy+XYO9p3M9JCWV7pQzbE8Od+s1w+yEH23bo= From: Simon Martin To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com Subject: [PATCH] c++: Handle SCOPE_REF in contains_placeholder_p [PR117158] Date: Fri, 1 Nov 2024 09:07:59 +0000 Message-ID: <01020192e6fb44f4-ef53170f-2e9d-427a-ad18-e4fc2dd31c25-000000@eu-west-1.amazonses.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Feedback-ID: ::1.eu-west-1.sMDMtMBSIJpOhM8kCarpRYeKFuDfm/WoE5+9WtFxb8w=:AmazonSES X-SES-Outgoing: 2024.11.01-54.240.7.18 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Since r10-3793-g1a37b6d9a7e57c, we ICE upon the following valid code with -std=c++17 and above === cut here === struct Base { unsigned int *intarray; }; template struct Sub : public Base { bool Get(int i) { return (Base::intarray[++i] == 0); } }; === cut here === The problem is that from c++17 on, we use -fstrong-eval-order and need to wrap the array access expression into a SAVE_EXPR, and end up calling contains_placeholder_p with a SCOPE_REF, that it does not handle well. This patch fixes this by skipping the first operand of SCOPE_REFs in contains_placeholder_p. Successfully tested on x86_64-pc-linux-gnu. PR c++/117158 gcc/ChangeLog: * tree.cc (contains_placeholder_p): Skip the first operand of SCOPE_REFs. gcc/testsuite/ChangeLog: * g++.dg/parse/crash77.C: New test. --- gcc/testsuite/g++.dg/parse/crash77.C | 13 +++++++++++++ gcc/tree.cc | 3 +++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/g++.dg/parse/crash77.C diff --git a/gcc/testsuite/g++.dg/parse/crash77.C b/gcc/testsuite/g++.dg/parse/crash77.C new file mode 100644 index 00000000000..25a426fa6d6 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/crash77.C @@ -0,0 +1,13 @@ +// PR c++/117158 +// { dg-do "compile" } + +struct Base { + unsigned int *intarray; +}; + +template +struct Sub : public Base { + bool Get(int i) { + return (Base::intarray[++i] == 0); + } +}; diff --git a/gcc/tree.cc b/gcc/tree.cc index b4c059d3b0d..7f8911002d0 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -4122,6 +4122,9 @@ contains_placeholder_p (const_tree exp) if (!exp) return false; + if (TREE_CODE (exp) == SCOPE_REF) + exp = TREE_OPERAND (exp, 1); + code = TREE_CODE (exp); if (code == PLACEHOLDER_EXPR) return true;