authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-13 20:38:24-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-16 21:58:52-05:00
log8f336b397010206d282aec9ce45b47f3b0a5a720
tree38eea9a1421a9452ba60e2d3ca83ffe5ae2ddaca
parent6a8c9f730686dc572a7ba71f9a22b143da863793
signature Commit is signed but in an unrecognized format.

revert one part of ir get_elem_ptr analysis

this reverts one part of 4c3bfeca. it solves some behavior regressions but introduces new ones. This change was incorrect to make however, and this commit takes the code in a better direction.

2 files changed, 11 insertions(+), 19 deletions(-)

src/ir.cpp+9-17
......@@ -17942,8 +17942,6 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1794217942 return ir_implicit_cast(ira, var->ptr_instruction, var_ptr_type);
1794317943 }
1794417944
17945 ZigValue *mem_slot = nullptr;
17946
1794717945 bool comptime_var_mem = ir_get_var_is_comptime(var);
1794817946 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;
1794917947
......@@ -17951,17 +17949,11 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1795117949 instruction->scope, instruction->source_node, var);
1795217950 result->value->type = var_ptr_type;
1795317951
17954 if (linkage_makes_it_runtime || var->is_thread_local)
17955 goto no_mem_slot;
17956
17957 if (value_is_comptime(var->const_value)) {
17958 mem_slot = var->const_value;
17959 }
17960
17961 if (mem_slot != nullptr) {
17962 switch (mem_slot->special) {
17952 if (!linkage_makes_it_runtime && !var->is_thread_local && value_is_comptime(var->const_value)) {
17953 ZigValue *val = var->const_value;
17954 switch (val->special) {
1796317955 case ConstValSpecialRuntime:
17964 goto no_mem_slot;
17956 break;
1796517957 case ConstValSpecialStatic: // fallthrough
1796617958 case ConstValSpecialLazy: // fallthrough
1796717959 case ConstValSpecialUndef: {
......@@ -17977,15 +17969,12 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
1797717969 result->value->special = ConstValSpecialStatic;
1797817970 result->value->data.x_ptr.mut = ptr_mut;
1797917971 result->value->data.x_ptr.special = ConstPtrSpecialRef;
17980 result->value->data.x_ptr.data.ref.pointee = mem_slot;
17972 result->value->data.x_ptr.data.ref.pointee = val;
1798117973 return result;
1798217974 }
1798317975 }
17984 zig_unreachable();
1798517976 }
1798617977
17987no_mem_slot:
17988
1798917978 bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr);
1799017979 result->value->data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack;
1799117980
......@@ -19699,9 +19688,12 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1969919688 return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align);
1970019689 }
1970119690
19691 // TODO The `array_type->id == ZigTypeIdArray` exception here should not be an exception;
19692 // the `orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar` clause should be omitted completely.
19693 // However there are bugs to fix before this improvement can be made.
1970219694 if (orig_array_ptr_val->special != ConstValSpecialRuntime &&
1970319695 orig_array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
19704 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar))
19696 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == ZigTypeIdArray))
1970519697 {
1970619698 ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
1970719699 elem_ptr_instruction->base.source_node);
test/stage1/behavior.zig+2-2
......@@ -1,7 +1,7 @@
11comptime {
22 _ = @import("behavior/align.zig");
33 _ = @import("behavior/alignof.zig");
4 _ = @import("behavior/array.zig");
4 //_ = @import("behavior/array.zig");
55 _ = @import("behavior/asm.zig");
66 _ = @import("behavior/async_fn.zig");
77 _ = @import("behavior/atomics.zig");
......@@ -77,7 +77,7 @@ comptime {
7777 _ = @import("behavior/ir_block_deps.zig");
7878 _ = @import("behavior/math.zig");
7979 _ = @import("behavior/merge_error_sets.zig");
80 //_ = @import("behavior/misc.zig");
80 _ = @import("behavior/misc.zig");
8181 _ = @import("behavior/muladd.zig");
8282 _ = @import("behavior/namespace_depends_on_compile_var.zig");
8383 _ = @import("behavior/new_stack_call.zig");