From patchwork Fri Jul 14 22:37:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1808048 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Xm3NIFr4; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R2mcn6THhz20bY for ; Sat, 15 Jul 2023 08:39:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 392113857033 for ; Fri, 14 Jul 2023 22:39:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 392113857033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689374375; bh=SwpVjwL1/DwaawGjj4AQ9ODy5fwhfE93T9//1Li46K8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Xm3NIFr4LG2qaw/gh6AbpdZUnPi1MjkXBDrRa2Ee4uMpUVqsDkvKVDJKRtqq7IKdN 3FfFRE9+UBzNUDq89fDVneVBIyrG0xGR6y/8zAD73Wsjma+ivsB24oyg2CJrUGR9T8 zteeUYBrPhmsXwaBlavws6RwL6Uw/k94DXNdFvWs= 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 5640038582A4 for ; Fri, 14 Jul 2023 22:38:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5640038582A4 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-561-vzLNZ5moMUaTA02tKqPF6w-1; Fri, 14 Jul 2023 18:37:50 -0400 X-MC-Unique: vzLNZ5moMUaTA02tKqPF6w-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-765de3a3404so305576485a.2 for ; Fri, 14 Jul 2023 15:37:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689374269; x=1691966269; 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=SwpVjwL1/DwaawGjj4AQ9ODy5fwhfE93T9//1Li46K8=; b=eTzG02QJdQo3NeJ7M9AtiqOaTMqKOUJqO9N2JIKfTPQiiUn9ChahXC+e8uEaKyaLyG uQ3UpGXb3g6fJoOBnjYHFmSzQncfx+2LCE6qvUWIf841WXJTZ4IxvUH+ZdD3iK6+MthI zIlBMF0LvNRl91k3y4DCPh7OrmyMfyu0zFQ6XITVMgmEOUFyrGnizLZY3N1oULsTSFmc PnoWPdt1lH3QvnOaCLJ/0HhWrCsE1VqrEBRAlmRClIiQ5tV04Dp4j8Lwmj0eOXet+UFE hzE/9KCbNZFugLhgxaloduRs+lA1r1ZSjTgS1ehxoz4t1RwEVRjJZM7JSkH2/GK5yQEa 2GCg== X-Gm-Message-State: ABy/qLbBS3i7KudHrV+wgaRZqZCjNLvN4FBWgvUllWR0p1Dff6Np9yU5 wUS8XQak5JzFQjjCkP+GXRH89X2hxlSuw1I+Hl3B1XDCJX68SFW1EdRFbBpEwMD3Enw7eYVWhd1 nWX40tUCwjm6ey5SxN1cVG6dSXugHEjJ+fqHlM08fDxkhaFhZco8iVEBVwaklFO85L7Q/Q8G8mw == X-Received: by 2002:a37:2c41:0:b0:767:d709:c3f5 with SMTP id s62-20020a372c41000000b00767d709c3f5mr6235542qkh.62.1689374269348; Fri, 14 Jul 2023 15:37:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlFiBrR36cuxglP+r1LuLw8pLCqG0D1/LvDVQ2U35h0qAb58ZWBjzhkwq07k2x4gnhRcD/VuvQ== X-Received: by 2002:a37:2c41:0:b0:767:d709:c3f5 with SMTP id s62-20020a372c41000000b00767d709c3f5mr6235525qkh.62.1689374268994; Fri, 14 Jul 2023 15:37:48 -0700 (PDT) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id a20-20020a0ce354000000b005ef442226bbsm4341915qvm.8.2023.07.14.15.37.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 15:37:47 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Marek Polacek Subject: [pushed] c++: c++26 regression fixes Date: Fri, 14 Jul 2023 18:37:44 -0400 Message-Id: <20230714223744.264094-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.7 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, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- Apparently I wasn't actually running the testsuite in C++26 mode like I thought I was, so there were some failures I wasn't seeing. The constexpr hunk fixes regressions with the P2738 implementation; we still need to use the old handling for casting from void pointers to heap variables. PR c++/110344 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_constant_expression): Move P2738 handling after heap handling. * name-lookup.cc (get_cxx_dialect_name): Add C++26. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-cast2.C: Adjust for P2738. * g++.dg/ipa/devirt-45.C: Handle -fimplicit-constexpr. --- gcc/cp/constexpr.cc | 21 ++++++++++---------- gcc/cp/name-lookup.cc | 2 ++ gcc/testsuite/g++.dg/cpp0x/constexpr-cast2.C | 6 +++--- gcc/testsuite/g++.dg/ipa/devirt-45.C | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) base-commit: 49a2a63e6518cfa294d903f5f62ab1f922df438e diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index cca0435bafc..9f96a6c41ea 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -7681,17 +7681,6 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, && !is_std_construct_at (ctx->call) && !is_std_allocator_allocate (ctx->call)) { - /* P2738 (C++26): a conversion from a prvalue P of type "pointer to - cv void" to a pointer-to-object type T unless P points to an - object whose type is similar to T. */ - if (cxx_dialect > cxx23) - if (tree ob - = cxx_fold_indirect_ref (ctx, loc, TREE_TYPE (type), op)) - { - r = build1 (ADDR_EXPR, type, ob); - break; - } - /* Likewise, don't error when casting from void* when OP is &heap uninit and similar. */ tree sop = tree_strip_nop_conversions (op); @@ -7699,6 +7688,16 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, && VAR_P (TREE_OPERAND (sop, 0)) && DECL_ARTIFICIAL (TREE_OPERAND (sop, 0))) /* OK */; + /* P2738 (C++26): a conversion from a prvalue P of type "pointer to + cv void" to a pointer-to-object type T unless P points to an + object whose type is similar to T. */ + else if (cxx_dialect > cxx23 + && (sop = cxx_fold_indirect_ref (ctx, loc, + TREE_TYPE (type), sop))) + { + r = build1 (ADDR_EXPR, type, sop); + break; + } else { if (!ctx->quiet) diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index 74565184403..2d747561e1f 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -6731,6 +6731,8 @@ get_cxx_dialect_name (enum cxx_dialect dialect) return "C++20"; case cxx23: return "C++23"; + case cxx26: + return "C++26"; } } diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-cast2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-cast2.C index b79e8a90131..3efbd92f043 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-cast2.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-cast2.C @@ -6,11 +6,11 @@ static int i; constexpr void *vp0 = nullptr; constexpr void *vpi = &i; constexpr int *p1 = (int *) vp0; // { dg-error "cast from .void\\*. is not allowed" } -constexpr int *p2 = (int *) vpi; // { dg-error "cast from .void\\*. is not allowed" } +constexpr int *p2 = (int *) vpi; // { dg-error "cast from .void\\*. is not allowed" "" { target c++23_down } } constexpr int *p3 = static_cast(vp0); // { dg-error "cast from .void\\*. is not allowed" } -constexpr int *p4 = static_cast(vpi); // { dg-error "cast from .void\\*. is not allowed" } +constexpr int *p4 = static_cast(vpi); // { dg-error "cast from .void\\*. is not allowed" "" { target c++23_down } } constexpr void *p5 = vp0; constexpr void *p6 = vpi; constexpr int *pi = &i; -constexpr bool b = ((int *)(void *) pi == pi); // { dg-error "cast from .void\\*. is not allowed" } +constexpr bool b = ((int *)(void *) pi == pi); // { dg-error "cast from .void\\*. is not allowed" "" { target c++23_down } } diff --git a/gcc/testsuite/g++.dg/ipa/devirt-45.C b/gcc/testsuite/g++.dg/ipa/devirt-45.C index c26be21964c..019b454835c 100644 --- a/gcc/testsuite/g++.dg/ipa/devirt-45.C +++ b/gcc/testsuite/g++.dg/ipa/devirt-45.C @@ -37,5 +37,5 @@ int main() } /* One invocation is A::foo () other is B::foo () even though the type is destroyed and rebuilt in test() */ -/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*A::foo" 2 "inline" } } */ +/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*A::foo" 2 "inline" { target { ! implicit_constexpr } } } }*/ /* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*B::foo" 1 "inline" } } */