Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_codegen_llvm/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
}
attributes::apply_to_callsite(result, llvm::AttributePlace::Function, &{ attrs });

// Switch to the 'normal' basic block if we did an `invoke` instead of a `call`
if let Some((dest, _, _)) = dest_catch_funclet {
self.switch_to_block(dest);
}

// Write results to outputs
for (idx, op) in operands.iter().enumerate() {
if let InlineAsmOperandRef::Out { reg, place: Some(place), .. }
Expand Down
17 changes: 15 additions & 2 deletions src/test/codegen/asm-may_unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@ impl Drop for Foo {
}
}

// CHECK-LABEL: @may_unwind
// CHECK-LABEL: @asm_may_unwind
#[no_mangle]
pub unsafe fn may_unwind() {
pub unsafe fn asm_may_unwind() {
let _m = Foo;
// CHECK: invoke void asm sideeffect alignstack inteldialect unwind ""
asm!("", options(may_unwind));
}

// CHECK-LABEL: @asm_with_result_may_unwind
#[no_mangle]
pub unsafe fn asm_with_result_may_unwind() -> u64 {
let _m = Foo;
let res: u64;
// CHECK: [[RES:%[0-9]+]] = invoke i64 asm sideeffect alignstack inteldialect unwind
// CHECK-NEXT: to label %[[NORMALBB:[a-b0-9]+]]
asm!("mov {}, 1", out(reg) res, options(may_unwind));
// CHECK: [[NORMALBB]]:
// CHECK: ret i64 [[RES:%[0-9]+]]
res
}