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 <0001jayant@gmail.com>
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)
--- /dev/null
+// { 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