From patchwork Tue Feb 21 12:01:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59969 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1826804wrn; Tue, 21 Feb 2023 04:12:33 -0800 (PST) X-Google-Smtp-Source: AK7set9fFpmyhEjzjKqYFnCPG5TWLShyLzk9TL7B+NoLn3U71H1715LaQcBBXvSHqUmGd6OGBTVG X-Received: by 2002:aa7:d5c9:0:b0:4ad:6db4:b922 with SMTP id d9-20020aa7d5c9000000b004ad6db4b922mr4853175eds.14.1676981553288; Tue, 21 Feb 2023 04:12:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981553; cv=none; d=google.com; s=arc-20160816; b=mequPJCBn8iZGUWYwI3VnjvqwQunyz7W476QnoCSgH2/W7qPsk94wX+TaxcMNN7vCT Rd5+1WTIlu6qaJgZlNEw7lkJNb/argtcNa2KXzBOZjIlyVdlC+ckF8vkSmBXqV+6k5QX JliYQX2PxV2rOwLPLFbNTynQYWJUZ/6V3V/26vy39e1RBVcc4/nbk2gWNejyTTEVe19v AIrGI1x7RgzPfKJXRp3i8x3Qfq8Tdh2L7da2DLLAZzM+VzYLIm1ZnLE6At1Y9RVR5FpM WPpFKP4i8tBHKP69xwm3QRb2e6Gp6suKAY/KBDtzocUm6zoZVZ7kWb60XWfTqWIijpyQ gtIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dmarc-filter :delivered-to; bh=3DSDX42u7UBLloU8IjNfd1l6UUlH+44+y1aYaZdS/E8=; b=O0IEhQt5tMV0BJkMyvBUJUu1UbP2vhCkiD1O89CojfwzuLXhl5Mi5nNws+k+llHbcW M2uyxagCtA5vNbqyXeWXkeQ09euo6Ezl4vYzyLm9lkhkpULS85Ii1dkTmHyhkZAx9COL wRetfYGPBiAsqdH2ELT1f7xpkMYnryJ7qfxxnTq+LZOD/VY4oIvFYnuKMV6FCEGhLMSa IMlZOB6Hj1+FOye9gwInrWj9oTgMue7MhWzMHugRbdDbpKSzZrkOgqzSygR8uYvaU+Rb 6sW4mcpqrIlM02azU8E1ZVnWZ1FKlfsP5ekYSR/iGbWyquD0njpkj5QTJimEKeKSpQVB eOig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=VT1p5UxS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id by11-20020a0564021b0b00b004acdbd726cbsi4586058edb.7.2023.02.21.04.12.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:12:33 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=VT1p5UxS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B66CF383817F for ; Tue, 21 Feb 2023 12:06:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 17845384692A for ; Tue, 21 Feb 2023 12:03:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17845384692A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x42c.google.com with SMTP id bo30so3601255wrb.0 for ; Tue, 21 Feb 2023 04:03:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=3DSDX42u7UBLloU8IjNfd1l6UUlH+44+y1aYaZdS/E8=; b=VT1p5UxSt49/umGiKmHngU5aMVhAg/zOdd7gk9a94lBGcx+3EjwNQ0k2TCKbqdlTvR 4K7Jv4phyXYciWDHNKsf3HJnB2XM71vBhnJj3YVKTX2kyEfPRBLoqbROzJLClzjz7S4c R3Lwl19v3nbEcdiyuIwh7gQgZC6t2iYEBjiC6HKMhDsxpCRoh8mVhmwp55UtQxYD7jOQ dYu8BUc/fLS70yEmMQ5aYdYM5iMf81a0fZ5aBKNhckoULviZFL8QoPM6rgUJ59FWm1L2 12YNLszVjWM3xuEqpdYjcx/NbyoJjZEZLUm8iPmNrbf+4/Cc+s1CNIDIt7VzQdibs6si t96A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=3DSDX42u7UBLloU8IjNfd1l6UUlH+44+y1aYaZdS/E8=; b=3sEE5uH7ZT9IrgKklAh6FVV7kJx3wA/6b2cmtVanMn80tKHNXTgB5kuH7ul8vGzDcP bb8OqT3J5av3lqIsWgM8Hpd6pX2v/7/9VdJaZX+ICRqNnlal1nhI0KJIixeQPt/Lillj rHWRtl+TuWkx38oiS5gb1MDWysxPcAD11X+RTkmsNCAtHnNup3Omirfcd/aOW7feUMr9 hvEbi8FTPdPOW0SmsRmY0WGxkN99ltdRY+O38/fmLNsLoSWohn/2G38kSh8VNCp3UAWD GFQG2jJX/AUAAtn/zyVYZGN5DsIhaXYG8kEk1qo0G8UmOaVWFDJccTaLTzBl0rVHD7fm tu6A== X-Gm-Message-State: AO0yUKVSzAJXJckPRMQguJFkMEwnzw3BqtkLC4NlelDm0cuTu2dBksBi sN09bw0ke81odxsZGsphRfX09lJzHDrfHOb/6g== X-Received: by 2002:adf:d84b:0:b0:2c5:48b9:7307 with SMTP id k11-20020adfd84b000000b002c548b97307mr4225392wrl.64.1676981016530; Tue, 21 Feb 2023 04:03:36 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.03.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:36 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, =?utf-8?q?Marc_Poulhi=C3=A8s?= Subject: [committed 016/103] gccrs: fix ICE on missing closing paren Date: Tue, 21 Feb 2023 13:01:06 +0100 Message-Id: <20230221120230.596966-17-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221120230.596966-1-arthur.cohen@embecosm.com> References: <20230221120230.596966-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable 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: , Reply-To: arthur.cohen@embecosm.com 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?1758442609544542347?= X-GMAIL-MSGID: =?utf-8?q?1758442609544542347?= From: Marc Poulhiès Fix crash (segfault) on a missing closing parenthesis when parsing the expressions in a block. The returned `expr` was missing a check before being used. Add corresponding test. Signed-off-by: Marc Poulhiès gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_stmt_or_expr_without_block): Check if `expr` is valid after parsing it. gcc/testsuite/ChangeLog: * rust/compile/missing_closing_paren.rs: New test. --- gcc/rust/parse/rust-parse-impl.h | 15 +++++++++++---- .../rust/compile/missing_closing_paren.rs | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/rust/compile/missing_closing_paren.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 72207a1bc22..a4a912f8c1d 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -11738,10 +11738,17 @@ Parser::parse_stmt_or_expr_without_block () // must be expression statement lexer.skip_token (); - std::unique_ptr stmt ( - new AST::ExprStmtWithoutBlock (std::move (expr), - t->get_locus ())); - return ExprOrStmt (std::move (stmt)); + if (expr) + { + std::unique_ptr stmt ( + new AST::ExprStmtWithoutBlock (std::move (expr), + t->get_locus ())); + return ExprOrStmt (std::move (stmt)); + } + else + { + return ExprOrStmt::create_error (); + } } // return expression diff --git a/gcc/testsuite/rust/compile/missing_closing_paren.rs b/gcc/testsuite/rust/compile/missing_closing_paren.rs new file mode 100644 index 00000000000..895c3133c3b --- /dev/null +++ b/gcc/testsuite/rust/compile/missing_closing_paren.rs @@ -0,0 +1,3 @@ +fn foo() { + (""; // { dg-error "unexpected token .*" } +}