From: jayant chauhan <[email protected]>
The check_deprecated_attribute function previously assumed that the
attribute always contained an input (arguments). However, #[deprecated]
is valid without arguments. Accessing the input on a bare #[deprecated]
attribute resulted in a null pointer dereference and a segmentation fault.
This patch adds a guard clause to check if the attribute has input
before attempting to access it, preventing the crash.
Fixes Rust-GCC#4410
gcc/rust/ChangeLog:
* util/rust-attributes.cc (check_deprecated_attribute): Guard against
attributes without input.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4410.rs: New test.
Signed-off-by: Jayant Chauhan <[email protected]>
---
gcc/rust/util/rust-attributes.cc | 3 +++
gcc/testsuite/rust/compile/issue-4410.rs | 11 +++++++++++
2 files changed, 14 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/issue-4410.rs
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index e4429d8a550..8da23c5d1b2 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -298,6 +298,9 @@ check_doc_attribute (const AST::Attribute &attribute)
static void
check_deprecated_attribute (const AST::Attribute &attribute)
{
+ if (!attribute.has_attr_input ())
+ return;
+
const auto &input = attribute.get_attr_input ();
if (input.get_attr_input_type () != AST::AttrInput::META_ITEM)
diff --git a/gcc/testsuite/rust/compile/issue-4410.rs
b/gcc/testsuite/rust/compile/issue-4410.rs
new file mode 100644
index 00000000000..9ece6ba41ce
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4410.rs
@@ -0,0 +1,11 @@
+// { dg-options "-frust-incomplete-and-experimental-compiler-do-not-use -w" }
+#![feature(no_core)]
+#![no_core]
+
+// The bug was that a bare #[deprecated] (with no arguments) caused a Segfault.
+// This test ensures it compiles without crashing.
+
+#[deprecated]
+pub mod a {}
+
+fn main() {}
\ No newline at end of file
--
2.50.1