Skip to content

Commit

Permalink
Fix infinite recursion in ctfe align_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Feb 18, 2024
1 parent 99db695 commit 586d704
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 189 deletions.
25 changes: 16 additions & 9 deletions compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,15 +478,22 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
let args2 = ecx.copy_fn_args(args)?;
// For align_offset, we replace the function call if the pointer has no address.
match ecx.align_offset(instance, &args2, destination, target)? {
ControlFlow::Continue(()) => ecx.eval_fn_call(
FnVal::Instance(instance),
abis,
args,
false,
destination,
target,
unwind,
),
ControlFlow::Continue(()) => {
// Can't use `eval_fn_call` here because `eval_fn_call` tries to call
// const eval extra fn which ends up here, so calling `eval_fn_call`
// would cause infinite recursion and stack overflow.
let body = ecx.load_mir(instance.def, None)?;
ecx.eval_body(
instance,
body,
abis,
args,
false,
destination,
target,
unwind,
)
}
ControlFlow::Break(()) => Ok(()),
}
}
Expand Down
Loading

0 comments on commit 586d704

Please sign in to comment.