aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatty Kuhn <matty.kuhn.1@gmail.com>2025-04-04 18:09:41 -0600
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2025-04-07 08:27:17 +0000
commit3f2e8aef6f9e70da075261da80fa1400a2341634 (patch)
tree281addc4318a1d4b26b6be78e22779f1a271bbd2
parent1d07cf75d5c558728d95a668a06dd7ecb4f5bb47 (diff)
downloadgcc-3f2e8aef6f9e70da075261da80fa1400a2341634.zip
gcc-3f2e8aef6f9e70da075261da80fa1400a2341634.tar.gz
gcc-3f2e8aef6f9e70da075261da80fa1400a2341634.tar.bz2
gccrs: fix ICE segfault with empty feature gate
This patch fixes an issue where an empty feature gate would segfault, instead of reporting a syntax error to the user. gcc/rust/ChangeLog: * ast/rust-ast.h: (AST::Attribute): add empty_input function * checks/errors/rust-feature-gate.cc: (FeatureGate::visit): check for empty feature gate gcc/testsuite/ChangeLog: * rust/compile/feature.rs: add an invalid empty feature to produce an error Signed-off-by: Matty Kuhn <matty.kuhn.1@gmail.com>
-rw-r--r--gcc/rust/ast/rust-ast.h3
-rw-r--r--gcc/rust/checks/errors/rust-feature-gate.cc7
-rw-r--r--gcc/testsuite/rust/compile/feature.rs2
3 files changed, 12 insertions, 0 deletions
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 53bf1bc..71facff 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -657,6 +657,9 @@ public:
// Returns whether the attribute is considered an "empty" attribute.
bool is_empty () const { return attr_input == nullptr && path.is_empty (); }
+ // Returns whether the attribute has no input
+ bool empty_input () const { return !attr_input; }
+
location_t get_locus () const { return locus; }
AttrInput &get_attr_input () const { return *attr_input; }
diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc
index 5f07d22..708dbb1 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -40,6 +40,13 @@ FeatureGate::visit (AST::Crate &crate)
{
if (attr.get_path ().as_string () == "feature")
{
+ // check for empty feature, such as `#![feature], this is an error
+ if (attr.empty_input ())
+ {
+ rust_error_at (attr.get_locus (), ErrorCode::E0556,
+ "malformed %<feature%> attribute input");
+ continue;
+ }
const auto &attr_input = attr.get_attr_input ();
auto type = attr_input.get_attr_input_type ();
if (type == AST::AttrInput::AttrInputType::TOKEN_TREE)
diff --git a/gcc/testsuite/rust/compile/feature.rs b/gcc/testsuite/rust/compile/feature.rs
index f743f92..6f428f0 100644
--- a/gcc/testsuite/rust/compile/feature.rs
+++ b/gcc/testsuite/rust/compile/feature.rs
@@ -2,5 +2,7 @@
#![feature(AA)] //{ dg-error "unknown feature .AA." }
#![feature(iamcrabby)] // { dg-error "unknown feature .iamcrabby." }
#![feature(nonexistent_gccrs_feature)] // { dg-error "unknown feature .nonexistent_gccrs_feature." }
+// ErrorCode - E0556
+#![feature] // { dg-error "malformed .feature. attribute input" }
fn main() {}