| author | |
| committer | |
| log | 1f08be4d7fdf08bda66312ab4b2e401de378083e |
| tree | 0bc6e3afdacd0b75f1870b5b953dd7a9722cf9c2 |
| parent | 5c2a1055a03d4ef9e4d292afe8b934cb6a7afa11 |
* 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 | ... | @@ -20363,6 +20363,7 @@ static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstru |
| 20363 | 20363 | ||
| 20364 | IrInstruction *result = ir_const(ira, &instruction->base, dest_type); | 20364 | IrInstruction *result = ir_const(ira, &instruction->base, dest_type); |
| 20365 | result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr; | 20365 | result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 20366 | result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar; | ||
| 20366 | result->value.data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&val->data.x_bigint); | 20367 | result->value.data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&val->data.x_bigint); |
| 20367 | return result; | 20368 | return result; |
| 20368 | } | 20369 | } |
test/cases/inttoptr.zig+14| ... | @@ -11,3 +11,17 @@ fn randomAddressToFunction() void { | ... | @@ -11,3 +11,17 @@ fn randomAddressToFunction() void { |
| 11 | var addr: usize = 0xdeadbeef; | 11 | var addr: usize = 0xdeadbeef; |
| 12 | var ptr = @intToPtr(fn () void, addr); | 12 | var ptr = @intToPtr(fn () void, addr); |
| 13 | } | 13 | } |
| 14 | |||
| 15 | test "mutate through ptr initialized with constant intToPtr value" { | ||
| 16 | forceCompilerAnalyzeBranchHardCodedPtrDereference(false); | ||
| 17 | } | ||
| 18 | |||
| 19 | fn 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 |