Skip to content

Commit

Permalink
Rollup merge of rust-lang#108997 - tgross35:patch-1, r=JohnTitor
Browse files Browse the repository at this point in the history
Change text -> rust highlighting in sanitizer.md

Not sure why this has syntax highlighting turned off, but it doesn't need to be

Relevant page: https://doc.rust-lang.org/beta/unstable-book/compiler-flags/sanitizer.html
  • Loading branch information
matthiaskrgr committed Mar 16, 2023
2 parents 11a80a0 + 738ea1b commit e505cdc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/doc/unstable-book/src/compiler-flags/sanitizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ See the [Clang ControlFlowIntegrity documentation][clang-cfi] for more details.
## Example
```text
```rust
#![feature(naked_functions)]
use std::arch::asm;
Expand All @@ -223,6 +223,8 @@ fn add_one(x: i32) -> i32 {
x + 1
}
# // Only define this function if the assembly works
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[naked]
pub extern "C" fn add_two(x: i32) {
// x + 2 preceded by a landing pad/nop block
Expand All @@ -238,7 +240,7 @@ pub extern "C" fn add_two(x: i32) {
nop
nop
nop
lea rax, [rdi+2]
lea eax, [edi+2]
ret
",
options(noreturn)
Expand All @@ -250,6 +252,10 @@ fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
f(arg) + f(arg)
}
# // Can only call add_two on x86/64
# #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
# fn main() { println!("this test does not work on this target") }
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn main() {
let answer = do_twice(add_one, 5);
Expand Down

0 comments on commit e505cdc

Please sign in to comment.