aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/expand/rust-expand-visitor.cc35
-rw-r--r--gcc/rust/expand/rust-expand-visitor.h2
-rw-r--r--gcc/rust/util/rust-attributes.cc1
3 files changed, 33 insertions, 5 deletions
diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc
index c25c017..dac1948 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -17,6 +17,7 @@
// <http://www.gnu.org/licenses/>.
#include "rust-expand-visitor.h"
+#include "rust-attributes.h"
namespace Rust {
@@ -1400,8 +1401,15 @@ ExpandVisitor::visit_outer_attrs (T &item, std::vector<AST::Attribute> &attrs)
{
auto current = *it;
- it = attrs.erase (it);
- expand_outer_attribute (item, current.get_path ());
+ if (!is_builtin (current) && !is_derive (current))
+ {
+ it = attrs.erase (it);
+ expand_outer_attribute (item, current.get_path ());
+ }
+ else
+ {
+ it++;
+ }
}
}
@@ -1429,8 +1437,15 @@ ExpandVisitor::visit_inner_using_attrs (T &item,
{
auto current = *it;
- it = attrs.erase (it);
- expand_inner_attribute (item, current.get_path ());
+ if (!is_builtin (current) && !is_derive (current))
+ {
+ it = attrs.erase (it);
+ expand_inner_attribute (item, current.get_path ());
+ }
+ else
+ {
+ it++;
+ }
}
}
@@ -1476,7 +1491,7 @@ ExpandVisitor::visit_attrs_with_derive (T &item)
{
auto current = *it;
- if (is_derive (current))
+ if (!is_builtin (current) && is_derive (current))
{
it = attrs.erase (it);
// Downcasting checked in is_derive
@@ -1500,4 +1515,14 @@ ExpandVisitor::is_derive (AST::Attribute &attr)
&& !segments.empty () && "derive" == segments[0].get_segment_name ();
}
+bool
+ExpandVisitor::is_builtin (AST::Attribute &attr)
+{
+ auto &segments = attr.get_path ().get_segments ();
+ return !segments.empty ()
+ && !Analysis::BuiltinAttributeMappings::get ()
+ ->lookup_builtin (segments[0].get_segment_name ())
+ .is_error ();
+}
+
} // namespace Rust
diff --git a/gcc/rust/expand/rust-expand-visitor.h b/gcc/rust/expand/rust-expand-visitor.h
index e0ff37c..c2b3e78 100644
--- a/gcc/rust/expand/rust-expand-visitor.h
+++ b/gcc/rust/expand/rust-expand-visitor.h
@@ -339,6 +339,8 @@ public:
template <typename T> void visit_attrs_with_derive (T &item);
+ bool is_builtin (AST::Attribute &attr);
+
private:
MacroExpander &expander;
};
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 941d445..372762d 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -39,6 +39,7 @@ static const BuiltinAttrDefinition __definitions[]
{"link_section", CODE_GENERATION},
{"no_mangle", CODE_GENERATION},
{"repr", CODE_GENERATION},
+ {"rustc_builtin_macro", EXPANSION},
{"path", EXPANSION},
{"macro_use", NAME_RESOLUTION},
// FIXME: This is not implemented yet, see