From patchwork Wed Jan 31 23:41:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 195075 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp95176dyc; Wed, 31 Jan 2024 15:42:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFR2b0rys+2vqdpDkxSnCdGLHCoMXesLF+a2dDTQQFZ4jipE8CylvCpBS0icPnacSVGk6Pv X-Received: by 2002:a05:620a:1267:b0:784:8c6:69c9 with SMTP id b7-20020a05620a126700b0078408c669c9mr950572qkl.73.1706744560500; Wed, 31 Jan 2024 15:42:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706744560; cv=pass; d=google.com; s=arc-20160816; b=USCtWz15y1xc8HSWU0VgW3jyyaVIu6uhHBIriCVdVJ1hjDmmwrgjDPCL2kRi9RqRkS qs/fJocqTBJzxO8vyonW1sumJw0tAn7e9sjg9ehv6TFl6CbQ5e91xTk6WFCgfkoYP6mp oRCLTSyCO5CKDhHdAdOscACGOYvAYRD2lGQ/8dSKGEYojQ7DGvJ5PzbvM9LOY91VVjwF +LvG4n/cXOVdJH2rdiXoWac9mgZnlON89wApLVazJAJa2NR38+cdT5/PfhZnnfndjIR7 qkuH0kn2D4keJbYGdq5gYXKPHelGVF0QDKpK3r/uTj5HMAZIxdIiuL2ZzRL3rKlqw22i M2dw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=c3NLZZKoOjbQ+i6Qcauv+qLcrWQJ16NB/J3YIN9WaHc=; fh=6PQ/33BAXZhk8sHJtWOw/4VzFdP+2PKrhmxihBkokoU=; b=w2vldAETp9O9fmr4gk+5apbTkQgXAnbnMRSsfcs5hslq0nlE253kFTLJhcUy6F6+hX B2IRRnOnCfrIgM7YcKGK0GW4rKNV3yWksZ32A7Si7lBDJgmAjunymwk6XH4FH9Tpetxa TNzmnbNph/XO9ume7PF6c8aBnyNOampSJLWLYjta8ybFDG9IscySqbyqUCFunrWwu5r8 cg1hk5FTqmMBYiNsQ8M5lDuH0/rW8jBY2OqU2FZBhmTf4EpMj3YMcAOom8wZPgF3dnh8 RmrNaCoWfI+15r1KX+sU4zRauX3mtfcCrIuoyyEZ5GQhs0TaRldI9TG8DtXhnLN2e/Hn fXgA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="aOk4f/Sz"; arc=pass (i=1); 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=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCXBCeIo1/4jMX6A7zUPUZP0K5Xga6sLBzx7fSddNw/KA/57bEFXyYlZOucK/9EmMZnw4PQvWYZTRpz8WUOj15UCY7qzWw== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k7-20020ae9f107000000b007838d584725si12685971qkg.554.2024.01.31.15.42.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 15:42:40 -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=@redhat.com header.s=mimecast20190719 header.b="aOk4f/Sz"; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 266D03857728 for ; Wed, 31 Jan 2024 23:42:40 +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 10D453858297 for ; Wed, 31 Jan 2024 23:41:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 10D453858297 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 10D453858297 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=1706744508; cv=none; b=vulrepSVivPeqT5vk66x2mN8WuocjssXNqWAE4xKQihnojg8P8dMLUsR0zbxMQETOcXMi+5YR+xhaca+h2IrLj3LoaWww2EQsmYcRgwfsoA16i4H74wJ1bVCv6OfKDMRNTclCFAJjpuzX/OnvNw0lXTptaCSzFGOP/Q0qI/Ahfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706744508; c=relaxed/simple; bh=DBhgNeTvi7zEL61KUU4JbN7qpE7DGUBQVc1NzrUOwKU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=U8VBYlnqCxbrkbB5aRfek+7i5cRR+SUMcikBzeGkKtnDLfwK9s9sXdhdv5iDWXogcQgah+cx199gu7W0q2sBx8hM/MeyefJWfWcYK5rb7sNmWfxMY5Uls89y81cVYxxXxAL/8n8MKT/vNFvu14OcxIlwyHQFroBsLRYA7cGBEnU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706744505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=c3NLZZKoOjbQ+i6Qcauv+qLcrWQJ16NB/J3YIN9WaHc=; b=aOk4f/SzLow6lgb+iSbUxBWFRNw7nI+Be+YQRKXJV2FsYjD2Pw9/g2ks4VSL7cSbkG5k74 kaHkTT1+ZdASX/LfFRHmiqqQu1p6WZ1P9acSDPdbEuCk4L7wwQAO4jsNKNcv5bWEO22rO0 lDZBMoY2mSd/YETyeWov/0mAjR/8CyY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-212-odk4-zeXPRSNoOi7Kr8Dfw-1; Wed, 31 Jan 2024 18:41:44 -0500 X-MC-Unique: odk4-zeXPRSNoOi7Kr8Dfw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id DE65D88B7A0 for ; Wed, 31 Jan 2024 23:41:43 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.17.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF3832026D66; Wed, 31 Jan 2024 23:41:43 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: ICE with throw inside concept [PR112437] Date: Wed, 31 Jan 2024 18:41:41 -0500 Message-ID: <20240131234141.173999-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 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_H5, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789651384380594215 X-GMAIL-MSGID: 1789651384380594215 Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/13/12? -- >8 -- We crash in the loop at the end of treat_lvalue_as_rvalue_p for code like template concept Throwable = requires(T x) { throw x; }; because the code assumes that we eventually reach sk_function_parms or sk_try and bail, but in a concept we're in a sk_namespace. We're already checking sk_try so we don't crash in a function-try-block, but I've added a test anyway. PR c++/112437 gcc/cp/ChangeLog: * typeck.cc (treat_lvalue_as_rvalue_p): Bail out on sk_namespace in the move on throw of parms loop. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-throw1.C: New test. * g++.dg/eh/throw4.C: New test. --- gcc/cp/typeck.cc | 4 +++- gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C | 8 ++++++++ gcc/testsuite/g++.dg/eh/throw4.C | 13 +++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C create mode 100644 gcc/testsuite/g++.dg/eh/throw4.C base-commit: d22d1a9346f27db41459738c6eb404f8f0956e6f diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index a15eda3f5f8..4937022ff20 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -10863,7 +10863,9 @@ treat_lvalue_as_rvalue_p (tree expr, bool return_p) for (tree decl = b->names; decl; decl = TREE_CHAIN (decl)) if (decl == retval) return set_implicit_rvalue_p (move (expr)); - if (b->kind == sk_function_parms || b->kind == sk_try) + if (b->kind == sk_function_parms + || b->kind == sk_try + || b->kind == sk_namespace) return NULL_TREE; } } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C new file mode 100644 index 00000000000..bc3e3b6891a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-throw1.C @@ -0,0 +1,8 @@ +// PR c++/112437 +// { dg-do compile { target c++20 } } + +struct S {}; +template +concept Throwable = requires(T x) { throw x; }; + +bool a = Throwable; diff --git a/gcc/testsuite/g++.dg/eh/throw4.C b/gcc/testsuite/g++.dg/eh/throw4.C new file mode 100644 index 00000000000..b474472de48 --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/throw4.C @@ -0,0 +1,13 @@ +// PR c++/112437 +// { dg-do compile } + +struct S {}; + +S +foo (S s) +try { + throw s; +} +catch (...) { + throw s; +}