Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}