diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-04-03 11:03:37 +0200 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-04-05 08:20:48 +0000 |
commit | 865f3b05ad3085e7fe1545fdffb9b5fca3db6412 (patch) | |
tree | 691dc76406ee0a51b7d962abe05c84bb9c1b558c /gcc | |
parent | a7302b77e3915c55ac043401696c84fcdbb96336 (diff) | |
download | gcc-865f3b05ad3085e7fe1545fdffb9b5fca3db6412.zip gcc-865f3b05ad3085e7fe1545fdffb9b5fca3db6412.tar.gz gcc-865f3b05ad3085e7fe1545fdffb9b5fca3db6412.tar.bz2 |
expand: Add builtin attribute identification
Add a function to identify builtin attributes and skip those on proc
macro expansion phase.
gcc/rust/ChangeLog:
* expand/rust-expand-visitor.cc (ExpandVisitor::visit_outer_attrs):
Change condition order.
(ExpandVisitor::visit_inner_using_attrs): Likewise.
(ExpandVisitor::visit_attrs_with_derive): Likewise.
(ExpandVisitor::is_builtin): Add builtin identification
function.
* expand/rust-expand-visitor.h: Add function prototype.
* util/rust-attributes.cc: Add missing rustc_builtin_macro
attribute.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/expand/rust-expand-visitor.cc | 35 | ||||
-rw-r--r-- | gcc/rust/expand/rust-expand-visitor.h | 2 | ||||
-rw-r--r-- | gcc/rust/util/rust-attributes.cc | 1 |
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 6e6f48b..e727fbc 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 |