public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] hir: more conformant builtin macro detection ...
@ 2022-08-06 12:09 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-08-06 12:09 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:df1a20119080c3b09fcf75d6374b69126db3f623

commit df1a20119080c3b09fcf75d6374b69126db3f623
Author: liushuyu <liushuyu011@gmail.com>
Date:   Tue Aug 2 17:06:40 2022 -0600

    hir: more conformant builtin macro detection ...
    
    ... a macro is now considered builtin macro only if it has
    rustc_builtin_macro attribute. This also allows overriding macro
    definition with the same name as the builtin ones.
    
    Signed-off-by: Zixing Liu <liushuyu011@gmail.com>

Diff:
---
 gcc/rust/util/rust-hir-map.cc | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 6a6deebf944..8705fdcf381 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -18,6 +18,7 @@
 
 #include "rust-hir-map.h"
 #include "rust-ast-full.h"
+#include "rust-diagnostics.h"
 #include "rust-hir-full.h"
 #include "rust-macro-builtins.h"
 #include "rust-mapping-common.h"
@@ -818,9 +819,22 @@ Mappings::insert_macro_def (AST::MacroRulesDefinition *macro)
       {"include", MacroBuiltin::include},
     };
 
-  auto builtin = builtin_macros.find (macro->get_rule_name ());
-  if (builtin != builtin_macros.end ())
-    macro->set_builtin_transcriber (builtin->second);
+  auto outer_attrs = macro->get_outer_attrs ();
+  bool should_be_builtin
+    = std::any_of (outer_attrs.begin (), outer_attrs.end (),
+		   [] (AST::Attribute attr) {
+		     return attr.get_path () == "rustc_builtin_macro";
+		   });
+  if (should_be_builtin)
+    {
+      auto builtin = builtin_macros.find (macro->get_rule_name ());
+      if (builtin != builtin_macros.end ())
+	macro->set_builtin_transcriber (builtin->second);
+      else
+	rust_error_at (macro->get_locus (),
+		       "cannot find a built-in macro with name %qs",
+		       macro->get_rule_name ().c_str ());
+    }
 
   auto it = macroMappings.find (macro->get_node_id ());
   rust_assert (it == macroMappings.end ());


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-06 12:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-06 12:09 [gcc/devel/rust/master] hir: more conformant builtin macro detection Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).