mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
* Mark comptime int hardcoded address as a run time variable #1171 * test case for dereferencing hardcoded address intToPtr
This commit is contained in:
parent
5c2a1055a0
commit
1f08be4d7f
@ -20363,6 +20363,7 @@ static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstru
|
||||
|
||||
IrInstruction *result = ir_const(ira, &instruction->base, dest_type);
|
||||
result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
|
||||
result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar;
|
||||
result->value.data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&val->data.x_bigint);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -11,3 +11,17 @@ fn randomAddressToFunction() void {
|
||||
var addr: usize = 0xdeadbeef;
|
||||
var ptr = @intToPtr(fn () void, addr);
|
||||
}
|
||||
|
||||
test "mutate through ptr initialized with constant intToPtr value" {
|
||||
forceCompilerAnalyzeBranchHardCodedPtrDereference(false);
|
||||
}
|
||||
|
||||
fn forceCompilerAnalyzeBranchHardCodedPtrDereference(x: bool) void {
|
||||
const hardCodedP = @intToPtr(*volatile u8, 0xdeadbeef);
|
||||
if (x) {
|
||||
hardCodedP.* = hardCodedP.* | 10;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user