Skip to content

Commit 8ecaad8

Browse files
committed
Auto merge of #105919 - uweigand:s390x-stack-overflow, r=Nilstrieb
Fix stack overflow in recursive AST walk in early lint The src/test/ui/issues/issue-74564-if-expr-stack-overflow.rs test case added to verify #74564 still crashes with a stack overflow on s390x-ibm-linux. Symptom is a very deep recursion in compiler/rustc_lint/src/early.rs: fn visit_expr(&mut self, e: &'a ast::Expr) { self.with_lint_attrs(e.id, &e.attrs, |cx| { lint_callback!(cx, check_expr, e); ast_visit::walk_expr(cx, e); }) } (where walk_expr recursively calls back into visit_expr). The crash happens at a nesting depth of over 17000 stack frames when using the default 8 MB stack size on s390x. This patch fixes the problem by adding a ensure_sufficient_stack call to the with_lint_attrs routine (which also should take care of all the other mutually recursive visitors here). Fixes part of #105383.
2 parents ca855e6 + 6bb2bda commit 8ecaad8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

compiler/rustc_lint/src/early.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::passes::{EarlyLintPass, EarlyLintPassObject};
1919
use rustc_ast::ptr::P;
2020
use rustc_ast::visit::{self as ast_visit, Visitor};
2121
use rustc_ast::{self as ast, walk_list, HasAttrs};
22+
use rustc_data_structures::stack::ensure_sufficient_stack;
2223
use rustc_middle::ty::RegisteredTools;
2324
use rustc_session::lint::{BufferedEarlyLint, LintBuffer, LintPass};
2425
use rustc_session::Session;
@@ -71,7 +72,7 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
7172
self.inlined_check_id(id);
7273
debug!("early context: enter_attrs({:?})", attrs);
7374
lint_callback!(self, enter_lint_attrs, attrs);
74-
f(self);
75+
ensure_sufficient_stack(|| f(self));
7576
debug!("early context: exit_attrs({:?})", attrs);
7677
lint_callback!(self, exit_lint_attrs, attrs);
7778
self.context.builder.pop(push);

0 commit comments

Comments
 (0)