aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiam Naddell <liam.naddell@mail.utoronto.ca>2024-07-19 14:19:26 -0400
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-17 16:35:53 +0100
commitc7cdae718c24e7a3f68d7090cc9947df5d848fb8 (patch)
tree9abb862956383a122a64c30dead38d70779f7727
parent9afadf56ca5ea97e73135891ef7a772a866ac630 (diff)
downloadgcc-c7cdae718c24e7a3f68d7090cc9947df5d848fb8.zip
gcc-c7cdae718c24e7a3f68d7090cc9947df5d848fb8.tar.gz
gcc-c7cdae718c24e7a3f68d7090cc9947df5d848fb8.tar.bz2
gccrs: [gccrs#2987] Patch ICE when deriving Clone and Copy
gcc/rust/ChangeLog: * expand/rust-expand-visitor.cc: Fix ICE caused by unique_ptr UB and buggy iterator use gcc/testsuite/ChangeLog: * rust/compile/issue-2987.rs: Add test for deriving Clone and Copy at the same time Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
-rw-r--r--gcc/rust/expand/rust-expand-visitor.cc17
-rw-r--r--gcc/testsuite/rust/compile/issue-2987.rs17
2 files changed, 26 insertions, 8 deletions
diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc
index 61147e2..38399d0d 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -167,10 +167,10 @@ ExpandVisitor::expand_inner_items (
for (auto it = items.begin (); it != items.end (); it++)
{
- auto &item = *it;
- if (item->has_outer_attrs ())
+ Rust::AST::Item &item = **it;
+ if (item.has_outer_attrs ())
{
- auto &attrs = item->get_outer_attrs ();
+ auto &attrs = item.get_outer_attrs ();
for (auto attr_it = attrs.begin (); attr_it != attrs.end ();
/* erase => No increment*/)
@@ -190,16 +190,17 @@ ExpandVisitor::expand_inner_items (
if (maybe_builtin.has_value ())
{
auto new_item
- = builtin_derive_item (*item, current,
+ = builtin_derive_item (item, current,
maybe_builtin.value ());
- // this inserts the derive *before* the item - is it a
- // problem?
+
it = items.insert (it, std::move (new_item));
}
else
{
+ // Macro is not a builtin, so it must be a
+ // user-defined derive macro.
auto new_items
- = derive_item (*item, to_derive, expander);
+ = derive_item (item, to_derive, expander);
std::move (new_items.begin (), new_items.end (),
std::inserter (items, it));
}
@@ -215,7 +216,7 @@ ExpandVisitor::expand_inner_items (
{
attr_it = attrs.erase (attr_it);
auto new_items
- = expand_item_attribute (*item, current.get_path (),
+ = expand_item_attribute (item, current.get_path (),
expander);
it = items.erase (it);
std::move (new_items.begin (), new_items.end (),
diff --git a/gcc/testsuite/rust/compile/issue-2987.rs b/gcc/testsuite/rust/compile/issue-2987.rs
new file mode 100644
index 0000000..1ab5fdc
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2987.rs
@@ -0,0 +1,17 @@
+// { dg-options "-w" } Currently there are a lot of warnings produced from inside clone/copy
+// builtins
+
+#[lang = "copy"]
+trait Copy {}
+
+#[lang = "clone"]
+trait Clone {
+ fn clone(&self) -> Self;
+}
+
+#[derive(Copy)]
+#[derive(Clone)]
+struct Empty;
+
+#[derive(Copy,Clone)]
+struct Empty2;