authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-12-20 09:44:10+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-20 15:47:43-05:00
logf077c3c4ccd03f48f785ee812ab2c88c85792014
treec7b83ad5642f4064c200a9feade04bfb3134e3ad
parent9daa7e1e193a693b4415d3db8031633236f28876

Fix comptime evaluation of runtime array access

Fix #3951

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

src/ir.cpp+1
...@@ -19500,6 +19500,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19500,6 +19500,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19500 }19500 }
1950119501
19502 if (orig_array_ptr_val->special != ConstValSpecialRuntime &&19502 if (orig_array_ptr_val->special != ConstValSpecialRuntime &&
19503 orig_array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
19503 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||19504 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||
19504 array_type->id == ZigTypeIdArray))19505 array_type->id == ZigTypeIdArray))
19505 {19506 {
test/stage1/behavior/pointers.zig+6
...@@ -282,3 +282,9 @@ test "pointer sentinel with +inf" {...@@ -282,3 +282,9 @@ test "pointer sentinel with +inf" {
282 S.doTheTest();282 S.doTheTest();
283 comptime S.doTheTest();283 comptime S.doTheTest();
284}284}
285
286test "pointer to array at fixed address" {
287 const array = @intToPtr(*volatile [1]u32, 0x10);
288 // Silly check just to reference `array`
289 expect(@ptrToInt(&array[0]) == 0x10);
290}