Skip to content

Commit

Permalink
Factor out check whether an unwind action generates invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiasko committed Mar 6, 2025
1 parent 5c1733e commit 02d7fc1
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions compiler/rustc_mir_transform/src/add_call_guards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
kind: TerminatorKind::Call { target: Some(ref mut destination), unwind, .. },
source_info,
}) if pred_count[*destination] > 1
&& (matches!(
unwind,
UnwindAction::Cleanup(_) | UnwindAction::Terminate(_)
) || self == &AllCallEdges) =>
&& (generates_invoke(unwind) || self == &AllCallEdges) =>
{
// It's a critical edge, break it
*destination = new_block(source_info, block.is_cleanup, *destination);
Expand All @@ -81,9 +78,7 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
});
let has_labels =
operands.iter().any(|op| matches!(op, InlineAsmOperand::Label { .. }));
let invoke =
matches!(unwind, UnwindAction::Cleanup(_) | UnwindAction::Terminate(_));
if has_outputs && (has_labels || invoke) {
if has_outputs && (has_labels || generates_invoke(unwind)) {
for target in targets.iter_mut() {
if pred_count[*target] > 1 {
*target = new_block(source_info, block.is_cleanup, *target);
Expand All @@ -104,3 +99,11 @@ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards {
true
}
}

/// Returns true if this unwind action is code generated as an invoke as opposed to a call.
fn generates_invoke(unwind: UnwindAction) -> bool {
match unwind {
UnwindAction::Continue | UnwindAction::Unreachable => false,
UnwindAction::Cleanup(_) | UnwindAction::Terminate(_) => true,
}
}

0 comments on commit 02d7fc1

Please sign in to comment.