diff options
author | CohenArthur <arthur.cohen@epita.fr> | 2021-03-29 21:08:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-29 20:08:21 +0100 |
commit | ff1eca9a578bb8ff5d35a64e96f6b17fb5f6f81e (patch) | |
tree | 498202910e11fd250591dd590b5cb1149d1dc200 /gcc | |
parent | 099fcbd107ad6139de2c387c62327d0d189a5261 (diff) | |
download | gcc-ff1eca9a578bb8ff5d35a64e96f6b17fb5f6f81e.zip gcc-ff1eca9a578bb8ff5d35a64e96f6b17fb5f6f81e.tar.gz gcc-ff1eca9a578bb8ff5d35a64e96f6b17fb5f6f81e.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.cc | 2 | ||||
-rw-r--r-- | gcc/testsuite/rust.test/xfail_compile/cfg_attr.rs | 7 |
2 files changed, 8 insertions, 1 deletions
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<AST::Attribute> &attrs) const void MacroExpander::expand_cfg_attrs (std::vector<AST::Attribute> &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() { +} |