From patchwork Fri Jul 5 14:25:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nina Dinka Ranns X-Patchwork-Id: 1957342 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlemail.com header.i=@googlemail.com header.a=rsa-sha256 header.s=20230601 header.b=L+aTO4AG; 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 4WFwmh01y1z1xqb for ; Sat, 6 Jul 2024 00:26:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E68213885C18 for ; Fri, 5 Jul 2024 14:26:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by sourceware.org (Postfix) with ESMTPS id 1CFEE388459B for ; Fri, 5 Jul 2024 14:25:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1CFEE388459B Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=googlemail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=googlemail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1CFEE388459B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f32 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720189555; cv=none; b=D4zghNCoJpLnR9X8VevOfuA9FW48uyfTVJWMMDG6gos2u4MIDk88W9vyVzY4aILRv1Frmn9PjfDluQFTe39uy6H2Sds620XJX9MyLwZQ4amFnfGWh3MqeCP9WfMDmE6SgsXXTCmy62tWSxlsXT/U3gpJ4f8JdJx0A7lCgWDgcvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720189555; c=relaxed/simple; bh=WZdfSOFJfdE3WDN9h6fgMf/UQeAQXQmW1uKOyBUItqI=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=AloYNazRs0wf8YRLF6LuhC2p+3e2ZdEIR0LOSVB4qvb4uEvU5Sxe5k2wElOjbrbI+Tiev7ulK+/zNZV8cTzd+Vp2hwwi4e+80BTmxI4wrnnSnNEjLYJYfj5CTviQgBubECVyGLCnLSfAdkOuBiwktWFLeQtF3S4wh7AFG2h09yk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf32.google.com with SMTP id 6a1803df08f44-6b5f128b199so7086356d6.0 for ; Fri, 05 Jul 2024 07:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1720189552; x=1720794352; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=Ev6/psZWDc37KCnISBQ5JjOHkT6N+z4ISCgxYwW2FSw=; b=L+aTO4AGqH0dejyv9K+xnULxT1KHrn0M0hlduKFXf9tsi9zJLYjWDsb34nkecyAZBN JyBPT4rM4j+tHWz5B1FSnbNGuJMihF7FgIsha5B/Yx/NZQkXrfd5zkC8MzuQqx7Irq3k bh3sY+7XpajFpNLxEOtfiVT0W8zDXfYXUFth2ADabmxJU1RmPlhWkg1chAeIFfMw+RMo f+EI/sG/RHDg5OUgimYLtzv8kbGbYZ/wVSxSlhYIXXB398v0jrs3ftChA5Vlry8mmvKp 07ZZTKuuHrQeaJPVupeivSOZAXOcRmWtfHzSN8AOWY31lWSYSvDNqmQH8jzLr7jn9IaV Chug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720189552; x=1720794352; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Ev6/psZWDc37KCnISBQ5JjOHkT6N+z4ISCgxYwW2FSw=; b=cDzDvKyui0YW36XE3hIHTreyZ7A/g6XBr96w0ja84All0CRMcndpRvUlez86e6KUWj 5001wvh5iQV2o8B6TP0KzW0e4LSOh5qoMLm7Tv8+t3rlbGhf0STwcflcbFI+Z9FJLkW6 49Zgbj6ffL2scE1E55fYLQyEF5XpklOtRfNsHdAa5Zj/5PY/YZAZnDDCJHw88DeExbaT igz3y/MYEWrFT1AZAw7xBpEl4z5kn/qq01T4p0uDjTdDAfTikZ7+i2kNA31KFRus7iHk oK+SkSu6LqXeReNJFuoFkAclR+x0kBZb0WCjBPRZ8xkz1475GKIPzU7u3aQY5zUDOSh4 zArw== X-Gm-Message-State: AOJu0YyxiQUQCV9Ovx0hHR7m/7SHdpxA72uZ6nsoFWMIP/SMT0wfC6dM Y19Cjm5wJB1eu4GU/3fg7b7rdXZgHUTE8Xhmf7kXRB4pYz8T5cjr5+uHniEsH3V9HcsLqPogB9K 4cFC0MtViSjebLY/6RLFqAexeX/K+K3Ei X-Google-Smtp-Source: AGHT+IFp1AEmqZWIejq7mvkXVFAXmXjz0a6mFIB5ahLs2+4kVLGj0pugxiUwwKWgfGSBkZae2wtRzFRZPnmnoNzzpf4= X-Received: by 2002:a05:6214:cab:b0:6b5:d94f:cf45 with SMTP id 6a1803df08f44-6b5ed00ee2cmr53240786d6.35.1720189552237; Fri, 05 Jul 2024 07:25:52 -0700 (PDT) MIME-Version: 1.0 From: Nina Dinka Ranns Date: Fri, 5 Jul 2024 15:25:41 +0100 Message-ID: Subject: [PATCH] c++, contracts: Fix ICE in create_tmp_var [PR113968] To: gcc-patches List Cc: Jason Merrill , Iain Sandoe X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Certain places in contract parsing currently do not check for errors. This results in contracts with embedded errors which eventually confuse gimplify. Checks for errors added in grok_contract() and cp_parser_contract_attribute_spec() to exit early if an error is encountered. Tested on x86_64-pc-linux-gnu Signed-off-by: Nina Ranns --- PR c++/113968 gcc/cp/ChangeLog: * contracts.cc (grok_contract): Check for error_mark_node early exit * parser.cc (cp_parser_contract_attribute_spec): Check for error_mark_node early exit gcc/testsuite/ChangeLog: * g++.dg/contracts/pr113968.C: New test. Signed-off-by: Nina Ranns --- gcc/cp/contracts.cc | 7 ++++++ gcc/cp/parser.cc | 3 +++ gcc/testsuite/g++.dg/contracts/pr113968.C | 29 +++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 gcc/testsuite/g++.dg/contracts/pr113968.C diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc index 634e3cf4fa9..a7d0fdacf6e 100644 --- a/gcc/cp/contracts.cc +++ b/gcc/cp/contracts.cc @@ -750,6 +750,9 @@ tree grok_contract (tree attribute, tree mode, tree result, cp_expr condition, location_t loc) { + if (condition == error_mark_node) + return error_mark_node; + tree_code code; if (is_attribute_p ("assert", attribute)) code = ASSERTION_STMT; @@ -785,6 +788,10 @@ grok_contract (tree attribute, tree mode, tree result, cp_expr condition, /* The condition is converted to bool. */ condition = finish_contract_condition (condition); + + if (condition == error_mark_node) + return error_mark_node; + CONTRACT_CONDITION (contract) = condition; return contract; diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 31ae9c2fb54..22c5e760aee 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -30835,6 +30835,9 @@ cp_parser_contract_attribute_spec (cp_parser *parser, tree attribute) return error_mark_node; } + if (contract == error_mark_node) + return error_mark_node; + return finish_contract_attribute (attribute, contract); } diff --git a/gcc/testsuite/g++.dg/contracts/pr113968.C b/gcc/testsuite/g++.dg/contracts/pr113968.C new file mode 100644 index 00000000000..fbaad1c930d --- /dev/null +++ b/gcc/testsuite/g++.dg/contracts/pr113968.C @@ -0,0 +1,29 @@ +// check that an invalid contract condition doesn't cause an ICE +// { dg-do compile } +// { dg-options "-std=c++2a -fcontracts " } + +struct A +{ + A (A&); +}; +struct S +{ + void f(A a) + [[ pre : a]] // { dg-error "could not convert" } + [[ pre : a.b]]// { dg-error "has no member" } + { + + } +}; +void f(A a) + [[ pre : a]] // { dg-error "could not convert" } + [[ pre : a.b]]// { dg-error "has no member" } + { + [[ assert : a ]]; // { dg-error "could not convert" } + [[ assert : a.b ]];// { dg-error "has no member" } + } + +int +main () +{ +}