From f077c3c4ccd03f48f785ee812ab2c88c85792014 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Fri, 20 Dec 2019 09:44:10 +0100 Subject: [PATCH] Fix comptime evaluation of runtime array access Fix #3951 --- src/ir.cpp | 1 + test/stage1/behavior/pointers.zig | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/ir.cpp b/src/ir.cpp index bc16cef561..0c7160fa80 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -19500,6 +19500,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct } if (orig_array_ptr_val->special != ConstValSpecialRuntime && + orig_array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr && (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == ZigTypeIdArray)) { diff --git a/test/stage1/behavior/pointers.zig b/test/stage1/behavior/pointers.zig index 1dd07c8986..e1004243fc 100644 --- a/test/stage1/behavior/pointers.zig +++ b/test/stage1/behavior/pointers.zig @@ -282,3 +282,9 @@ test "pointer sentinel with +inf" { S.doTheTest(); comptime S.doTheTest(); } + +test "pointer to array at fixed address" { + const array = @intToPtr(*volatile [1]u32, 0x10); + // Silly check just to reference `array` + expect(@ptrToInt(&array[0]) == 0x10); +}