authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-19 22:29:39-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-19 22:29:39-04:00
log78eeb6e9aea9c280513faaa83f9df959b7ac6f59
tree5ffb6fa07d22ff74ae5be52553d15bf843c5dc53
parent04c25efe112e374facaf1bc8b58bbdb6999a39e3
signaturelock-open Commit is signed but in an unrecognized format.

fix double getelementptr of runtime global


3 files changed, 76 insertions(+), 125 deletions(-)

src/codegen.cpp+3
......@@ -3832,6 +3832,9 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
38323832static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executable,
38333833 IrInstructionStructFieldPtr *instruction)
38343834{
3835 if (instruction->base.value.special != ConstValSpecialRuntime)
3836 return nullptr;
3837
38353838 LLVMValueRef struct_ptr = ir_llvm_value(g, instruction->struct_ptr);
38363839 // not necessarily a pointer. could be ZigTypeIdStruct
38373840 ZigType *struct_ptr_type = instruction->struct_ptr->value.type;
src/ir.cpp+67-119
......@@ -187,9 +187,9 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
187187static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
188188 ZigType *dest_type);
189189static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
190 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value);
190 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool non_null_comptime);
191191static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,
192 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime);
192 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime);
193193static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr,
194194 IrInstruction *base_ptr, bool safety_check_on, bool initializing);
195195static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr,
......@@ -10844,7 +10844,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
1084410844 }
1084510845
1084610846 if (result_loc == nullptr) result_loc = no_result_loc();
10847 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true);
10847 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false);
1084810848 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1084910849 return result_loc_inst;
1085010850 }
......@@ -11282,7 +11282,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
1128211282 }
1128311283 IrInstruction *result_loc_inst = nullptr;
1128411284 if (result_loc != nullptr) {
11285 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true);
11285 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false);
1128611286 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1128711287 return result_loc_inst;
1128811288 }
......@@ -11325,7 +11325,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
1132511325 IrInstruction *result_loc_inst;
1132611326 if (handle_is_ptr(wanted_type)) {
1132711327 if (result_loc == nullptr) result_loc = no_result_loc();
11328 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true);
11328 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false);
1132911329 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1133011330 return result_loc_inst;
1133111331 }
......@@ -11410,7 +11410,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
1141011410 IrInstruction *result_loc_inst;
1141111411 if (handle_is_ptr(wanted_type)) {
1141211412 if (result_loc == nullptr) result_loc = no_result_loc();
11413 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true);
11413 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false);
1141411414 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1141511415 return result_loc_inst;
1141611416 }
......@@ -11483,7 +11483,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
1148311483
1148411484 IrInstruction *result_loc;
1148511485 if (type_has_bits(ptr_type) && !handle_is_ptr(value->value.type)) {
11486 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value.type, nullptr, true);
11486 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value.type, nullptr, true, false);
1148711487 } else {
1148811488 result_loc = nullptr;
1148911489 }
......@@ -11527,7 +11527,7 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s
1152711527 if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false);
1152811528
1152911529 if (result_loc == nullptr) result_loc = no_result_loc();
11530 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true);
11530 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false);
1153111531 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1153211532 return result_loc_inst;
1153311533 }
......@@ -12180,7 +12180,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *
1218012180 result->value.type = array_type;
1218112181 return result;
1218212182 }
12183 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, true);
12183 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, true, false);
1218412184 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1218512185 return result_loc_inst;
1218612186 }
......@@ -12761,7 +12761,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1276112761 IrInstruction *result_loc_inst;
1276212762 if (type_entry->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) {
1276312763 if (result_loc == nullptr) result_loc = no_result_loc();
12764 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true);
12764 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true, false);
1276512765 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1276612766 return result_loc_inst;
1276712767 }
......@@ -14910,7 +14910,7 @@ static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) {
1491014910
1491114911// when calling this function, at the callsite must check for result type noreturn and propagate it up
1491214912static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
14913 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value)
14913 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool non_null_comptime)
1491414914{
1491514915 Error err;
1491614916 if (result_loc->resolved_loc != nullptr) {
......@@ -14984,9 +14984,11 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1498414984 return result_loc->resolved_loc;
1498514985 }
1498614986 case ResultLocIdReturn: {
14987 bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime;
14988 if (is_comptime)
14989 return nullptr;
14987 if (!non_null_comptime) {
14988 bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime;
14989 if (is_comptime)
14990 return nullptr;
14991 }
1499014992 if (!type_has_bits(ira->explicit_return_type) || !handle_is_ptr(ira->explicit_return_type))
1499114993 return nullptr;
1499214994
......@@ -15005,6 +15007,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1500515007 return ira->codegen->invalid_instruction;
1500615008 peer_parent->skipped = is_comptime;
1500715009 if (peer_parent->skipped) {
15010 if (non_null_comptime) {
15011 return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
15012 value_type, value, false, non_null_comptime);
15013 }
1500815014 return nullptr;
1500915015 }
1501015016
......@@ -15016,7 +15022,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1501615022 }
1501715023
1501815024 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
15019 peer_parent->resolved_type, nullptr, false);
15025 peer_parent->resolved_type, nullptr, false, non_null_comptime);
1502015026 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||
1502115027 parent_result_loc->value.type->id == ZigTypeIdUnreachable)
1502215028 {
......@@ -15066,7 +15072,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1506615072 }
1506715073
1506815074 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,
15069 dest_type, bitcasted_value, false);
15075 dest_type, bitcasted_value, false, non_null_comptime);
1507015076 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||
1507115077 parent_result_loc->value.type->id == ZigTypeIdUnreachable)
1507215078 {
......@@ -15094,10 +15100,11 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1509415100}
1509515101
1509615102static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,
15097 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value, bool force_runtime)
15103 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value, bool force_runtime,
15104 bool non_null_comptime)
1509815105{
1509915106 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
15100 value);
15107 value, non_null_comptime);
1510115108 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value.type)))
1510215109 return result_loc;
1510315110
......@@ -15144,23 +15151,16 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrIn
1514415151 ZigType *implicit_elem_type = ir_resolve_type(ira, instruction->ty->child);
1514515152 if (type_is_invalid(implicit_elem_type))
1514615153 return ira->codegen->invalid_instruction;
15147 ResultLoc *old_result_loc = instruction->result_loc;
15148 for (;;) {
15149 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, old_result_loc,
15150 implicit_elem_type, nullptr, false);
15151 if (result_loc != nullptr)
15152 return result_loc;
15154 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
15155 implicit_elem_type, nullptr, false, true);
15156 if (result_loc != nullptr)
15157 return result_loc;
1515315158
15154 if (instruction->result_loc->id == ResultLocIdPeer) {
15155 old_result_loc = reinterpret_cast<ResultLocPeer *>(instruction->result_loc)->parent->parent;
15156 continue;
15157 }
15158 IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type);
15159 result->value.special = ConstValSpecialUndef;
15160 IrInstruction *ptr = ir_get_ref(ira, &instruction->base, result, false, false);
15161 ptr->value.data.x_ptr.mut = ConstPtrMutComptimeVar;
15162 return ptr;
15163 }
15159 IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type);
15160 result->value.special = ConstValSpecialUndef;
15161 IrInstruction *ptr = ir_get_ref(ira, &instruction->base, result, false, false);
15162 ptr->value.data.x_ptr.mut = ConstPtrMutComptimeVar;
15163 return ptr;
1516415164}
1516515165
1516615166static void ir_reset_result(ResultLoc *result_loc) {
......@@ -15500,7 +15500,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1550015500 // * "string literal used as comptime slice is memoized"
1550115501 // * "comptime modification of const struct field" - except modified to avoid
1550215502 // ConstPtrMutComptimeVar, thus defeating the logic below.
15503 bool same_global_refs = ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst;
15503 bool same_global_refs = ptr->value.data.x_ptr.mut != ConstPtrMutComptimeVar;
1550415504 copy_const_val(dest_val, &value->value, same_global_refs);
1550515505 if (!ira->new_irb.current_basic_block->must_be_comptime_source_instr) {
1550615506 ira->new_irb.current_basic_block->must_be_comptime_source_instr = source_instr;
......@@ -15986,7 +15986,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1598615986 IrInstruction *result_loc;
1598715987 if (handle_is_ptr(impl_fn_type_id->return_type)) {
1598815988 result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc,
15989 impl_fn_type_id->return_type, nullptr, true);
15989 impl_fn_type_id->return_type, nullptr, true, false);
1599015990 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
1599115991 return result_loc;
1599215992 }
......@@ -16106,7 +16106,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1610616106 IrInstruction *result_loc;
1610716107 if (handle_is_ptr(return_type)) {
1610816108 result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc,
16109 return_type, nullptr, true);
16109 return_type, nullptr, true, false);
1611016110 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
1611116111 return result_loc;
1611216112 }
......@@ -16198,7 +16198,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
1619816198
1619916199 if (dst_size <= src_size) {
1620016200 if (src_size == dst_size && types_have_same_zig_comptime_repr(pointee->type, out_val->type)) {
16201 copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
16201 copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut != ConstPtrMutComptimeVar);
1620216202 return ErrorNone;
1620316203 }
1620416204 Buf buf = BUF_INIT;
......@@ -16600,7 +16600,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1660016600
1660116601 // In case resolving the parent activates a suspend, do it now
1660216602 IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent,
16603 peer_parent->resolved_type, nullptr, false);
16603 peer_parent->resolved_type, nullptr, false, false);
1660416604 if (parent_result_loc != nullptr &&
1660516605 (type_is_invalid(parent_result_loc->value.type) || instr_is_unreachable(parent_result_loc)))
1660616606 {
......@@ -17246,11 +17246,10 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
1724617246 field_val->special = ConstValSpecialUndef;
1724717247 field_val->type = struct_type->data.structure.fields[i].type_entry;
1724817248 ConstParent *parent = get_const_val_parent(ira->codegen, field_val);
17249 if (parent != nullptr) {
17250 parent->id = ConstParentIdStruct;
17251 parent->data.p_struct.struct_val = struct_val;
17252 parent->data.p_struct.field_index = i;
17253 }
17249 assert(parent != nullptr);
17250 parent->id = ConstParentIdStruct;
17251 parent->data.p_struct.struct_val = struct_val;
17252 parent->data.p_struct.field_index = i;
1725417253 }
1725517254 }
1725617255 IrInstruction *result;
......@@ -17264,7 +17263,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
1726417263 }
1726517264 ConstExprValue *const_val = &result->value;
1726617265 const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct;
17267 const_val->data.x_ptr.mut = struct_ptr->value.data.x_ptr.mut;
17266 const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
1726817267 const_val->data.x_ptr.data.base_struct.struct_val = struct_val;
1726917268 const_val->data.x_ptr.data.base_struct.field_index = field->src_index;
1727017269 return result;
......@@ -17414,6 +17413,11 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
1741417413 link_lib->symbols.append(symbol_name);
1741517414}
1741617415
17416static IrInstruction *ir_error_dependency_loop(IrAnalyze *ira, IrInstruction *source_instr) {
17417 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected"));
17418 emit_error_notes_for_ref_stack(ira->codegen, msg);
17419 return ira->codegen->invalid_instruction;
17420}
1741717421
1741817422static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) {
1741917423 resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node);
......@@ -17428,6 +17432,9 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_
1742817432 {
1742917433 TldVar *tld_var = (TldVar *)tld;
1743017434 ZigVar *var = tld_var->var;
17435 if (var == nullptr) {
17436 return ir_error_dependency_loop(ira, source_instruction);
17437 }
1743117438 if (tld_var->extern_lib_name != nullptr) {
1743217439 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node);
1743317440 }
......@@ -17443,23 +17450,13 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_
1744317450 if (type_is_invalid(fn_entry->type_entry))
1744417451 return ira->codegen->invalid_instruction;
1744517452
17446 // TODO instead of allocating this every time, put it in the tld value and we can reference
17447 // the same one every time
17448 ConstExprValue *const_val = create_const_vals(1);
17449 const_val->special = ConstValSpecialStatic;
17450 const_val->type = fn_entry->type_entry;
17451 const_val->data.x_ptr.data.fn.fn_entry = fn_entry;
17452 const_val->data.x_ptr.special = ConstPtrSpecialFunction;
17453 const_val->data.x_ptr.mut = ConstPtrMutComptimeConst;
17454
1745517453 if (tld_fn->extern_lib_name != nullptr) {
1745617454 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node);
1745717455 }
1745817456
17459 bool ptr_is_const = true;
17460 bool ptr_is_volatile = false;
17461 return ir_get_const_ptr(ira, source_instruction, const_val, fn_entry->type_entry,
17462 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
17457 IrInstruction *fn_inst = ir_create_const_fn(&ira->new_irb, source_instruction->scope,
17458 source_instruction->source_node, fn_entry);
17459 return ir_get_ref(ira, source_instruction, fn_inst, true, false);
1746317460 }
1746417461 }
1746517462 zig_unreachable();
......@@ -19673,12 +19670,6 @@ static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira,
1967319670 return ir_const_unsigned(ira, &instruction->base, bit_offset);
1967419671}
1967519672
19676static IrInstruction *ir_error_dependency_loop(IrAnalyze *ira, IrInstruction *source_instr) {
19677 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected"));
19678 emit_error_notes_for_ref_stack(ira->codegen, msg);
19679 return ira->codegen->invalid_instruction;
19680}
19681
1968219673static void ensure_field_index(ZigType *type, const char *field_name, size_t index) {
1968319674 Buf *field_name_buf;
1968419675
......@@ -21088,7 +21079,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
2108821079 IrInstruction *result_loc;
2108921080 if (handle_is_ptr(result_type)) {
2109021081 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
21091 result_type, nullptr, true);
21082 result_type, nullptr, true, false);
2109221083 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
2109321084 return result_loc;
2109421085 }
......@@ -21345,7 +21336,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2134521336 }
2134621337
2134721338 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
21348 dest_slice_type, nullptr, true);
21339 dest_slice_type, nullptr, true, false);
2134921340 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
2135021341 return result_loc;
2135121342 }
......@@ -21422,7 +21413,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
2142221413 }
2142321414
2142421415 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
21425 dest_slice_type, nullptr, true);
21416 dest_slice_type, nullptr, true, false);
2142621417 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
2142721418 return result_loc;
2142821419 }
......@@ -22164,7 +22155,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2216422155 }
2216522156
2216622157 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
22167 return_type, nullptr, true);
22158 return_type, nullptr, true, false);
2216822159 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
2216922160 return result_loc;
2217022161 }
......@@ -23729,58 +23720,15 @@ static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstru
2372923720static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
2373023721 IrInstructionDeclRef *instruction)
2373123722{
23732 Tld *tld = instruction->tld;
23733 LVal lval = instruction->lval;
23734
23735 resolve_top_level_decl(ira->codegen, tld, instruction->base.source_node);
23736 if (tld->resolution == TldResolutionInvalid)
23723 IrInstruction *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base, instruction->tld);
23724 if (type_is_invalid(ref_instruction->value.type))
2373723725 return ira->codegen->invalid_instruction;
2373823726
23739 switch (tld->id) {
23740 case TldIdContainer:
23741 case TldIdCompTime:
23742 zig_unreachable();
23743 case TldIdVar: {
23744 TldVar *tld_var = (TldVar *)tld;
23745 ZigVar *var = tld_var->var;
23746
23747 if (var == nullptr) {
23748 return ir_error_dependency_loop(ira, &instruction->base);
23749 }
23750
23751 IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var);
23752 if (type_is_invalid(var_ptr->value.type))
23753 return ira->codegen->invalid_instruction;
23754
23755 if (tld_var->extern_lib_name != nullptr) {
23756 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, instruction->base.source_node);
23757 }
23758
23759 if (lval == LValPtr) {
23760 return var_ptr;
23761 } else {
23762 return ir_get_deref(ira, &instruction->base, var_ptr, nullptr);
23763 }
23764 }
23765 case TldIdFn: {
23766 TldFn *tld_fn = (TldFn *)tld;
23767 ZigFn *fn_entry = tld_fn->fn_entry;
23768 ir_assert(fn_entry->type_entry, &instruction->base);
23769
23770 if (tld_fn->extern_lib_name != nullptr) {
23771 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, instruction->base.source_node);
23772 }
23773
23774 IrInstruction *ref_instruction = ir_create_const_fn(&ira->new_irb, instruction->base.scope,
23775 instruction->base.source_node, fn_entry);
23776 if (lval == LValPtr) {
23777 return ir_get_ref(ira, &instruction->base, ref_instruction, true, false);
23778 } else {
23779 return ref_instruction;
23780 }
23781 }
23727 if (instruction->lval == LValPtr) {
23728 return ref_instruction;
23729 } else {
23730 return ir_get_deref(ira, &instruction->base, ref_instruction, nullptr);
2378223731 }
23783 zig_unreachable();
2378423732}
2378523733
2378623734static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) {
......@@ -24655,7 +24603,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
2465524603
2465624604 bool was_written = instruction->result_loc->written;
2465724605 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
24658 value->value.type, value, false);
24606 value->value.type, value, false, false);
2465924607 if (result_loc != nullptr) {
2466024608 if (type_is_invalid(result_loc->value.type))
2466124609 return ira->codegen->invalid_instruction;
......@@ -24684,7 +24632,7 @@ static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInst
2468424632 return operand;
2468524633
2468624634 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,
24687 &instruction->result_loc_bit_cast->base, operand->value.type, operand, false);
24635 &instruction->result_loc_bit_cast->base, operand->value.type, operand, false, false);
2468824636 if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)))
2468924637 return result_loc;
2469024638
test/stage1/behavior/struct.zig+6-6
......@@ -522,12 +522,12 @@ const S0 = struct {
522522 }
523523};
524524
525//var g_foo: S0 = S0.init();
526//
527//test "access to global struct fields" {
528// g_foo.bar.value = 42;
529// expect(g_foo.bar.value == 42);
530//}
525var g_foo: S0 = S0.init();
526
527test "access to global struct fields" {
528 g_foo.bar.value = 42;
529 expect(g_foo.bar.value == 42);
530}
531531
532532//test "packed struct with fp fields" {
533533// const S = packed struct {