diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-04-03 11:03:37 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:28:45 +0100 |
commit | 895373dea127efb837163564f77c44bbf47538b9 (patch) | |
tree | d3cad666f77c0991e50730d6c96f264f90f4cbe4 /gcc | |
parent | 4210e02e82289dbf6203418e86fed68153844361 (diff) | |
download | gcc-895373dea127efb837163564f77c44bbf47538b9.zip gcc-895373dea127efb837163564f77c44bbf47538b9.tar.gz gcc-895373dea127efb837163564f77c44bbf47538b9.tar.bz2 |
gccrs: 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 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 |