From patchwork Sat May 25 23:18:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1939293 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=KOM1ZEq+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4VmyXQ3mLfz1ydW for ; Sun, 26 May 2024 09:19:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0608C385EC59 for ; Sat, 25 May 2024 23:18:57 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 5E5943858CD9 for ; Sat, 25 May 2024 23:18:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E5943858CD9 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 5E5943858CD9 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716679120; cv=none; b=Vxbe6kU0j8D4LcxwCtBDiddwvOGC4mGLPCwTlzYfKkM6ek61YNBqvO7zOdKymtqcKi2AZFDjVEnllC/m8t+Ned3OcGC1vSH2T/LR3Ela86ttbzLw+gnQ2fsjy4LHbHjvkzyNNK0XfdWG5uk/PHW6TjfiLyDzb4e9YN2J3MvOg5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716679120; c=relaxed/simple; bh=xq2yVrtgRLVTL/iSJqy4jvhvpYCuZURkMexL0pj7t/k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=mQC/kYdGANhpTIT7s63BfMZ0YDS4pWrLG8aQHAnfL+O90GLx4q5MSvXh0ElMLQOAIPEg4BNtYwd7gbIGAN/yrh+XSXaRsWKCj/Bs192CExZInaXuRrgMV8wfCpVuE997cuEUUTy/WMyoWSA1jmarOddYx06rKvv2jKzRWK1KFHY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716679115; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=JiWMGf2Iu1V/Ppfz7ppb+yORgL+NZFokLwcNlw3ZpOs=; b=KOM1ZEq+V3pnN5gwuY2umzDXrudLl4WXNniH/0nSzXT4dBpJSbrsUdU+E2QMGxBOGnEuqh US2HcpTz3ZlXm+OPd1dHGYYsdFie+eZYYIpuJezcAmUVClSfh+fgkPOuNp3H+ufTP1TKnq aDrDZST0ywNrgTOr9VUOTOnPR+IkcrQ= Received: from mail-oo1-f72.google.com (mail-oo1-f72.google.com [209.85.161.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-619-EWT6FIIxOVqQJhw7DZXUPg-1; Sat, 25 May 2024 19:18:33 -0400 X-MC-Unique: EWT6FIIxOVqQJhw7DZXUPg-1 Received: by mail-oo1-f72.google.com with SMTP id 006d021491bc7-5b51a370a29so4532825eaf.0 for ; Sat, 25 May 2024 16:18:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716679111; x=1717283911; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JiWMGf2Iu1V/Ppfz7ppb+yORgL+NZFokLwcNlw3ZpOs=; b=EaHeXHaE6yJ/g/4N2CwcSCBBlzgIY0DNVJ5+fP2OuM3CAxy7NPx7aJ9u6sw0Y5/zHe BYSs4R/dhTNk/5pFvE4oHgOEur9bRNmpS48pSCybSpLXGIhsTQMpUinK2MRTA7Hf8Kwz Tvaxmyv61X2zQZwdRuU5SuQZkgbeqcPa6bV0E6/ArpqR2jaBY2vgXM2IYvx0zm3lVwhc ODUjubbx++PuWLdyhYFiI/x7NU/JdjrvMb9+IpTw/p/ja84E8runnnmcPDrKYCiNMpIS m795pZDVKLjTAn4CfpiX1wmDB9GZh+tvpxh7wzUiQWEpU45k31AaSv8rK2e5C/BY+W/F jfuA== X-Gm-Message-State: AOJu0YzRJ3lxYCARksPDOrP0duMcvIWDhN1uZiHhnvQkRD4nYYRsMLRa D7weP1jAex/yKYr0yqnSBGEBq8V/1Bs4DzbI043Trqb9F00I/Llp59lK5mdigswH+G2cy3+MZbk Tm+8vqK6W6nJWJfo78wufoR4O/haE4Y94zOPCumn/WyCwpYNIA3s1qv9p58dHycoVoYwuhxBFM5 ZTRgLoF2uxinrtmKU5KOCi3hzTHKkKHKgfzan/ X-Received: by 2002:a05:6358:5328:b0:186:27ce:639c with SMTP id e5c5f4694b2df-197e50cb1efmr853445955d.18.1716679110936; Sat, 25 May 2024 16:18:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkhwpv8lU6b3s3l5YQWPfKJ4bSRbIFCxf1HZLTcdC2ls+alET5jcvTgcPpUbhjlRt2Oxfnqw== X-Received: by 2002:a05:6358:5328:b0:186:27ce:639c with SMTP id e5c5f4694b2df-197e50cb1efmr853442255d.18.1716679110182; Sat, 25 May 2024 16:18:30 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abd30371sm180081585a.104.2024.05.25.16.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 May 2024 16:18:29 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: canonicity of fn types w/ instantiated eh specs [PR115223] Date: Sat, 25 May 2024 19:18:28 -0400 Message-ID: <20240525231828.1043776-1-ppalka@redhat.com> X-Mailer: git-send-email 2.45.1.246.gb9cfe4845c MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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_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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrap and regtest on x86_64-pc-linux-gnu in progress, does this look OK for trunk if successful? -- >8 -- When propagating structural equality in build_cp_fntype_variant, we should consider structural equality of the exception-less variant, not of the given type which might use structural equality only because of the (complex) noexcept-spec we're intending to replace, as in maybe_instantiate_noexcept which calls build_exception_variant using the function type with a deferred noexcept-spec. Otherwise we might pessimisticly use structural equality for a function type with a simple instantiated noexcept-spec, leading to a failed LTO-specific sanity check if we later use that (structural-equality) type as the canonical version of some other variant. PR c++/115223 gcc/cp/ChangeLog: * tree.cc (build_cp_fntype_variant): Propagate structural equality of the exception-less variant. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept87.C: New test. --- gcc/cp/tree.cc | 4 ++++ gcc/testsuite/g++.dg/cpp0x/noexcept87.C | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept87.C diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index 4d87661b4ad..f810b8cd777 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -2796,6 +2796,10 @@ build_cp_fntype_variant (tree type, cp_ref_qualifier rqual, bool complex_eh_spec_p = (cr && cr != noexcept_true_spec && !UNPARSED_NOEXCEPT_SPEC_P (cr)); + if (!complex_eh_spec_p && TYPE_RAISES_EXCEPTIONS (type)) + /* We want to consider structural equality of the exception-less + variant since we'll be replacing the exception specification. */ + type = build_cp_fntype_variant (type, rqual, /*raises=*/NULL_TREE, late); if (TYPE_STRUCTURAL_EQUALITY_P (type) || complex_eh_spec_p) /* Propagate structural equality. And always use structural equality for function types with a complex noexcept-spec since their identity diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept87.C b/gcc/testsuite/g++.dg/cpp0x/noexcept87.C new file mode 100644 index 00000000000..60b1497472b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept87.C @@ -0,0 +1,11 @@ +// PR c++/115223 +// { dg-do compile { target c++11 } } +// { dg-additional-options -flto } + +template +void f() noexcept(bool(T() || true)); + +void g(int n) { f(); } + +using type = void; +type callDestructorIfNecessary() noexcept {}