From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 18CB7383468E for ; Wed, 5 Apr 2023 14:06:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 18CB7383468E 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 e18so36328723wra.9 for ; Wed, 05 Apr 2023 07:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703583; 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=ZJGzI+1+8dpVv/ULvDh1J2DnRrWjTQOcHB2rF70bhBw=; b=GVpKDNxLoimU7ID2QG4rZHqSaf2otqDhgXmXvtNFuv9tSmEBIERuB6dfaTpGNtn/wh lgK6afjAPrrXLDIch2/PAT+FQuL/lyOsP2OCG0E8mpSlIty7IKb8G9CVtrihqDLkpOuL BBYAQ1uFjwG7SVS6gqY4IZzvtUEpxGPSgvb5extuRKV4qdom69vnVbLUzk9EpSK2RqZP zC7YuaQ1nGOWDn2mwQHQevonPLPBXLaoycPR2aB8LFFcwYn3r+OL5V75PUs1CmWENwZC msK6WzO5ZOHt/2rNKRb0ONRyhEr5GaT9HMVC6DVmdfEUo7qHasi0BNqz3DldqPBqrWFT mp0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703583; 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=ZJGzI+1+8dpVv/ULvDh1J2DnRrWjTQOcHB2rF70bhBw=; b=hHhGA8FFVEBfZdMxMAgANyCPwer9Ux8uZ0/lQ2BeWNDXZCHeN4u0IeZ7OmC9zOgFwQ z0BHU7mm8NaVLwthPh33kdG3CMVRatAZbEfUHZIQZOWvsOseSGk61ZuSi47ScJGLiNR4 Lzbd6FXzyiR7i4Eu+yENlBJPk9liHz4ItadrXIKP3P2v4WF0jencjhKCnqpbBxydiyKT xInSaH5HQdnK8lNg2xJeCGZ+HEzi50Zn5p9FrDGO+ZGb39/dNmXRlfKQQPMTbYpvJsv6 0zrVwKo7q5mH7yJ4M0SdskpJrlqNGa4aGrjNu5IpUvYkH0jmsBSNBrGbmdWAvNt7uPIu QAoA== X-Gm-Message-State: AAQBX9czfijeXb9lCSdf6G+SPYIj7QqfaOiBI0GC0gy0hKpHZKHG0g+1 Tt6TS8To2L25pQDQNjk22RHBEU9E8RkSPW1bYA== X-Google-Smtp-Source: AKy350a21oNmBpaOxZwZ7GX0mObox7B+vqdPASDaQVFOeuyQleYDlKTCwnJUOJZWg58LW7ZwAZlPRg== X-Received: by 2002:adf:cf09:0:b0:2d6:adfe:cea5 with SMTP id o9-20020adfcf09000000b002d6adfecea5mr4067907wrj.68.1680703582853; Wed, 05 Apr 2023 07:06:22 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:22 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 78/88] gccrs: builtins: Return empty list of tokens instead of nullptr Date: Wed, 5 Apr 2023 16:04:02 +0200 Message-Id: <20230405140411.3016563-79-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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.5 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: Arthur Cohen gcc/rust/ChangeLog: * expand/rust-macro-builtins.cc (MacroBuiltin::include_handler): Do not return nullptr token in expansion of `include!()` gcc/testsuite/ChangeLog: * rust/compile/empty.in: New test. * rust/compile/include_empty.rs: New test. --- gcc/rust/expand/rust-macro-builtins.cc | 15 +++++++++++++-- gcc/testsuite/rust/compile/empty.in | 1 + gcc/testsuite/rust/compile/include_empty.rs | 8 ++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/rust/compile/empty.in create mode 100644 gcc/testsuite/rust/compile/include_empty.rs diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index 3b6f69bbd69..97594921dec 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -752,8 +752,19 @@ MacroBuiltin::include_handler (Location invoc_locus, AST::MacroInvocData &invoc) nodes.push_back (node); } - // FIXME: Do not return an empty token vector here - return AST::Fragment (nodes, nullptr); + // FIXME: This returns an empty vector of tokens and works fine, but is that + // the expected behavior? `include` macros are a bit harder to reason about + // since they include tokens. Furthermore, our lexer has no easy way to return + // a slice of tokens like the MacroInvocLexer. So it gets even harder to + // extrac tokens from here. For now, let's keep it that way and see if it + // eventually breaks, but I don't expect it to cause many issues since the + // list of tokens is only used when a macro invocation mixes eager + // macro invocations and already expanded tokens. Think + // `concat!(a!(), 15, b!())`. We need to be able to expand a!(), expand b!(), + // and then insert the `15` token in between. In the case of `include!()`, we + // only have one argument. So it's either going to be a macro invocation or a + // string literal. + return AST::Fragment (nodes, std::vector> ()); } AST::Fragment diff --git a/gcc/testsuite/rust/compile/empty.in b/gcc/testsuite/rust/compile/empty.in new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/gcc/testsuite/rust/compile/empty.in @@ -0,0 +1 @@ + diff --git a/gcc/testsuite/rust/compile/include_empty.rs b/gcc/testsuite/rust/compile/include_empty.rs new file mode 100644 index 00000000000..28e940fa0ac --- /dev/null +++ b/gcc/testsuite/rust/compile/include_empty.rs @@ -0,0 +1,8 @@ +#[rustc_builtin_macro] +macro_rules! include { + () => {}; +} + +include!("empty.in"); + +fn main() {} -- 2.40.0