-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
201 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// compile-flags: -O | ||
// only-x86_64 | ||
|
||
#![crate_type = "rlib"] | ||
#![feature(asm_goto)] | ||
|
||
use std::arch::asm; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn panicky() {} | ||
|
||
struct Foo; | ||
|
||
impl Drop for Foo { | ||
fn drop(&mut self) { | ||
println!(); | ||
} | ||
} | ||
|
||
// CHECK-LABEL: @asm_goto | ||
#[no_mangle] | ||
pub unsafe fn asm_goto() { | ||
// CHECK: callbr void asm sideeffect alignstack inteldialect " | ||
// CHECK-NEXT: to label %[[FALLTHROUGHBB:[a-b0-9]+]] [label %[[JUMPBB:[a-b0-9]+]]] | ||
asm!("jmp {}", label {}); | ||
} | ||
|
||
// CHECK-LABEL: @asm_goto_with_outputs | ||
#[no_mangle] | ||
pub unsafe fn asm_goto_with_outputs() -> u64 { | ||
let out: u64; | ||
// CHECK: [[RES:%[0-9]+]] = callbr i64 asm sideeffect alignstack inteldialect " | ||
// CHECK-NEXT: to label %[[FALLTHROUGHBB:[a-b0-9]+]] [label %[[JUMPBB:[a-b0-9]+]]] | ||
asm!("{} /* {} */", out(reg) out, label { return 1; }); | ||
// CHECK: [[JUMPBB]]: | ||
// CHECK-NEXT: [[RET:%.+]] = phi i64 [ [[RES]], %[[FALLTHROUGHBB]] ], [ 1, %start ] | ||
// CHECK-NEXT: ret i64 [[RET]] | ||
out | ||
} | ||
|
||
// CHECK-LABEL: @asm_goto_noreturn | ||
#[no_mangle] | ||
pub unsafe fn asm_goto_noreturn() -> u64 { | ||
let out: u64; | ||
// CHECK: callbr void asm sideeffect alignstack inteldialect " | ||
// CHECK-NEXT: to label %unreachable [label %[[JUMPBB:[a-b0-9]+]]] | ||
asm!("jmp {}", label { return 1; }, options(noreturn)); | ||
// CHECK: [[JUMPBB]]: | ||
// CHECK-NEXT: ret i64 1 | ||
out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// only-x86_64 | ||
// run-pass | ||
// needs-asm-support | ||
// revisions: mirunsafeck thirunsafeck | ||
// [thirunsafeck]compile-flags: -Z thir-unsafeck | ||
|
||
#![deny(unreachable_code)] | ||
#![feature(asm_goto)] | ||
|
||
use std::arch::asm; | ||
|
||
fn goto_fallthough() { | ||
unsafe { | ||
asm!( | ||
"/* {} */", | ||
label { | ||
unreachable!(); | ||
} | ||
) | ||
} | ||
} | ||
|
||
fn goto_jump() { | ||
unsafe { | ||
let mut value = false; | ||
asm!( | ||
"jmp {}", | ||
label { | ||
value = true; | ||
} | ||
); | ||
assert!(value); | ||
} | ||
} | ||
|
||
// asm goto with outputs cause miscompilation in LLVM. UB can be triggered | ||
// when outputs are used inside the label block when optimisation is enabled. | ||
// See: https://github.com/llvm/llvm-project/issues/74483 | ||
/* | ||
fn goto_out_fallthrough() { | ||
unsafe { | ||
let mut out: usize; | ||
asm!( | ||
"lea {}, [{} + 1]", | ||
"/* {} */", | ||
out(reg) out, | ||
in(reg) 0x12345678usize, | ||
label { | ||
unreachable!(); | ||
} | ||
); | ||
assert_eq!(out, 0x12345679); | ||
} | ||
} | ||
fn goto_out_jump() { | ||
unsafe { | ||
let mut value = false; | ||
let mut out: usize; | ||
asm!( | ||
"lea {}, [{} + 1]", | ||
"jmp {}", | ||
out(reg) out, | ||
in(reg) 0x12345678usize, | ||
label { | ||
value = true; | ||
assert_eq!(out, 0x12345679); | ||
} | ||
); | ||
assert!(value); | ||
} | ||
} | ||
*/ | ||
|
||
fn goto_noreturn() { | ||
unsafe { | ||
'a: { | ||
asm!( | ||
"jmp {}", | ||
label { | ||
break 'a; | ||
}, | ||
options(noreturn) | ||
); | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
goto_fallthough(); | ||
goto_jump(); | ||
// goto_out_fallthrough(); | ||
// goto_out_jump(); | ||
goto_noreturn(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// only-x86_64 | ||
|
||
use std::arch::asm; | ||
|
||
fn main() { | ||
unsafe { | ||
asm!("jmp {}", label {}); | ||
//~^ ERROR label operands for inline assembly are unstable | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0658]: label operands for inline assembly are unstable | ||
--> $DIR/feature-gate-asm_goto.rs:7:24 | ||
| | ||
LL | asm!("jmp {}", label {}); | ||
| ^^^^^^^^ | ||
| | ||
= help: add `#![feature(asm_goto)]` to the crate attributes to enable | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |