From: Harishankar <[email protected]>
the problem is cfg-strip emits an error for unstrippable expressions but
doesn't mark the parent for strip, leaving a broken subtree for later
passes to ICE on.
gcc/rust/ChangeLog:
* expand/rust-cfg-strip.cc (CfgStrip::visit): mark CallExpr for
strip when function expression fails stripping.
(CfgStrip::visit): mark ArrayIndexExpr for strip when array or
index expression fails stripping.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4167.rs: New test.
Signed-off-by: Harishankar <[email protected]>
---
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/46ab8c2e73e538105d3f09c872a9109506acf3c8
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4526
gcc/rust/expand/rust-cfg-strip.cc | 20 ++++++++++++++------
gcc/testsuite/rust/compile/issue-4167.rs | 15 +++++++++++++++
2 files changed, 29 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-4167.rs
diff --git a/gcc/rust/expand/rust-cfg-strip.cc
b/gcc/rust/expand/rust-cfg-strip.cc
index 2e6971e63..67baebec1 100644
--- a/gcc/rust/expand/rust-cfg-strip.cc
+++ b/gcc/rust/expand/rust-cfg-strip.cc
@@ -828,9 +828,13 @@ CfgStrip::visit (AST::ArrayIndexExpr &expr)
const auto &array_expr = expr.get_array_expr ();
if (array_expr.is_marked_for_strip ())
- rust_error_at (array_expr.get_locus (),
- "cannot strip expression in this position - outer "
- "attributes not allowed");
+ {
+ rust_error_at (array_expr.get_locus (),
+ "cannot strip expression in this position - outer "
+ "attributes not allowed");
+ expr.mark_for_strip ();
+ return;
+ }
const auto &index_expr = expr.get_index_expr ();
if (index_expr.is_marked_for_strip ())
@@ -1044,9 +1048,13 @@ CfgStrip::visit (AST::CallExpr &expr)
auto &function = expr.get_function_expr ();
if (function.is_marked_for_strip ())
- rust_error_at (function.get_locus (),
- "cannot strip expression in this position - outer "
- "attributes not allowed");
+ {
+ rust_error_at (function.get_locus (),
+ "cannot strip expression in this position - outer "
+ "attributes not allowed");
+ expr.mark_for_strip ();
+ return;
+ }
/* spec says outer attributes are specifically allowed for elements
* of call expressions, so full stripping possible */
diff --git a/gcc/testsuite/rust/compile/issue-4167.rs
b/gcc/testsuite/rust/compile/issue-4167.rs
new file mode 100644
index 000000000..47f4e88ea
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4167.rs
@@ -0,0 +1,15 @@
+#![feature(no_core)]
+#![no_core]
+macro_rules! the_macro {
+ ( $foo:stmt ; $bar:stmt ; ) => {
+ #[cfg(foo)]
+ $foo
+
+ $foo[cfg(bar)]
+ $bar
+ };
+}
+
+fn the_function() {
+ the_macro!( (); (); ); // { dg-error "cannot strip expression in this
position" }
+}
base-commit: 679aad3804e8443ec5181fd184785d82aec42bdf
--
2.53.0