[gccrs COMMIT 2/2] cfi_encoding: Recognize the attribute
gerris.rs@gmail.com
gerris.rs@gmail.com
Mon Sep 14 13:11:47 GMT 2026
From: Arthur Cohen <arthur.cohen@opensrcsec.com>
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.
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github: https://github.com/Rust-GCC/gccrs/commit/a107b3c08762eda82ad6f1ffdf595ff4b01c3152
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4846
.../errors/feature/rust-feature-defs-rfl.h | 2 ++
.../checks/errors/feature/rust-feature-gate.cc | 16 ++++++++++++++++
.../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(-)
create mode 100644 gcc/testsuite/rust/compile/cfi-encoding1.rs
create mode 100644 gcc/testsuite/rust/compile/cfi-encoding2.rs
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 8d5cc32e5..288ffc862 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 3d43d736e..4cb4583f7 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 74d81a5e1..e74a98605 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 99c549ea9..f4409e1fa 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 33be02a43..58c789fd1 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 000000000..643ab565a
--- /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 000000000..9d5670097
--- /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);
--
2.55.0
More information about the Gcc-rust
mailing list