]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add `#[track_caller]` as known attribute
authorbeamandala <mandalapubhavesh@gmail.com>
Thu, 20 Mar 2025 22:34:48 +0000 (17:34 -0500)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 14 Apr 2025 16:23:55 +0000 (18:23 +0200)
gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc (MacroBuiltin::builtin_transcribers):
Add entry for track_caller.
* util/rust-attribute-values.h: add `TRACK_CALLER` attribute.
* util/rust-attributes.cc: add `track_caller` attribute definition.

gcc/testsuite/ChangeLog:

* rust/compile/track_caller.rs: New test.

Signed-off-by: Bhavesh Mandalapu <mandalapubhavesh@gmail.com>
gcc/rust/expand/rust-macro-builtins.cc
gcc/rust/util/rust-attribute-values.h
gcc/rust/util/rust-attributes.cc
gcc/testsuite/rust/compile/track_caller.rs [new file with mode: 0644]

index 39c4c46b8e0d8caa79710bf18fd12181f6bae106..a1388fb1dfb3066e4ce05e10fee0b7524d7af75f 100644 (file)
@@ -137,6 +137,7 @@ std::unordered_map<std::string, AST::MacroTranscriberFunc>
     {"cfg_accessible", MacroBuiltin::sorry},
     {"rustc_const_stable", MacroBuiltin::sorry},
     {"rustc_const_unstable", MacroBuiltin::sorry},
+    {"track_caller", MacroBuiltin::sorry},
     /* Derive builtins do not need a real transcriber, but still need one. It
        should however never be called since builtin derive macros get expanded
        differently, and benefit from knowing on what kind of items they are
index 9ef5cc52e81ae0f6f5495f198e1ebebdad9fda31..d579fa298013b82a6e8031b142037fcefc70f9eb 100644 (file)
@@ -58,6 +58,7 @@ public:
   static constexpr auto &RUSTC_CONST_UNSTABLE = "rustc_const_unstable";
   static constexpr auto &MAY_DANGLE = "may_dangle";
   static constexpr auto &PRELUDE_IMPORT = "prelude_import";
+  static constexpr auto &TRACK_CALLER = "track_caller";
 };
 } // namespace Values
 } // namespace Rust
index 03452c75bd8a4b9b777717a9c050a2f81c47b2f4..df0fe1b0bcaceee24a05cae081cde935b467ca2e 100644 (file)
@@ -75,7 +75,8 @@ static const BuiltinAttrDefinition __definitions[]
      // assuming we keep these for static analysis
      {Attrs::RUSTC_CONST_STABLE, STATIC_ANALYSIS},
      {Attrs::RUSTC_CONST_UNSTABLE, STATIC_ANALYSIS},
-     {Attrs::PRELUDE_IMPORT, NAME_RESOLUTION}};
+     {Attrs::PRELUDE_IMPORT, NAME_RESOLUTION},
+     {Attrs::TRACK_CALLER, CODE_GENERATION}};
 
 BuiltinAttributeMappings *
 BuiltinAttributeMappings::get ()
diff --git a/gcc/testsuite/rust/compile/track_caller.rs b/gcc/testsuite/rust/compile/track_caller.rs
new file mode 100644 (file)
index 0000000..fd1d842
--- /dev/null
@@ -0,0 +1,6 @@
+#[track_caller]
+fn foo() {}
+
+fn main() {
+    foo();
+}