From patchwork Tue Nov 29 20:03:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 27482 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp542054wrr; Tue, 29 Nov 2022 12:04:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf5VbgsjT1VuG0Zyvk3PCCWRwantXWoR6+N/My6/6pP3P5VzNYjn/te0ds+Xv8zBxMWs3pQZ X-Received: by 2002:a17:906:cf85:b0:78d:b66d:749f with SMTP id um5-20020a170906cf8500b0078db66d749fmr47017396ejb.566.1669752258327; Tue, 29 Nov 2022 12:04:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669752258; cv=none; d=google.com; s=arc-20160816; b=HVst86j4AIVqdxr5wJ8eAQr/zJ4eKQeVWqls4NoHNuGplxUjph+tgcTUQfPZ8oJXw/ VPCwhITMC9VY++utSnUH2bmKuUs9qgcLnhyh3izqWsA3zznbES29GBu8h9Y75jEvL7hf AGPN8m8Pu9yxbYNTWYUnbB+Jgp+/DH3rhtfKGjNQUlq7p3VKFI78YF434rttmLX5chAg fBQ57bu2ssvDl9Y3wpWO9BzPwh9r4snBBnvoGT7kOv7YX0fzp+nz+sR7w5M/j9sa55UM QCGwlLreU+Bu63lzNfUdGyHd1g9kGEFF30FLkVVzEpPZ0nAY5KC+T3aHE/6tyLySDnQm vVCw== 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=4kxxlTV2GLRdbmBbj22b+XjJuB2Ua1uxTq8M6VtZj5I=; b=lPrrskVJjgo4R+8oW8v8d1MLjR3D2C2i49E6uP/76BzUneTnJQpk8MzNo8j9/BsG65 C/lIJNc+2GD8FxEBeWaovbvyIUt6pI6hZOVEEO87txIok7XMyTidpWDkHaQYbTnVcpBB mUBf4Tms7CbjHlDXBpYDMDVAdX8NYr7cHF1Z3+T72ImZpEQiNX5Ukn/hKULDAc9DMHVX pkZLdzQzq6oQN13sWRCf5c+kZv8FYlEfwt6TRoVkoc2J/z90z29jBpH4SOCDN1QYTJ+B RaRHsbrm4nbWPqyZ0LYjBE7UvsMOfCVocSMOzG5N6XSWJDmKwQVh779gCNiuPc8ucJ5s FuDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eMM8qtoD; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 17-20020a170906059100b007ae1e519db0si9997002ejn.220.2022.11.29.12.04.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 12:04:18 -0800 (PST) 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=eMM8qtoD; 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 E9C323858C36 for ; Tue, 29 Nov 2022 20:04:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E9C323858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669752257; bh=4kxxlTV2GLRdbmBbj22b+XjJuB2Ua1uxTq8M6VtZj5I=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=eMM8qtoDGmKRFhv7OfBLmYe44/s8/uDbVIkSRcnTtS61ER/8w7iCvSmhg12uHJFa6 e2AWb2e9rTS3rH+hJ2bB8GvOwUug+TEKWsTUg2ImnejJX5L8C4cW2cMLfULVj+xMCn BnmT8UykeC547JxdHVxcMOPIkXuPl+fl/z6ifLzY= 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 6E1783858D1E for ; Tue, 29 Nov 2022 20:03:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E1783858D1E Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-651-7FEh3U10N-a-6pBOyLZE6Q-1; Tue, 29 Nov 2022 15:03:26 -0500 X-MC-Unique: 7FEh3U10N-a-6pBOyLZE6Q-1 Received: by mail-qv1-f71.google.com with SMTP id b2-20020a0cfe62000000b004bbfb15297dso21548464qvv.19 for ; Tue, 29 Nov 2022 12:03:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=4kxxlTV2GLRdbmBbj22b+XjJuB2Ua1uxTq8M6VtZj5I=; b=inWBI2e3wHTke573gopSycuD5tahEWdtqopocf7BqKwmYHIwJCvQr2XjCZO5ezrKNK hMD1LRB2NDZ9KlfCIniZs7bYTe8cG/41pLCIlunD6JPXoP5re2VJmUFX7SwKL74eYPjU vo4vT7PCVMKt9MQhHYQfg+Da+Uwm5eytLGIZhwd03BsheB/7N6RbDuRWVlV653G2qkH1 Q531U/dRVkX0l3knwKC/VWGeuNbGfeSzGaGcYbBA9B2zEkkWqugcsNt3JtAmxiB9fs2i H0u98z0dlpYqK7IaVGdnA4nTjmeul3KFDsqgd3vvgYg8mGahWx+6HSBm6KOmQpZQJ9IO zSkA== X-Gm-Message-State: ANoB5pkq6zS12K7upjvM0ZID19VijOfvM3vn4UqEKqU0HKQOrXj4ZeVY Nn80aXXe96GLfugG4f4wepKxOm4zbqq/tWBMXHH8Oib1N+V0fIDWbMhkWAGrxH5XcgxY09GkUW2 W6CPycC3//Gd+y/4DGZmBjZhyfFuX9Irw7864bBpKqwm69XEthYwJg1jt5alnPJJqpVs= X-Received: by 2002:a37:b401:0:b0:6fa:2aef:51ff with SMTP id d1-20020a37b401000000b006fa2aef51ffmr32233808qkf.270.1669752205041; Tue, 29 Nov 2022 12:03:25 -0800 (PST) X-Received: by 2002:a37:b401:0:b0:6fa:2aef:51ff with SMTP id d1-20020a37b401000000b006fa2aef51ffmr32233774qkf.270.1669752204682; Tue, 29 Nov 2022 12:03:24 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id n1-20020a05620a294100b006fa16fe93bbsm11366510qkp.15.2022.11.29.12.03.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 12:03:23 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: ICE with <=> of incompatible pointers [PR107542] Date: Tue, 29 Nov 2022 15:03:22 -0500 Message-Id: <20221129200322.1544250-1-ppalka@redhat.com> X-Mailer: git-send-email 2.39.0.rc0.49.g083e01275b MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.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_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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750862144162792943?= X-GMAIL-MSGID: =?utf-8?q?1750862144162792943?= In a SFINAE context composite_pointer_type returns error_mark_node if the given pointer types are incompatible, but the SPACESHIP_EXPR case of cp_build_binary_op wasn't prepared to handle error_mark_node, which led to an ICE (from spaceship_comp_cat) for the below testcase where we form a <=> with incompatible pointer operands. (In a non-SFINAE context composite_pointer_type issues a permerror and returns cv void* in this case, so no ICE.) Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/12? PR c++/107542 gcc/cp/ChangeLog: * typeck.cc (cp_build_binary_op): Handle result_type being error_mark_node in the SPACESHIP_EXPR case. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/spaceship-sfinae2.C: New test. --- gcc/cp/typeck.cc | 5 ++-- .../g++.dg/cpp2a/spaceship-sfinae2.C | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-sfinae2.C diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index f0e7452f3a0..10b7ed020f7 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -6215,8 +6215,9 @@ cp_build_binary_op (const op_location_t &location, tree_code orig_code0 = TREE_CODE (orig_type0); tree orig_type1 = TREE_TYPE (orig_op1); tree_code orig_code1 = TREE_CODE (orig_type1); - if (!result_type) - /* Nope. */; + if (!result_type || result_type == error_mark_node) + /* Nope. */ + result_type = NULL_TREE; else if ((orig_code0 == BOOLEAN_TYPE) != (orig_code1 == BOOLEAN_TYPE)) /* "If one of the operands is of type bool and the other is not, the program is ill-formed." */ diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-sfinae2.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-sfinae2.C new file mode 100644 index 00000000000..52ff038b36f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-sfinae2.C @@ -0,0 +1,29 @@ +// PR c++/107542 +// { dg-do compile { target c++20 } } + +#include + +template +concept same_as = __is_same(T, U); + +template +concept Ord = requires(const Lhs& lhs, const Rhs& rhs) { + { lhs <=> rhs } -> same_as; +}; + +static_assert(Ord); // Works. +static_assert(!Ord); // ICE. + +template +struct S { + T* p; +}; + +template + requires(Ord) +constexpr inline auto operator<=>(const S& l, const S& r) noexcept { + return l.p <=> r.p; +} + +static_assert(Ord, S>); // Works. +static_assert(!Ord, S>); // ICE.