Skip to content

Commit

Permalink
Mark comptime int hardcoded address pointee as a run time variable #1171
Browse files Browse the repository at this point in the history
 (#1868)

* Mark comptime int hardcoded address as a run time variable #1171

* test case for dereferencing hardcoded address intToPtr
  • Loading branch information
justinbalexander authored and andrewrk committed Jan 4, 2019
1 parent 5c2a105 commit 1f08be4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 14 additions & 0 deletions test/cases/inttoptr.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 1f08be4

Please sign in to comment.