From 1f08be4d7fdf08bda66312ab4b2e401de378083e Mon Sep 17 00:00:00 2001 From: vegecode <39607947+vegecode@users.noreply.github.com> Date: Fri, 4 Jan 2019 16:34:21 -0600 Subject: [PATCH] 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 --- src/ir.cpp | 1 + test/cases/inttoptr.zig | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/ir.cpp b/src/ir.cpp index dac5403550..400b07368b 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -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; } diff --git a/test/cases/inttoptr.zig b/test/cases/inttoptr.zig index 6695352383..ba3cc52f09 100644 --- a/test/cases/inttoptr.zig +++ b/test/cases/inttoptr.zig @@ -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; + } +} +