From patchwork Wed Apr 5 14:02:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 79628 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp339917vqo; Wed, 5 Apr 2023 07:14:47 -0700 (PDT) X-Google-Smtp-Source: AKy350YwIrcW6e0D0IwmntsjQ6L6QG4E5xRjlC1xH0y66VitRu7D+NmdjzsA301A98Wkoe4xyDJB X-Received: by 2002:a17:906:4a8b:b0:944:43e:7983 with SMTP id x11-20020a1709064a8b00b00944043e7983mr3267034eju.67.1680704087330; Wed, 05 Apr 2023 07:14:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680704087; cv=none; d=google.com; s=arc-20160816; b=X274bUS2G2rCwlb3U5ogv+a3YVpzFsBdlJcG2hT5VE2t4NnoIMhjSOUPQDteg/KGz5 cFVjWHz1d9I/fXdIPPF6OgBY0vAmssvSVMZC3MlLmXZa+Az8iG3XPmK+Uf7RA3JWyCkX B0DE9vBzaoEu2/0xP5ADd0qZAQp1Ei4mmBDMUytb3/DXJPUzYNtf2GItzPylL4J7e7E4 KVl1EgsklHvC+57H2aNrY0v/ZfgSXKG+9bWMvCFq8MuxcQkANcpSYbTA01JXeJSI45Pb gYYn41ATNOIT3ffOBRgzQBWbolqdaNQCjVQ6AAQFAiXMj1TpN3Ided9q07DuKx2g8tkO 2GTQ== 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=ijCAWty14IN6VF2vyYT9cikgJKQ0mlLXSf1w3+dmMVc=; b=wo5vmOL0cfJSrAJw59CSoR8HEelMzHSSeeDfnR6/wWzZ2yQJL4Um0eylegUURVHN9s wNhTaeQKyu8tQn7EmRsKul3CZtj2RNEDO2gEppd+Id0jl7F47ZEeinDJ0LpmoNHgMOb3 7GbG5iiYrNwQ32omQqSa9AZjJXXWCzzJ0vjZuQ5PtAF/49cViaze30ulw+HjVtxIRYpZ xAJgzRdEIIMwSP7K+kTwXSpatUZbY9Gn490L8qdA/UdNRH2TiVaqfHWLCfeLmaLDvgGR 3RDK1Y89pnid2SVbZwGDr5RblsIFgbiutCTa1aVPNvo9yl15QavZ52KXyrJ4PCscvbr2 W4vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=O1w4Hby7; 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" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id p11-20020a170906b20b00b0093defbd6296si1365666ejz.1053.2023.04.05.07.14.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:14:47 -0700 (PDT) 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=@embecosm.com header.s=google header.b=O1w4Hby7; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 114A7396E022 for ; Wed, 5 Apr 2023 14:08:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id DECBF38555BF for ; Wed, 5 Apr 2023 14:05:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DECBF38555BF 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-wm1-x334.google.com with SMTP id d11-20020a05600c3acb00b003ef6e6754c5so18371167wms.5 for ; Wed, 05 Apr 2023 07:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703537; 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=ijCAWty14IN6VF2vyYT9cikgJKQ0mlLXSf1w3+dmMVc=; b=O1w4Hby7lhrGO8DLS+F92oigpwfTxD4zRZ/Kf/WapjV81TMYP+iQhtScS9uDdP0Z6k 0Mykd3f9wWYYYLma9e1rtayT/2/h03fxW+R3Zr10WOsNwxWG1OuaLnY540+wJn7fgWPR nMjTgoenthsTmm+zaCR9nI4bnBj1GEaP8eH70vmIvllkm5axyXD1XT7Djxgoj5y3VcyI 8SFPfy/xMqRYjAiSFjE4Es4M8tfRX/uon1FRVs7dYCIT4lOoCLaBG5+1mlM4jSQR6Wp3 kB0LYNmQ2EtJcjCSIL9YTVFaf0qmuBNutD+Tmd2cMiWAWnX+QsEBhfql9lTK/nqDI7x4 EbxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703537; 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=ijCAWty14IN6VF2vyYT9cikgJKQ0mlLXSf1w3+dmMVc=; b=Rvwu+ZaeP1cWfSaspcVhNh4p3NtBQ2c0RQFShlBAc4XsC9MFXLYjEQSCgsSLTCKgBL tIayN1kHJ24jDLfDd+a5xjggVy4NlhbZAcbNTeR5elXWAMVe23o2HsPiHtD0JFrVgtGV milxeFfwxkkCiDW2YPeJQ+rlDDDipBL/8bK3AOKqXMVCmnpyxiyCrxewqWZOmP+oSadK 9vo1b/APYHQcRSM7pgK0euYZCx6AQ9pYA6cYTGlm5fvcFaVaCI+OefaQ0DE7GFR5XSh+ Du7cm1m3eGVUqzxY88KGhkiGFmH5RGb0R6lFYmU5BkcZX56ca5Xc7W7dcOK7sADdKnAE Wz4A== X-Gm-Message-State: AAQBX9eljqZ4a88v78Z8VyRQfCBj7kaFXyYsPf2abAPggs8y4XFSzPXn heAv1tlpxoaDXl1Y5+Ltvujo9qui7NgB8bctWA== X-Received: by 2002:a7b:c301:0:b0:3ef:5dd6:2f94 with SMTP id k1-20020a7bc301000000b003ef5dd62f94mr4738550wmj.31.1680703537384; Wed, 05 Apr 2023 07:05:37 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.05.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:37 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Lyra Subject: [committed 14/88] gccrs: Do not crash on empty macros expand. Fixes #1712 Date: Wed, 5 Apr 2023 16:02:58 +0200 Message-Id: <20230405140411.3016563-15-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405140411.3016563-1-arthur.cohen@embecosm.com> References: <20230405140411.3016563-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, 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?1762345969074373634?= X-GMAIL-MSGID: =?utf-8?q?1762345969074373634?= From: Lyra This commit fixes a compiler crash when expanding an empty macro into an existing AST. gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (transcribe_expression): Fix ICE when expanding empty macros. gcc/testsuite/ChangeLog: * rust/compile/macro45.rs: New test. Signed-off-by: Lyra Karenai --- gcc/rust/expand/rust-macro-expand.cc | 2 ++ gcc/testsuite/rust/compile/macro45.rs | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 gcc/testsuite/rust/compile/macro45.rs diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 9c3523e0515..bf914ee19e3 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -839,6 +839,8 @@ static AST::Fragment transcribe_expression (Parser &parser) { auto expr = parser.parse_expr (); + if (expr == nullptr) + return AST::Fragment::create_error (); return AST::Fragment::complete ({std::move (expr)}); } diff --git a/gcc/testsuite/rust/compile/macro45.rs b/gcc/testsuite/rust/compile/macro45.rs new file mode 100644 index 00000000000..52dbcbb0016 --- /dev/null +++ b/gcc/testsuite/rust/compile/macro45.rs @@ -0,0 +1,7 @@ +macro_rules! empty { + () => {}; // { dg-error "found unexpected token '\}' in null denotation" } +} + +fn main() { + let a = empty!(); +}