Skip to content

Commit 586d704

Browse files
committed
Fix infinite recursion in ctfe align_offset
1 parent 99db695 commit 586d704

File tree

2 files changed

+216
-189
lines changed

2 files changed

+216
-189
lines changed

compiler/rustc_const_eval/src/const_eval/machine.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -478,15 +478,22 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
478478
let args2 = ecx.copy_fn_args(args)?;
479479
// For align_offset, we replace the function call if the pointer has no address.
480480
match ecx.align_offset(instance, &args2, destination, target)? {
481-
ControlFlow::Continue(()) => ecx.eval_fn_call(
482-
FnVal::Instance(instance),
483-
abis,
484-
args,
485-
false,
486-
destination,
487-
target,
488-
unwind,
489-
),
481+
ControlFlow::Continue(()) => {
482+
// Can't use `eval_fn_call` here because `eval_fn_call` tries to call
483+
// const eval extra fn which ends up here, so calling `eval_fn_call`
484+
// would cause infinite recursion and stack overflow.
485+
let body = ecx.load_mir(instance.def, None)?;
486+
ecx.eval_body(
487+
instance,
488+
body,
489+
abis,
490+
args,
491+
false,
492+
destination,
493+
target,
494+
unwind,
495+
)
496+
}
490497
ControlFlow::Break(()) => Ok(()),
491498
}
492499
}

0 commit comments

Comments
 (0)