From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 9B73A3846903 for ; Tue, 21 Feb 2023 12:03:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B73A3846903 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-x433.google.com with SMTP id o4so4163564wrs.4 for ; Tue, 21 Feb 2023 04:03:37 -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=wzZ9ijmdBPeytukQcGOoeJFBypEIdqPoBmJHD9HN3N4q/7iYpgHhXQADr/EH6qohC6 GcNBcYNetzU62fQx9DYEYCIcvyq7ErSCspFZvouIxe89IWR7ofYldLYMCwPViTVJ5jXg 1cITd8QtzxV7hulvlqKJWKH0kIUgelN0Zf/A0at5m3UG2OpY5dmqbs8g1oNOlbAlStQc etz9J8ZxfjLyvLbBC1o98/8zoIxbux5qIbw7ztBE9dTg82gLFxVQsXPxW2yZvLOzQWUi chyK7N/Z7lth3+y7hKaL19jgiJ6RCfG7wMV+JjiRRRZ/yJE7xPt+LQ9MSRBX5BuQku/G ftYw== X-Gm-Message-State: AO0yUKWxnU9iGbMKxrkSG7jgVUjNn2hokOP7w6G1/KKmmb7cv7Ba57wL 7K1q+CPltfUwALmcWzfSFMw6RUMwXFFYnOTJ/Q== X-Google-Smtp-Source: AK7set/19SPG30N5/QkuvroF6HqSlVlr/ozkeUj1admHoajLRhexG1exWQ52Jpo9IsaVZKq9Va3Tqg== 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=20Poulhi=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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 .*" } +} -- 2.39.1