mirror of
https://github.com/ziglang/zig.git
synced 2024-11-30 09:02:32 +00:00
a06e9eca45
* airSlice * airArrayToSlice * and initial support for airSlicePtr and co
31 lines
903 B
Zig
31 lines
903 B
Zig
const builtin = @import("builtin");
|
|
|
|
test "casting integer address to function pointer" {
|
|
if (builtin.zig_backend == .stage1) return error.SkipZigTest;
|
|
|
|
addressToFunction();
|
|
comptime addressToFunction();
|
|
}
|
|
|
|
fn addressToFunction() void {
|
|
var addr: usize = 0xdeadbee0;
|
|
_ = @intToPtr(*const fn () void, addr);
|
|
}
|
|
|
|
test "mutate through ptr initialized with constant intToPtr value" {
|
|
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
|
|
|
forceCompilerAnalyzeBranchHardCodedPtrDereference(false);
|
|
}
|
|
|
|
fn forceCompilerAnalyzeBranchHardCodedPtrDereference(x: bool) void {
|
|
const hardCodedP = @intToPtr(*volatile u8, 0xdeadbeef);
|
|
if (x) {
|
|
hardCodedP.* = hardCodedP.* | 10;
|
|
} else {
|
|
return;
|
|
}
|
|
}
|