authorgravatar for 39607947+vegecode@users.noreply.github.comvegecode <39607947+vegecode@users.noreply.github.com> 2019-01-04 16:34:21-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-01-04 17:34:21-05:00
log1f08be4d7fdf08bda66312ab4b2e401de378083e
tree0bc6e3afdacd0b75f1870b5b953dd7a9722cf9c2
parent5c2a1055a03d4ef9e4d292afe8b934cb6a7afa11

Mark comptime int hardcoded address pointee as a run time variable #1171 (#1868)

* Mark comptime int hardcoded address as a run time variable #1171 * test case for dereferencing hardcoded address intToPtr

2 files changed, 15 insertions(+), 0 deletions(-)

src/ir.cpp+1
......@@ -20363,6 +20363,7 @@ static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstru
2036320363
2036420364 IrInstruction *result = ir_const(ira, &instruction->base, dest_type);
2036520365 result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
20366 result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar;
2036620367 result->value.data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&val->data.x_bigint);
2036720368 return result;
2036820369 }
test/cases/inttoptr.zig+14
......@@ -11,3 +11,17 @@ fn randomAddressToFunction() void {
1111 var addr: usize = 0xdeadbeef;
1212 var ptr = @intToPtr(fn () void, addr);
1313}
14
15test "mutate through ptr initialized with constant intToPtr value" {
16 forceCompilerAnalyzeBranchHardCodedPtrDereference(false);
17}
18
19fn forceCompilerAnalyzeBranchHardCodedPtrDereference(x: bool) void {
20 const hardCodedP = @intToPtr(*volatile u8, 0xdeadbeef);
21 if (x) {
22 hardCodedP.* = hardCodedP.* | 10;
23 } else {
24 return;
25 }
26}
27