From patchwork Wed Jan 1 14:40:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: A J Ryan Solutions Ltd X-Patchwork-Id: 2028845 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=ajryansolutions.co.uk header.i=@ajryansolutions.co.uk header.a=rsa-sha256 header.s=dkim header.b=AJErWrTG; 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 4YNXZr2RGLz1yc5 for ; Thu, 2 Jan 2025 01:41:07 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CD28A3858C50 for ; Wed, 1 Jan 2025 14:41:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD28A3858C50 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=ajryansolutions.co.uk header.i=@ajryansolutions.co.uk header.a=rsa-sha256 header.s=dkim header.b=AJErWrTG X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-200162.simplelogin.co (mail-200162.simplelogin.co [176.119.200.162]) by sourceware.org (Postfix) with ESMTPS id 4C07F3858C56 for ; Wed, 1 Jan 2025 14:40:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C07F3858C56 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=ajryansolutions.co.uk Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ajryansolutions.co.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4C07F3858C56 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=176.119.200.162 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1735742423; cv=pass; b=LqkOj3LqAfBQKzo/1IC8JGRrUpZUw/s9yppPriWeVc2Zrrk6oHRshMDyXCRN4aL2Als0yU8k9yMz0VcE5ukr4Un7c+en/wlGLaElHWGGRK177D+vERkaSzw7cx9qR6rJzwrX/XLxnyhEfpJRNn8RDvNU5R6UOFmbIL0n0OxlXQ4= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1735742423; c=relaxed/simple; bh=UQbhYRsSoyt7bUXDvyh03o4ATOEBcjIQ20oz73y5HC0=; h=DKIM-Signature:Date:Subject:MIME-Version:From:To:Message-ID; b=teFOS2SGDWbwVdh02mxwKSNIT6KNtFLydE2cXjXx5Td3AggBk++xunUXykaxD8U1pGe3hG8yPhmoZQ5xaRkgUlO+0Xz1YopGH5oOhgpAR1kq3jasLVFWpCNe8q7Mqdxy0CbpAysX/nCAiAVVg8YDLrjcS2kc2BH17Iz53IM/ECI= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C07F3858C56 ARC-Seal: i=1; a=rsa-sha256; d=simplelogin.co; s=arc-20230626; t=1735742422; cv=none; b=to/PwS4L7P9SDGPXzJW+mP7wIArPM/6RsYQ02dF2NIQOmTT6pHqiVRRCt9RCnyispmyrXL/kkujqK4L6JmH9H5J3KCUr9G9cqjO2idP3jU/ZDY3rE7Dt+NB+9UTFfUeND3rlZHpA6t13SF6Ev1YAhjpkIVjT4g5T1VW2GJ6HVoXiWhQRgyZpbMv1o9XV8IxASRZEVlNcQMS7gHxQj7zFh63i3SiLXOxi/wWJbI0bW4r9yelPcNEfGuqxeHnZcxSdJm/bP4INLZsaHuibq5YZBCtmnp/So20ZoEj/99rZjoX8WZfgFqmIdL9t4mBdx6h15rgiYMkwOuwBtz4KZlrwgA== ARC-Message-Signature: i=1; a=rsa-sha256; d=simplelogin.co; s=arc-20230626; t=1735742422; c=relaxed/simple; bh=UQbhYRsSoyt7bUXDvyh03o4ATOEBcjIQ20oz73y5HC0=; h=Date:Subject:From:To; b=d8zd/6xxjMtHvf3QNwirTDSuq6Jxa5pR/r4gCa7PbXq73omnDcI0iRLm4EflYij/Gzq130p1GqYb+ExLuQG1ICOLvoHXCAWB0j1AjX5v9qVfFG3rJqny3KDlhuCYOeyygnXvBxnFpSnEFsaerF2VwLPoThK3utMm45QsRoo0TAyGKONvBVa7pB59bixF4aqU2tkXGe/S3gWylDEgUxb4XkwJNrtH6jvNRWsSMrbYKH3p00TQUcUsSKDNMS0YBE8d2vPpWi/FrGb+HzOSO70cKaHKnEDes1US8A025EW/fk0ZNzvlYk4z9ZWxNV33JPSx/4N9qXftmz/3A3fH3Y+JZQ== ARC-Authentication-Results: i=1; mail.protonmail.ch DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ajryansolutions.co.uk; s=dkim; t=1735742422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=UQbhYRsSoyt7bUXDvyh03o4ATOEBcjIQ20oz73y5HC0=; b=AJErWrTGHIScpnwcfNvzUbayNwbuykt0Ue4nedlyRYUl7uUhCOHg3XJkc0293DmjjSwD95 wWFqDQRpWGaeNzHNJ1/tTi/+zqgG+Vswg18y9OBJ3BUI1THbbxNdJr1hGTl9aiiDwESXgQ cwV1cM8PMyOgGf7KGOBHuJUsRFbc420= Date: Wed, 01 Jan 2025 14:40:14 +0000 Subject: [PATCH] gcc: Add tree walk case to reach A pack from B in ...B>. [PR118265] MIME-Version: 1.0 From: A J Ryan Solutions Ltd To: gcc-patches@gcc.gnu.org Message-ID: <173574242188.7.15941998856003691840.550550580@ajryansolutions.co.uk> X-SimpleLogin-Type: Reply X-SimpleLogin-EmailLog-ID: 550550580 X-SimpleLogin-Want-Signing: yes 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 Hi and happy new year, this patch is to fix a compiler seg-fault as encountered in the following example: template struct Class1{}; template class Class2; template...Un> class Class2 { public: void apply(){} }; Class1 class1_bool; Class1 class1_char; int main() { Class2 class2; class2.apply(); } where it ends up populating the V argument in the instantiated template at the class2 declaration with the unknown placeholder and the segfault is when it later tries to get the name for an incompletely resolved type. The incorrect processing happens in unify_pack_expansion where it is calling unify_one_argument here(https://gcc.gnu.org/git?p=gcc.git;a=blob;f=gcc/cp/pt.cc;h=0ffa0b53e26a87df3ed2c7202446c68d2800db64;hb=HEAD#l24718) for each argument of the argument pack and recursively unifying the inner arguments. In this example the inner argument against V (bool/char) is set in targs however it is not seen as a pack argument in unify_pack_expansion because in the unfixed code it does not reach and link this associated pack and later on when processing the collected arguments to substitute it in in instantiate_class_template the argument has not been set as an argument pack in targs and it doesn't match the the template specialisation parameter which is a parameter pack and it falls back to the unknown placeholder. The parameter packs are originally linked in make_pack_expansion here(https://gcc.gnu.org/git?p=gcc.git;a=blob;f=gcc/cp/pt.cc;h=0ffa0b53e26a87df3ed2c7202446c68d2800db64;hb=HEAD#l4246) and the change is in this tree walk so that in the example above V is chained to Un and after calling unify_one_argument it loops over both packs and extracts their associated value set in targs and puts it into it's pack argument collection. Regards Adam Ryan From 5c60f42e1bb143b1c3752f23368cd6d926d0b598 Mon Sep 17 00:00:00 2001 From: Adam J Ryan Date: Wed, 1 Jan 2025 13:31:01 +0000 Subject: [PATCH] Add tree walk case to obtain A pack in ...B>. For non-type parameter packs when unifying the arguments in unify_pack_expansion it iterates over the associated packs of a param so that when it recursivly unifies the param with the arguments it knows which targs have been populated with parameter pack arguments that it can then collect up. This change adds a tree walk so that in the example above it reaches ...A and adds it to the associated packs for ...B and therefore knows it will have been set in targs in unify_pack_expansion and processes it as per other pack arguments. PR gcc/118265 Signed-off-by: Adam J Ryan --- gcc/cp/pt.cc | 5 +++++ gcc/testsuite/g++.dg/pr118265.C | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 gcc/testsuite/g++.dg/pr118265.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 0ffa0b53e26..22f5d4b1875 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -4012,6 +4012,11 @@ find_parameter_packs_r (tree *tp, int *walk_subtrees, void* data) &find_parameter_packs_r, ppd, ppd->visited); return NULL_TREE; + case TEMPLATE_PARM_INDEX: + if (parameter_pack_p) + WALK_SUBTREE ( TREE_TYPE(t) ); + return NULL_TREE; + case DECL_EXPR: { tree decl = DECL_EXPR_DECL (t); diff --git a/gcc/testsuite/g++.dg/pr118265.C b/gcc/testsuite/g++.dg/pr118265.C new file mode 100644 index 00000000000..00bda1b5b48 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr118265.C @@ -0,0 +1,17 @@ +// { dg-do compile { target c++20 } } +template struct Class1{}; + +template class Class2; +template...Un> class Class2 +{ + public: void apply(){} +}; + +Class1 class1_bool; +Class1 class1_char; + +int main() +{ + Class2 class2; + class2.apply(); +} \ No newline at end of file -- 2.43.0