Skip to content

Commit c7c10b1

Browse files
committed
Be explicit about pointer casts
Removes compiler warning added to nightly recently. People often accidentally cast function pointers to integers when they meant to call the function and cast the result, but they forgot the (). So because we actually want to cast a function pointer we have to be clear about that.
1 parent a3c4619 commit c7c10b1

12 files changed

+20
-20
lines changed

examples/mps3-an536/src/bin/abt-exception-a32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ unsafe fn data_abort_handler(addr: usize) -> usize {
8888
enable_alignment_check();
8989

9090
// note the fault isn't at the start of the function
91-
let expect_fault_at = unaligned_from_a32 as usize + 8;
91+
let expect_fault_at = unaligned_from_a32 as unsafe extern "C" fn() as usize + 8;
9292

9393
if addr == expect_fault_at {
9494
println!("caught unaligned_from_a32");

examples/mps3-an536/src/bin/abt-exception-t32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ unsafe fn data_abort_handler(addr: usize) -> usize {
8888
enable_alignment_check();
8989

9090
// note the fault isn't at the start of the function
91-
let expect_fault_at = unaligned_from_t32 as usize + 5;
91+
let expect_fault_at = unaligned_from_t32 as unsafe extern "C" fn() as usize + 5;
9292

9393
if addr == expect_fault_at {
9494
println!("caught unaligned_from_t32");

examples/mps3-an536/src/bin/prefetch-exception-a32.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ unsafe fn prefetch_abort_handler(addr: usize) -> usize {
6363
let ifar = Ifar::read();
6464
println!("IFAR (Faulting Address Register): {:?}", ifar);
6565

66-
if addr == bkpt_from_a32 as usize {
66+
if addr == bkpt_from_a32 as unsafe extern "C" fn() as usize {
6767
println!("caught bkpt_from_a32");
6868
} else {
6969
println!(
7070
"Bad fault address {:08x} is not {:08x}",
71-
addr, bkpt_from_a32 as usize
71+
addr, bkpt_from_a32 as unsafe extern "C" fn() as usize
7272
);
7373
}
7474

examples/mps3-an536/src/bin/prefetch-exception-t32.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ unsafe fn prefetch_abort_handler(addr: usize) -> usize {
6363
let ifar = Ifar::read();
6464
println!("IFAR (Faulting Address Register): {:?}", ifar);
6565

66-
if (addr + 1) == bkpt_from_t32 as usize {
66+
if (addr + 1) == bkpt_from_t32 as unsafe extern "C" fn() as usize {
6767
// note that thumb functions have their LSB set, despite always being a
6868
// multiple of two - that's how the CPU knows they are written in T32
6969
// machine code.
7070
println!("caught bkpt_from_t32");
7171
} else {
7272
println!(
7373
"Bad fault address {:08x} is not {:08x}",
74-
addr, bkpt_from_t32 as usize
74+
addr, bkpt_from_t32 as unsafe extern "C" fn() as usize
7575
);
7676
}
7777

examples/mps3-an536/src/bin/undef-exception-a32.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ fn prefetch_abort_handler(_addr: usize) -> ! {
5555
unsafe fn undefined_handler(addr: usize) -> usize {
5656
println!("undefined abort occurred");
5757

58-
if addr == udf_from_a32 as usize {
58+
if addr == udf_from_a32 as unsafe extern "C" fn() as usize {
5959
println!("caught udf_from_a32");
6060
} else {
6161
println!(
6262
"Bad fault address {:08x} is not {:08x}",
63-
addr, udf_from_a32 as usize
63+
addr, udf_from_a32 as unsafe extern "C" fn() as usize
6464
);
6565
}
6666

examples/mps3-an536/src/bin/undef-exception-t32.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ fn prefetch_abort_handler(_addr: usize) -> ! {
5555
unsafe fn undefined_handler(addr: usize) -> usize {
5656
println!("undefined abort occurred");
5757

58-
if (addr + 1) == udf_from_t32 as usize {
58+
if (addr + 1) == udf_from_t32 as unsafe extern "C" fn() as usize {
5959
// note that thumb functions have their LSB set, despite always being a
6060
// multiple of two - that's how the CPU knows they are written in T32
6161
// machine code.
6262
println!("caught udf_from_t32");
6363
} else {
6464
println!(
6565
"Bad fault address {:08x} is not {:08x}",
66-
addr, udf_from_t32 as usize
66+
addr, udf_from_t32 as unsafe extern "C" fn() as usize
6767
);
6868
}
6969

examples/versatileab/src/bin/abt-exception-a32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ unsafe fn data_abort_handler(addr: usize) -> usize {
8888
enable_alignment_check();
8989

9090
// note the fault isn't at the start of the function
91-
let expect_fault_at = unaligned_from_a32 as usize + 8;
91+
let expect_fault_at = unaligned_from_a32 as unsafe extern "C" fn() as usize + 8;
9292

9393
if addr == expect_fault_at {
9494
println!("caught unaligned_from_a32");

examples/versatileab/src/bin/abt-exception-t32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ unsafe fn data_abort_handler(addr: usize) -> usize {
8888
enable_alignment_check();
8989

9090
// note the fault isn't at the start of the function
91-
let expect_fault_at = unaligned_from_t32 as usize + 3;
91+
let expect_fault_at = unaligned_from_t32 as unsafe extern "C" fn() as usize + 3;
9292

9393
if addr == expect_fault_at {
9494
println!("caught unaligned_from_t32");

examples/versatileab/src/bin/prefetch-exception-a32.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ unsafe fn prefetch_abort_handler(addr: usize) -> usize {
6868
let ifar = Ifar::read();
6969
println!("IFAR (Faulting Address Register): {:?}", ifar);
7070

71-
if addr == bkpt_from_a32 as usize {
71+
if addr == bkpt_from_a32 as unsafe extern "C" fn() as usize {
7272
println!("caught bkpt_from_a32");
7373
} else {
7474
println!(
7575
"Bad fault address {:08x} is not {:08x}",
76-
addr, bkpt_from_a32 as usize
76+
addr, bkpt_from_a32 as unsafe extern "C" fn() as usize
7777
);
7878
}
7979
}

examples/versatileab/src/bin/prefetch-exception-t32.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ unsafe fn prefetch_abort_handler(addr: usize) -> usize {
6868
let ifar = Ifar::read();
6969
println!("IFAR (Faulting Address Register): {:?}", ifar);
7070

71-
if (addr + 1) == bkpt_from_t32 as usize {
71+
if (addr + 1) == bkpt_from_t32 as unsafe extern "C" fn() as usize {
7272
// note that thumb functions have their LSB set, despite always being a
7373
// multiple of two - that's how the CPU knows they are written in T32
7474
// machine code.
7575
println!("caught bkpt_from_t32");
7676
} else {
7777
println!(
7878
"Bad fault address {:08x} is not {:08x}",
79-
addr, bkpt_from_t32 as usize
79+
addr, bkpt_from_t32 as unsafe extern "C" fn() as usize
8080
);
8181
}
8282
}

0 commit comments

Comments
 (0)