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: 120700 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp2790958vqm; Fri, 14 Jul 2023 15:40:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlFeTbWKy7mH/RrlMmEay0tedmNvu7c3M9zLHfc8pnQ32Wz2b0+bEKnkuuhlRM/3xHcK1irK X-Received: by 2002:aa7:d1d9:0:b0:51e:1bf3:f4ac with SMTP id g25-20020aa7d1d9000000b0051e1bf3f4acmr4973422edp.27.1689374414049; Fri, 14 Jul 2023 15:40:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689374414; cv=none; d=google.com; s=arc-20160816; b=Pl0haO7oCLQeY6oYwAJIwgXHHhlHaJIDEEclC2hJdbz4zPoR6lDozq+/8//JIwYau9 fgEIgTqkSQOo72EJrFdf9uFOe17Pwgyu9L01IY9HHWbuW1Tbzq53mV9D1XDpdcI8m1nU cf1ZozFNFQluxRFjQgbdiZ89kQtwZabjpvpkWVsBYCNsUowD4a0qvr/TIQMSu1M7RosA FWzvp/JNWCfcwwK5Kt9UWpQovpBUtVIkBHypEENSoWR3QVCGWqoZcyydRC58TuV7q2Rl 7P4zdYJy895D74z1uLw4Hu+sgdK38bsXk48c+a7CU4kMVqeDVXdSSkqvLWNAzwdD1EBV 9whQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=SwpVjwL1/DwaawGjj4AQ9ODy5fwhfE93T9//1Li46K8=; fh=URSpMGnD8iyRzS+vPdRCza4BnxUl/C94tR711c6n/VU=; b=PLUfuCoLn5rCUYo4idJD26yOKkxdTNZUkkbjhDB6mWQKUIpw7TTEMKaEH0s7lLfcoD EqLmSgVd70z+b7JJsXJmz+5GR+dGs6bmWTrE5YspmbixEptFoxnK5+zguK8Ds5HRWG7c +dhMdbRuOVXrD4Syr33gZXSjUqKEowH3xKfSto2yDqNHvEFB45Lt3JfWPsVN6/J90D+n 5fLjbzI3I7sXL8ShaQdA9bkOXT5JsfLnLsuEMip6Tn4NvJ5PoYVjF4DdUt6+rIgalFYj NuLjUUxtzy4CrmuXY2LopWEM9Obg4419Xktb9ru0I67G5Vp9eqssgIpN6lUmD4pGW1IX SVLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Q3MnLY7s; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n8-20020aa7d048000000b0051e161794a1si10398431edo.119.2023.07.14.15.40.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 15:40:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Q3MnLY7s; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 310733857345 for ; Fri, 14 Jul 2023 22:39:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 310733857345 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689374399; 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=Q3MnLY7s3nELRsNENJ/ZlhiYuLoZsttd9Igxs3lczS8b7tz5BlgOPNjdaCRAlZaWi Bj4y5UwOh/eK78cV4yjM+pVZoxmw8yVgdZdEA8eAA0K+ia6hHfs55+5O1hm8dDskhB 8QLMEvHL2ik9IkdCzcSdv6ACV2p8Ibnt+Ov8lqqw= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771437465445516440 X-GMAIL-MSGID: 1771437465445516440 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" } } */