]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: util/attributes: Fix ICE on bare #[deprecated] attribute
authorjayant chauhan <0001jayant@gmail.com>
Sun, 1 Feb 2026 11:09:30 +0000 (16:39 +0530)
committerArthur Cohen <arthur.cohen@embecosm.com>
Fri, 27 Feb 2026 14:57:10 +0000 (15:57 +0100)
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>
gcc/rust/util/rust-attributes.cc
gcc/testsuite/rust/compile/issue-4410.rs [new file with mode: 0644]

index e4429d8a5505e40e813f07e67374cc4d637fcd5b..8da23c5d1b299423e733340c48282466d15b6e69 100644 (file)
@@ -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 (file)
index 0000000..9ece6ba
--- /dev/null
@@ -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