From patchwork Thu Aug 1 18:39:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1967988 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=Fe/sXQRM; 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 4WZd6v22Ydz1yZv for ; Fri, 2 Aug 2024 04:39:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C6C43858D35 for ; Thu, 1 Aug 2024 18:39:49 +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 ESMTP id EBD5D3858D26 for ; Thu, 1 Aug 2024 18:39:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EBD5D3858D26 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EBD5D3858D26 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=1722537569; cv=none; b=SGW39ruVs8WUBou+3w3dEDM4d311cIpfi/HFYDjS43+78IvX8LmWFM38zuP9kgWAb4eoOqRanoFfK67nq+RBumRJhAN5UbTxpcLf/e+eebde/9NERP28eCmUg7YismnESwLgMuNmV+D7gROnHrMXoVfwD32frZdHnvNwuHZaXUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722537569; c=relaxed/simple; bh=zR51g2C9tz+TZZbKlW9298n4H2XNx79uCvz9sgeA6iM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=YnBoK9dllgZ8BsELJ5iDk/xMoz48GchVUk4Zdud8oM0tpNhyixwYt+GMdAORIScucz8VWtWoPQ2Ik0bh0+VjcqGeCnHaEt15P7N2r8sPHPKEDlvoBO9kBFAq9zw/oAZRyYtgPXHgLz2efZ0O34hgJWrClbtYlLeL5pFYvgTQ/BQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722537566; 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=rMRdPQau9R3dmjzpv5QOMPueNgTlGr8dGpdmghWssdQ=; b=Fe/sXQRMPDwT1bp8YXDgGYwtK1++Dda5uE7IwqOU8KAk0a5t9KmKQ94wIgiaXDWxVfvKHe foIAfeQkrRaErSJ1Dn0Rjrr5nTa1/8FcQD5241oJvcGV0gPDe06THCVj/AdeBc6OINI45z QsN7Pt9eRX8oVwfwzMxUpwUrVSE/dEc= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-614-2kECw-UpMIiBiVwJC9fMWg-1; Thu, 01 Aug 2024 14:39:23 -0400 X-MC-Unique: 2kECw-UpMIiBiVwJC9fMWg-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8BFD81955D57 for ; Thu, 1 Aug 2024 18:39:22 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.25]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B1FF01955E80; Thu, 1 Aug 2024 18:39:16 +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 471IdDXO1756296 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 1 Aug 2024 20:39:13 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 471IdDxP1756295; Thu, 1 Aug 2024 20:39:13 +0200 Date: Thu, 1 Aug 2024 20:39:13 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix up handling of dependent (late) attributes on function/method types [PR116175] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 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 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! When working on unsequenced/reproducible attributes, I've noticed that on templates for some attributes decl_attributes isn't called at all, so they are kept in TYPE_ATTRIBUTES without any verification/transformations and also without argument substitution. The following patch fixes that for FUNCTION/METHOD_TYPE attributes. The included testcase ICEs without the pt.cc changes. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-08-01 Jakub Jelinek PR c++/116175 * pt.cc (apply_late_template_attributes): For function/method types call cp_build_type_attribute_variant on the non-dependent attributes. (rebuild_function_or_method_type): Add ARGS argument. Use apply_late_template_attributes rather than cp_build_type_attribute_variant. (maybe_rebuild_function_decl_type): Add ARGS argument, pass it to rebuild_function_or_method_type. (tsubst_function_decl): Adjust caller. (tsubst_function_type): Adjust rebuild_function_or_method_type caller. * g++.dg/ext/attr-format4.C: New test. Jakub --- gcc/cp/pt.cc.jj 2024-07-31 14:38:54.405628645 +0200 +++ gcc/cp/pt.cc 2024-08-01 16:29:59.671779469 +0200 @@ -12219,6 +12219,8 @@ apply_late_template_attributes (tree *de to our attributes parameter. */ gcc_assert (*p == attributes); } + else if (FUNC_OR_METHOD_TYPE_P (*decl_p)) + p = NULL; else { p = &TYPE_ATTRIBUTES (*decl_p); @@ -12237,7 +12239,10 @@ apply_late_template_attributes (tree *de tree nondep = t; /* Apply any non-dependent attributes. */ - *p = nondep; + if (p) + *p = nondep; + else if (nondep) + *decl_p = cp_build_type_attribute_variant (*decl_p, nondep); if (nondep == attributes) return true; @@ -14375,8 +14380,9 @@ lookup_explicit_specifier (tree v) identical to T. */ static tree -rebuild_function_or_method_type (tree t, tree return_type, tree arg_types, - tree raises, tsubst_flags_t complain) +rebuild_function_or_method_type (tree t, tree args, tree return_type, + tree arg_types, tree raises, + tsubst_flags_t complain) { gcc_assert (FUNC_OR_METHOD_TYPE_P (t)); @@ -14409,7 +14415,9 @@ rebuild_function_or_method_type (tree t, new_type = build_method_type_directly (r, return_type, TREE_CHAIN (arg_types)); } - new_type = cp_build_type_attribute_variant (new_type, TYPE_ATTRIBUTES (t)); + if (!apply_late_template_attributes (&new_type, TYPE_ATTRIBUTES (t), 0, + args, complain, NULL_TREE)) + return error_mark_node; cp_ref_qualifier rqual = type_memfn_rqual (t); bool late_return_type_p = TYPE_HAS_LATE_RETURN_TYPE (t); @@ -14422,7 +14430,7 @@ rebuild_function_or_method_type (tree t, resolution for Core issues 1001/1322. */ static void -maybe_rebuild_function_decl_type (tree decl) +maybe_rebuild_function_decl_type (tree decl, tree args) { bool function_type_needs_rebuilding = false; if (tree parm_list = FUNCTION_FIRST_USER_PARM (decl)) @@ -14474,7 +14482,7 @@ maybe_rebuild_function_decl_type (tree d *q = void_list_node; TREE_TYPE (decl) - = rebuild_function_or_method_type (fntype, + = rebuild_function_or_method_type (fntype, args, TREE_TYPE (fntype), new_parm_type_list, TYPE_RAISES_EXCEPTIONS (fntype), tf_none); } @@ -14657,7 +14665,7 @@ tsubst_function_decl (tree t, tree args, DECL_ARGUMENTS (r) = parms; DECL_RESULT (r) = NULL_TREE; - maybe_rebuild_function_decl_type (r); + maybe_rebuild_function_decl_type (r, args); TREE_STATIC (r) = 0; TREE_PUBLIC (r) = TREE_PUBLIC (t); @@ -15925,7 +15933,7 @@ tsubst_function_type (tree t, } /* Construct a new type node and return it. */ - return rebuild_function_or_method_type (t, return_type, arg_types, + return rebuild_function_or_method_type (t, args, return_type, arg_types, /*raises=*/NULL_TREE, complain); } --- gcc/testsuite/g++.dg/ext/attr-format4.C.jj 2024-08-01 17:44:35.492269816 +0200 +++ gcc/testsuite/g++.dg/ext/attr-format4.C 2024-08-01 17:43:27.340127120 +0200 @@ -0,0 +1,12 @@ +// PR c++/116175 +// { dg-do compile { target c++11 } } +// { dg-options "-Wformat" } + +template +int foo (T ...args, const char *fmt, ...) +[[gnu::format (printf, 1 + sizeof... (T), 2 + sizeof... (T))]]; + +int a = foo <> ("%d", 1); +int b = foo (1, 2, 3, 4, 5, "%d", 1); +int c = foo <> ("%f", 1); // { dg-warning "format '%f' expects argument of type 'double', but argument 2 has type 'int'" } +int d = foo (1, 2, 3, 4, 5, "%f", 1); // { dg-warning "format '%f' expects argument of type 'double', but argument 7 has type 'int'" }