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

commit r17-4359-gf29c99b3ae00c82b8fab444b5314b25e7a648d63
Author: Arthur Cohen <[email protected]>
Date:   Fri Sep 4 14:25:03 2026 +0200

    gccrs: cfi_encoding: Recognize the attribute
    
    And warn that it currently does not do anything, and depends on a patchset 
upstream
    that is currently being reviewed.
    
    gcc/rust/ChangeLog:
    
            * checks/errors/feature/rust-feature-defs-rfl.h: Add cfi_encoding 
RfL feature.
            * checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit): 
Add visitor
            for attributes in general, and warn on cfi_encoding being used.
            * checks/errors/feature/rust-feature-gate.h: Declare the attribute 
visitor.
            * util/rust-attribute-values.h: Add #[cfi_encoding].
            * util/rust-attributes.cc: Likewise.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/cfi-encoding1.rs: New test.
            * rust/compile/cfi-encoding2.rs: New test.

Diff:
---
 gcc/rust/checks/errors/feature/rust-feature-defs-rfl.h |  2 ++
 gcc/rust/checks/errors/feature/rust-feature-gate.cc    | 16 ++++++++++++++++
 gcc/rust/checks/errors/feature/rust-feature-gate.h     |  2 ++
 gcc/rust/util/rust-attribute-values.h                  |  2 ++
 gcc/rust/util/rust-attributes.cc                       |  3 ++-
 gcc/testsuite/rust/compile/cfi-encoding1.rs            |  5 +++++
 gcc/testsuite/rust/compile/cfi-encoding2.rs            |  6 ++++++
 7 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/checks/errors/feature/rust-feature-defs-rfl.h 
b/gcc/rust/checks/errors/feature/rust-feature-defs-rfl.h
index 8d5cc32e57a4..288ffc862929 100644
--- a/gcc/rust/checks/errors/feature/rust-feature-defs-rfl.h
+++ b/gcc/rust/checks/errors/feature/rust-feature-defs-rfl.h
@@ -24,3 +24,5 @@
 
 FEATURE_ACTIVE ("extended_key_value_attributes", EXTENDED_KEY_VALUE_ATTRIBUTES,
                "1.50.0", ISSUE_SOME (78835), EDITION_NONE)
+FEATURE_ACTIVE ("cfi_encoding", CFI_ENCODING, "1.71.0", ISSUE_SOME (89653),
+               EDITION_NONE)
diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.cc 
b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
index 3d43d736ecee..4cb4583f713f 100644
--- a/gcc/rust/checks/errors/feature/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
@@ -366,4 +366,20 @@ FeatureGate::visit (AST::EnumItem &enum_variant)
   AST::DefaultASTVisitor::visit (enum_variant);
 }
 
+void
+FeatureGate::visit (AST::Attribute &attr)
+{
+  if (attr.get_path ().as_string () == "cfi_encoding")
+    if (gate (Feature::Name::CFI_ENCODING, attr.get_locus (),
+             "#[cfi_encoding] is an experimental feature")
+       == GateResult::Allowed)
+      rust_warning_at (
+       attr.get_locus (), 0,
+       "the %<#[cfi_encoding]%> attribute is currently ignored and "
+       "does nothing - we are waiting on a patchset to land "
+       "into GCC as the KCFI functionality is not present yet");
+
+  AST::DefaultASTVisitor::visit (attr);
+}
+
 } // namespace Rust
diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.h 
b/gcc/rust/checks/errors/feature/rust-feature-gate.h
index 74d81a5e1ae0..e74a98605acf 100644
--- a/gcc/rust/checks/errors/feature/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/feature/rust-feature-gate.h
@@ -52,6 +52,8 @@ public:
   void visit (AST::Enum &enum_item) override;
   void visit (AST::EnumItem &enum_variant) override;
 
+  void visit (AST::Attribute &attr) override;
+
   enum class GateResult
   {
     Gated,
diff --git a/gcc/rust/util/rust-attribute-values.h 
b/gcc/rust/util/rust-attribute-values.h
index 99c549ea9211..f4409e1fa06b 100644
--- a/gcc/rust/util/rust-attribute-values.h
+++ b/gcc/rust/util/rust-attribute-values.h
@@ -125,6 +125,8 @@ public:
 
   static constexpr auto &RUSTC_CONVERSION_SUGGESTION
     = "rustc_conversion_suggestion";
+
+  static constexpr auto &CFI_ENCODING = "cfi_encoding";
 };
 } // namespace Values
 } // namespace Rust
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 33be02a43473..58c789fd1592 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -104,7 +104,8 @@ static const BuiltinAttrDefinition __definitions[]
      {Attrs::RUSTC_ALLOCATOR, CODE_GENERATION},
      {Attrs::RUSTC_ALLOCATOR_NOUNWIND, CODE_GENERATION},
      {Attrs::GLOBAL_ALLOCATOR, CODE_GENERATION},
-     {Attrs::RUSTC_CONVERSION_SUGGESTION, TYPE_CHECK}};
+     {Attrs::RUSTC_CONVERSION_SUGGESTION, TYPE_CHECK},
+     {Attrs::CFI_ENCODING, CODE_GENERATION}};
 
 static const std::set<std::string> __outer_attributes
   = {Attrs::INLINE,
diff --git a/gcc/testsuite/rust/compile/cfi-encoding1.rs 
b/gcc/testsuite/rust/compile/cfi-encoding1.rs
new file mode 100644
index 000000000000..643ab565afda
--- /dev/null
+++ b/gcc/testsuite/rust/compile/cfi-encoding1.rs
@@ -0,0 +1,5 @@
+#![feature(no_core)]
+#![no_core]
+
+#[cfi_encoding = "4Bleh"] // { dg-error "experimental feature" }
+pub struct Bleh(i32);
diff --git a/gcc/testsuite/rust/compile/cfi-encoding2.rs 
b/gcc/testsuite/rust/compile/cfi-encoding2.rs
new file mode 100644
index 000000000000..9d56700979af
--- /dev/null
+++ b/gcc/testsuite/rust/compile/cfi-encoding2.rs
@@ -0,0 +1,6 @@
+#![feature(no_core)]
+#![feature(cfi_encoding)]
+#![no_core]
+
+#[cfi_encoding = "4Bleh"] // { dg-warning "does nothing" }
+pub struct Bleh(i32);

Reply via email to