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
signaturelock-open 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,...@@ -17942,8 +17942,6 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
17942 return ir_implicit_cast(ira, var->ptr_instruction, var_ptr_type);17942 return ir_implicit_cast(ira, var->ptr_instruction, var_ptr_type);
17943 }17943 }
1794417944
17945 ZigValue *mem_slot = nullptr;
17946
17947 bool comptime_var_mem = ir_get_var_is_comptime(var);17945 bool comptime_var_mem = ir_get_var_is_comptime(var);
17948 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;17946 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,...@@ -17951,17 +17949,11 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
17951 instruction->scope, instruction->source_node, var);17949 instruction->scope, instruction->source_node, var);
17952 result->value->type = var_ptr_type;17950 result->value->type = var_ptr_type;
1795317951
17954 if (linkage_makes_it_runtime || var->is_thread_local)17952 if (!linkage_makes_it_runtime && !var->is_thread_local && value_is_comptime(var->const_value)) {
17955 goto no_mem_slot;17953 ZigValue *val = var->const_value;
1795617954 switch (val->special) {
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) {
17963 case ConstValSpecialRuntime:17955 case ConstValSpecialRuntime:
17964 goto no_mem_slot;17956 break;
17965 case ConstValSpecialStatic: // fallthrough17957 case ConstValSpecialStatic: // fallthrough
17966 case ConstValSpecialLazy: // fallthrough17958 case ConstValSpecialLazy: // fallthrough
17967 case ConstValSpecialUndef: {17959 case ConstValSpecialUndef: {
...@@ -17977,15 +17969,12 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -17977,15 +17969,12 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
17977 result->value->special = ConstValSpecialStatic;17969 result->value->special = ConstValSpecialStatic;
17978 result->value->data.x_ptr.mut = ptr_mut;17970 result->value->data.x_ptr.mut = ptr_mut;
17979 result->value->data.x_ptr.special = ConstPtrSpecialRef;17971 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;
17981 return result;17973 return result;
17982 }17974 }
17983 }17975 }
17984 zig_unreachable();
17985 }17976 }
1798617977
17987no_mem_slot:
17988
17989 bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr);17978 bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr);
17990 result->value->data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack;17979 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...@@ -19699,9 +19688,12 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19699 return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align);19688 return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align);
19700 }19689 }
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.
19702 if (orig_array_ptr_val->special != ConstValSpecialRuntime &&19694 if (orig_array_ptr_val->special != ConstValSpecialRuntime &&
19703 orig_array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&19695 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))
19705 {19697 {
19706 ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,19698 ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
19707 elem_ptr_instruction->base.source_node);19699 elem_ptr_instruction->base.source_node);
test/stage1/behavior.zig+2-2
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1comptime {1comptime {
2 _ = @import("behavior/align.zig");2 _ = @import("behavior/align.zig");
3 _ = @import("behavior/alignof.zig");3 _ = @import("behavior/alignof.zig");
4 _ = @import("behavior/array.zig");4 //_ = @import("behavior/array.zig");
5 _ = @import("behavior/asm.zig");5 _ = @import("behavior/asm.zig");
6 _ = @import("behavior/async_fn.zig");6 _ = @import("behavior/async_fn.zig");
7 _ = @import("behavior/atomics.zig");7 _ = @import("behavior/atomics.zig");
...@@ -77,7 +77,7 @@ comptime {...@@ -77,7 +77,7 @@ comptime {
77 _ = @import("behavior/ir_block_deps.zig");77 _ = @import("behavior/ir_block_deps.zig");
78 _ = @import("behavior/math.zig");78 _ = @import("behavior/math.zig");
79 _ = @import("behavior/merge_error_sets.zig");79 _ = @import("behavior/merge_error_sets.zig");
80 //_ = @import("behavior/misc.zig");80 _ = @import("behavior/misc.zig");
81 _ = @import("behavior/muladd.zig");81 _ = @import("behavior/muladd.zig");
82 _ = @import("behavior/namespace_depends_on_compile_var.zig");82 _ = @import("behavior/namespace_depends_on_compile_var.zig");
83 _ = @import("behavior/new_stack_call.zig");83 _ = @import("behavior/new_stack_call.zig");