From patchwork Wed Oct 30 07:17:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 99805 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5B9B2385841E for ; Wed, 30 Oct 2024 07:17:52 +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 ESMTP id 073F33858D28 for ; Wed, 30 Oct 2024 07:17:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 073F33858D28 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 073F33858D28 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=1730272643; cv=none; b=S3oHkfgXA46bBAGmxMC/Xd/gItExSnvvV51yJx0Uz1HPyc9Gi3He3d4hKXsoWcE31QpOVFjptgs8It+uExDTVkOn99K0rbg6bVcvM6wAGDdbYKnbcIPAP571CbdIw7P6XGWHCtFBCh1KC48C2X37DFSeG42GEg0NgrILxoDz9Ug= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730272643; c=relaxed/simple; bh=+ZoiE61t2L71FbsrE47lWTTF3nS+XyRRC5UyfIhhFtw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=v+YXvIv8I31eMgE0964mLgS2eYForOenFLWNqfKJ/OBhvmZeW+cZNjD6GpXQ0PoSrk/NNg0TU1NWbqMUVjafgw+rSyl4PpRIJCBhhJsV+cO7rzaCovwBR5fS5VlnH+aQHppZpd5WTEj6d1dwmCGY8RMV9krQAGYD+I4haJHLj/U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730272637; 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=Ev6CqlkeHNXxlKKKKXuolz82GsKCFKwFR75yZhsFOYU=; b=NGmfiJ0+FrcGVNHkbV/ZuydBjJGzpuGhIDdLvTDutdby5aJDITXzO4hbUrnpHvGMrRtVy5 gpAviE4ccBFApw6xXXjEyoRIGp1Sqee8oa46R+sf8YNttISIfwq/dbB07Gjxy81okiGwXe 7qVDpLX4iM4SuoO5oJpg517oCcKak3c= Received: from mx-prod-mc-04.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-695-4uShWi6dMMCXAnhwBunD2A-1; Wed, 30 Oct 2024 03:17:15 -0400 X-MC-Unique: 4uShWi6dMMCXAnhwBunD2A-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6876919560A5 for ; Wed, 30 Oct 2024 07:17:14 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.16]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CCE8219560A2; Wed, 30 Oct 2024 07:17:13 +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 49U7HAGS1784724 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 30 Oct 2024 08:17:10 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 49U7HAGo1784723; Wed, 30 Oct 2024 08:17:10 +0100 Date: Wed, 30 Oct 2024 08:17:10 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix ICE on constexpr virtual function [PR117317] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 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_H2, 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~patchwork=sourceware.org@gcc.gnu.org Hi! Since C++20 virtual methods can be constexpr, and if they are constexpr evaluated, we choose tentative_decl_linkage for those defer their output and decide at_eof again. On the following testcases we ICE though, because if expand_or_defer_fn_1 decides to use tentative_decl_linkage, it returns true and the caller in that case cals emit_associated_thunks, where use_thunk which it calls asserts DECL_INTERFACE_KNOWN on the thunk destination, which isn't the case for tentative_decl_linkage. The following patch fixes the ICE by not emitting the thunks for the DECL_DEFER_OUTPUT fns just yet but waiting until at_eof time when we return to those. Note, the second testcase ICEs already since r0-110035 with -std=c++0x before it gets a chance to diagnose constexpr virtual method. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and eventually for backports? 2024-10-30 Jakub Jelinek PR c++/117317 * semantics.cc (emit_associated_thunks): Do nothing for !DECL_INTERFACE_KNOWN && DECL_DEFER_OUTPUT fns. * g++.dg/cpp2a/pr117317-1.C: New test. * g++.dg/cpp2a/pr117317-2.C: New test. Jakub --- gcc/cp/semantics.cc.jj 2024-10-25 10:00:29.433768358 +0200 +++ gcc/cp/semantics.cc 2024-10-29 13:10:32.234068524 +0100 @@ -5150,7 +5150,10 @@ emit_associated_thunks (tree fn) enabling you to output all the thunks with the function itself. */ if (DECL_VIRTUAL_P (fn) /* Do not emit thunks for extern template instantiations. */ - && ! DECL_REALLY_EXTERN (fn)) + && ! DECL_REALLY_EXTERN (fn) + /* Do not emit thunks for tentative decls, those will be processed + again at_eof if really needed. */ + && (DECL_INTERFACE_KNOWN (fn) || !DECL_DEFER_OUTPUT (fn))) { tree thunk; --- gcc/testsuite/g++.dg/cpp2a/pr117317-1.C.jj 2024-10-29 13:12:23.373519669 +0100 +++ gcc/testsuite/g++.dg/cpp2a/pr117317-1.C 2024-10-29 13:12:18.223591437 +0100 @@ -0,0 +1,19 @@ +// PR c++/117317 +// { dg-do compile { target c++20 } } + +struct C { + constexpr bool operator== (const C &b) const { return foo (); } + constexpr virtual bool foo () const = 0; +}; +class A : public C {}; +class B : public C {}; +template +struct D : A, B +{ + constexpr bool operator== (const D &) const = default; + constexpr bool foo () const override { return true; } +}; +struct E : D<1> {}; +constexpr E e; +constexpr E f; +static_assert (e == f, ""); --- gcc/testsuite/g++.dg/cpp2a/pr117317-2.C.jj 2024-10-29 13:16:10.101359947 +0100 +++ gcc/testsuite/g++.dg/cpp2a/pr117317-2.C 2024-10-29 13:16:15.981278003 +0100 @@ -0,0 +1,15 @@ +// PR c++/117317 +// { dg-do compile { target c++20 } } + +struct C { + constexpr virtual bool foo () const = 0; +}; +struct A : public C {}; +struct B : public C {}; +template +struct D : A, B +{ + constexpr bool foo () const override { return true; } +}; +constexpr D<0> d; +static_assert (d.foo (), "");