aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/expand/rust-cfg-strip.cc
diff options
context:
space:
mode:
authorAntonio Gomes <antoniospg100@gmail.com>2024-07-18 22:50:54 -0300
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-19 15:32:00 +0100
commitaf654898a7b10b8789f6f0246169e24f4743643c (patch)
tree4d211671adabfd21ea427121ffd2f44be0981077 /gcc/rust/expand/rust-cfg-strip.cc
parent9a13dc48a3ac3282aaf9a77516b4f02faa60e393 (diff)
downloadgcc-af654898a7b10b8789f6f0246169e24f4743643c.zip
gcc-af654898a7b10b8789f6f0246169e24f4743643c.tar.gz
gcc-af654898a7b10b8789f6f0246169e24f4743643c.tar.bz2
gccrs: Properly striping struct fields when using attrs
gcc/rust/ChangeLog: * expand/rust-cfg-strip.cc: Strip struct expr fields and strip fields in struct definition * expand/rust-cfg-strip.h: Signatures for new function maybe_strip_struct_expr_fields gcc/testsuite/ChangeLog: * rust/compile/macro-issue2983_2984.rs: Add test to check for correct stripped fields Signed-off-by: Antonio Gomes <antoniospg100@gmail.com>
Diffstat (limited to 'gcc/rust/expand/rust-cfg-strip.cc')
-rw-r--r--gcc/rust/expand/rust-cfg-strip.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc
index 8abc5cb..4e6a8ac 100644
--- a/gcc/rust/expand/rust-cfg-strip.cc
+++ b/gcc/rust/expand/rust-cfg-strip.cc
@@ -195,6 +195,26 @@ CfgStrip::maybe_strip_struct_fields (std::vector<AST::StructField> &fields)
}
void
+CfgStrip::maybe_strip_struct_expr_fields (
+ std::vector<std::unique_ptr<AST::StructExprField>> &fields)
+{
+ for (auto it = fields.begin (); it != fields.end ();)
+ {
+ auto &field = *it;
+
+ auto &field_attrs = field->get_outer_attrs ();
+ expand_cfg_attrs (field_attrs);
+ if (fails_cfg_with_expand (field_attrs))
+ {
+ it = fields.erase (it);
+ continue;
+ }
+
+ ++it;
+ }
+}
+
+void
CfgStrip::maybe_strip_tuple_fields (std::vector<AST::TupleField> &fields)
{
for (auto it = fields.begin (); it != fields.end ();)
@@ -962,6 +982,8 @@ CfgStrip::visit (AST::StructExprStructFields &expr)
"cannot strip expression in this position - outer "
"attributes not allowed");
}
+
+ maybe_strip_struct_expr_fields (expr.get_fields ());
}
void
@@ -1852,6 +1874,10 @@ CfgStrip::visit (AST::StructStruct &struct_item)
}
AST::DefaultASTVisitor::visit (struct_item);
+
+ /* strip struct fields if required - this is presumably
+ * allowed by spec */
+ maybe_strip_struct_fields (struct_item.get_fields ());
}
void
CfgStrip::visit (AST::TupleStruct &tuple_struct)