From ff1eca9a578bb8ff5d35a64e96f6b17fb5f6f81e Mon Sep 17 00:00:00 2001 From: CohenArthur Date: Mon, 29 Mar 2021 21:08:21 +0200 Subject: Fix infinite loop when expanding cfg attributes (#319) rust-macro-expand: Fix infinite loop in cfg_attr expansion Expanding the cfg_attrs wasn't incrementing the index at which to access the attribute to expand, so the compiler was stuck in expanding the same attribute over and over again in some cases. Fixes #320 --- gcc/rust/expand/rust-macro-expand.cc | 2 +- gcc/testsuite/rust.test/xfail_compile/cfg_attr.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/rust.test/xfail_compile/cfg_attr.rs (limited to 'gcc') diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index b2a0bb5..496b451 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -3330,7 +3330,7 @@ MacroExpander::fails_cfg_with_expand (std::vector &attrs) const void MacroExpander::expand_cfg_attrs (std::vector &attrs) { - for (std::size_t i = 0; i < attrs.size ();) + for (std::size_t i = 0; i < attrs.size (); i++) { auto &attr = attrs[i]; if (attr.get_path () == "cfg_attr") diff --git a/gcc/testsuite/rust.test/xfail_compile/cfg_attr.rs b/gcc/testsuite/rust.test/xfail_compile/cfg_attr.rs new file mode 100644 index 0000000..95e636b --- /dev/null +++ b/gcc/testsuite/rust.test/xfail_compile/cfg_attr.rs @@ -0,0 +1,7 @@ +use std::env; // Add one line so gccrs doesn't believe we're parsing a shebang + +#[cfg_attr(feature = "somefeature", attribute = "someattr")] +struct Feature; + +fn main() { +} -- cgit v1.1