From patchwork Tue Jul 2 19:54:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1955613 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=Vgid4VPC; 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 4WDDD25lHtz1xpc for ; Wed, 3 Jul 2024 05:55:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 168073882172 for ; Tue, 2 Jul 2024 19:55:29 +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 ESMTPS id 1BE133882172 for ; Tue, 2 Jul 2024 19:55:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1BE133882172 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 1BE133882172 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=1719950108; cv=none; b=m7rll5I/L3GUHCe8TIgUqn32B6BGY99sQqwjdXM7AKf+YdeMJH2+gYjfWGDQafvCW3dv2RqMoNrwMXHELmTgzSSjFtphfkDWs5b1dwQJ7RSLoHYgw69rU+kt9OF4G1g7MjCMjA0BtdAOYfICPiToXHq9LuWyN/w3dq8XaB8ngiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719950108; c=relaxed/simple; bh=hLeMcExOSN8rQkq7mS5MXnWLsz4dr7pM+txT1sPBFRU=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=mnEJtx8sti8IpWQz4Obo6syP6QuKhlhYtmYOmCGqOnvz1LKd55Tn2unIbm3jibavnquHmBgHr8y4xCxY1vbeQQXksGi/PNb6bsSNBe3enTOFlJYZdqR95o/4y3s2r6LjabR2Qi0x7Vqihf5TYgKzO/hDoNMZPvRW6hDXy3/uGto= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719950103; 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=EGLEVyKzLBxKG6xGJc9RVFE/XVUg/LnHjQn1HlYc4TU=; b=Vgid4VPCdlGY67DqS9jVRrSelIGgIELyKGuHH3b7cQuU3OKdF9K5IJSOhY5EjRqSbtWkCC xtgUAl9GbsJZW6TyxcgbOcvJM9JG7jadtS/1za8/00b+uKpC2z8D6U0Rr120uR4lHAc39E 7E+TajGSFFqDOkNAqavxPb3VnbFIHPQ= 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-644-ryQQk0hdO1S1BkiHRbWIJg-1; Tue, 02 Jul 2024 15:55:00 -0400 X-MC-Unique: ryQQk0hdO1S1BkiHRbWIJg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 A3BA61956089 for ; Tue, 2 Jul 2024 19:54:59 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.5]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 278FA1956089; Tue, 2 Jul 2024 19:54:57 +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 462JsstU792620 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 2 Jul 2024 21:54:55 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 462JssI9792619; Tue, 2 Jul 2024 21:54:54 +0200 Date: Tue, 2 Jul 2024 21:54:54 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix ICE on constexpr placement new [PR115754] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.8 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! C++26 is making in P2747R2 paper placement new constexpr. While working on a patch for that, I've noticed we ICE starting with GCC 14 on the following testcase. The problem is that e.g. for the void * to sometype * casts checks, we really assume the casts have their operand constant evaluated as prvalue, but on the testcase the cast itself is evaluated with vc_discard and that means op can end up e.g. a VAR_DECL which the later code doesn't like and asserts on. If the result type is void, we don't really need the cast operand for anything, so can use vc_discard for the recursive call, VIEW_CONVERT_EXPR can appear on the lhs, so we need to honor the lval but otherwise the patch uses vc_prvalue. I'd like to get this patch in before the rest of P2747R2 implementation, so that it can be backported to 14.2 later on. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-07-02 Jakub Jelinek Jason Merrill PR c++/115754 * constexpr.cc (cxx_eval_constant_expression) : For conversions to void, pass vc_discard to the recursive call and otherwise for tcode other than VIEW_CONVERT_EXPR pass vc_prvalue. * g++.dg/cpp26/pr115754.C: New test. Jakub --- gcc/cp/constexpr.cc.jj 2024-05-08 10:16:53.966824718 +0200 +++ gcc/cp/constexpr.cc 2024-07-02 18:47:49.646843559 +0200 @@ -8103,7 +8103,10 @@ cxx_eval_constant_expression (const cons tree oldop = TREE_OPERAND (t, 0); tree op = cxx_eval_constant_expression (ctx, oldop, - lval, + VOID_TYPE_P (TREE_TYPE (t)) + ? vc_discard + : tcode == VIEW_CONVERT_EXPR + ? lval : vc_prvalue, non_constant_p, overflow_p); if (*non_constant_p) return t; --- gcc/testsuite/g++.dg/cpp26/pr115754.C.jj 2024-07-02 18:40:08.107750189 +0200 +++ gcc/testsuite/g++.dg/cpp26/pr115754.C 2024-07-02 18:39:57.110890921 +0200 @@ -0,0 +1,36 @@ +// PR c++/115754 +// { dg-do compile { target c++26 } } + +namespace std +{ + using size_t = decltype (sizeof 0); + + template + struct allocator + { + constexpr allocator () noexcept {} + + constexpr T *allocate (size_t n) + { return static_cast (::operator new (n * sizeof(T))); } + + constexpr void + deallocate (T *p, size_t n) + { ::operator delete (p); } + }; +} + +constexpr void * +operator new (std::size_t, void *p) noexcept +{ return p; } + +constexpr bool +foo () +{ + std::allocator a; + auto b = a.allocate (1); + ::new (b) int (); + a.deallocate (b, 1); + return true; +} + +constexpr bool a = foo ();