authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-26 13:04:58-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-26 13:04:58-04:00
log6a3fad1d596a59846d072a005f77f6c59da09824
tree6e67a5ac7d615580ac2c5114c2326cc23336574f
parent0839ed1f945dbbe3ad1f780a5334ad16ad12fd5e

Revert "src/ir.cpp: check return value of `const_ptr_pointee` to protect against dereferencing null pointers;"

This reverts commit 0839ed1f945dbbe3ad1f780a5334ad16ad12fd5e. I realized too late there is a better fix. See PR #1419

1 files changed, 1 insertions(+), 21 deletions(-)

src/ir.cpp+1-21
......@@ -10982,7 +10982,6 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1098210982 ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar)
1098310983 {
1098410984 ConstExprValue *pointee = const_ptr_pointee(ira->codegen, &ptr->value);
10985 if (!pointee) return ira->codegen->invalid_instruction;
1098610985 if (pointee->special != ConstValSpecialRuntime) {
1098710986 IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope,
1098810987 source_instruction->source_node, child_type);
......@@ -13656,7 +13655,6 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
1365613655 return ira->codegen->builtin_types.entry_invalid;
1365713656
1365813657 ConstExprValue *pointee = const_ptr_pointee(ira->codegen, comptime_value);
13659 if (!pointee) return ira->codegen->builtin_types.entry_invalid;
1366013658 if (pointee->type == child_type) {
1366113659 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
1366213660 copy_const_val(out_val, pointee, value->value.data.x_ptr.mut == ConstPtrMutComptimeConst);
......@@ -14060,7 +14058,6 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1406014058 ptr_type = ptr_type->data.pointer.child_type;
1406114059 if (orig_array_ptr_val->special != ConstValSpecialRuntime) {
1406214060 orig_array_ptr_val = const_ptr_pointee(ira->codegen, orig_array_ptr_val);
14063 if (!orig_array_ptr_val) return ira->codegen->builtin_types.entry_invalid;
1406414061 }
1406514062 }
1406614063 if (array_type->data.array.len == 0) {
......@@ -14102,7 +14099,6 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1410214099 if (!ptr_val)
1410314100 return ira->codegen->builtin_types.entry_invalid;
1410414101 ConstExprValue *args_val = const_ptr_pointee(ira->codegen, ptr_val);
14105 if (!args_val) return ira->codegen->builtin_types.entry_invalid;
1410614102 size_t start = args_val->data.x_arg_tuple.start_index;
1410714103 size_t end = args_val->data.x_arg_tuple.end_index;
1410814104 uint64_t elem_index_val;
......@@ -14384,7 +14380,6 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1438414380
1438514381 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
1438614382 ConstExprValue *struct_val = const_ptr_pointee(ira->codegen, ptr_val);
14387 if (!struct_val) return ira->codegen->invalid_instruction;
1438814383 if (type_is_invalid(struct_val->type))
1438914384 return ira->codegen->invalid_instruction;
1439014385 ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index];
......@@ -14427,7 +14422,6 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1442714422
1442814423 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
1442914424 ConstExprValue *union_val = const_ptr_pointee(ira->codegen, ptr_val);
14430 if (!union_val) return ira->codegen->invalid_instruction;
1443114425 if (type_is_invalid(union_val->type))
1443214426 return ira->codegen->invalid_instruction;
1443314427
......@@ -14624,7 +14618,6 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1462414618
1462514619 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
1462614620 ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);
14627 if (!child_val) return ira->codegen->builtin_types.entry_invalid;
1462814621
1462914622 if (buf_eql_str(field_name, "len")) {
1463014623 ConstExprValue *len_val = create_const_vals(1);
......@@ -14649,7 +14642,6 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1464914642
1465014643 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
1465114644 ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);
14652 if (!child_val) return ira->codegen->builtin_types.entry_invalid;
1465314645 TypeTableEntry *child_type = child_val->data.x_type;
1465414646
1465514647 if (type_is_invalid(child_type)) {
......@@ -14918,7 +14910,6 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1491814910 return ira->codegen->builtin_types.entry_invalid;
1491914911
1492014912 ConstExprValue *namespace_val = const_ptr_pointee(ira->codegen, container_ptr_val);
14921 if (!namespace_val) return ira->codegen->builtin_types.entry_invalid;
1492214913 assert(namespace_val->special == ConstValSpecialStatic);
1492314914
1492414915 ImportTableEntry *namespace_import = namespace_val->data.x_import;
......@@ -14995,7 +14986,6 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
1499514986 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) {
1499614987 if (instr_is_comptime(casted_value)) {
1499714988 ConstExprValue *dest_val = const_ptr_pointee(ira->codegen, &ptr->value);
14998 if (!dest_val) return ira->codegen->builtin_types.entry_invalid;
1499914989 if (dest_val->special != ConstValSpecialRuntime) {
1500014990 *dest_val = casted_value->value;
1500114991 if (!ira->new_irb.current_basic_block->must_be_comptime_source_instr) {
......@@ -15007,7 +14997,6 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
1500714997 ir_add_error(ira, &store_ptr_instruction->base,
1500814998 buf_sprintf("cannot store runtime value in compile time variable"));
1500914999 ConstExprValue *dest_val = const_ptr_pointee(ira->codegen, &ptr->value);
15010 if (!dest_val) return ira->codegen->builtin_types.entry_invalid;
1501115000 dest_val->type = ira->codegen->builtin_types.entry_invalid;
1501215001
1501315002 return ira->codegen->builtin_types.entry_invalid;
......@@ -15861,7 +15850,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1586115850 ConstExprValue *pointee_val = nullptr;
1586215851 if (instr_is_comptime(target_value_ptr)) {
1586315852 pointee_val = const_ptr_pointee(ira->codegen, &target_value_ptr->value);
15864 if (pointee_val && pointee_val->special == ConstValSpecialRuntime)
15853 if (pointee_val->special == ConstValSpecialRuntime)
1586515854 pointee_val = nullptr;
1586615855 }
1586715856 if ((err = ensure_complete_type(ira->codegen, target_type)))
......@@ -15992,7 +15981,6 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr
1599215981 return ira->codegen->builtin_types.entry_invalid;
1599315982
1599415983 ConstExprValue *pointee_val = const_ptr_pointee(ira->codegen, target_val_ptr);
15995 if (!pointee_val) return ira->codegen->builtin_types.entry_invalid;
1599615984 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1599715985 out_val->data.x_ptr.special = ConstPtrSpecialRef;
1599815986 out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut;
......@@ -18744,14 +18732,11 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1874418732 TypeTableEntry *child_array_type = array_type->data.pointer.child_type;
1874518733 assert(child_array_type->id == TypeTableEntryIdArray);
1874618734 parent_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value);
18747 if (!parent_ptr) return ira->codegen->builtin_types.entry_invalid;
1874818735 array_val = const_ptr_pointee(ira->codegen, parent_ptr);
18749 if (!array_val) return ira->codegen->builtin_types.entry_invalid;
1875018736 rel_end = child_array_type->data.array.len;
1875118737 abs_offset = 0;
1875218738 } else {
1875318739 array_val = const_ptr_pointee(ira->codegen, &ptr_ptr->value);
18754 if (!array_val) return ira->codegen->builtin_types.entry_invalid;
1875518740 rel_end = array_type->data.array.len;
1875618741 parent_ptr = nullptr;
1875718742 abs_offset = 0;
......@@ -18759,7 +18744,6 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1875918744 } else if (array_type->id == TypeTableEntryIdPointer) {
1876018745 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
1876118746 parent_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value);
18762 if (!parent_ptr) return ira->codegen->builtin_types.entry_invalid;
1876318747 if (parent_ptr->special == ConstValSpecialUndef) {
1876418748 array_val = nullptr;
1876518749 abs_offset = 0;
......@@ -18791,7 +18775,6 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1879118775 }
1879218776 } else if (is_slice(array_type)) {
1879318777 ConstExprValue *slice_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value);
18794 if (!slice_ptr) return ira->codegen->builtin_types.entry_invalid;
1879518778 parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index];
1879618779 ConstExprValue *len_val = &slice_ptr->data.x_struct.fields[slice_len_index];
1879718780
......@@ -19192,7 +19175,6 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
1919219175 BigInt *op1_bigint = &casted_op1->value.data.x_bigint;
1919319176 BigInt *op2_bigint = &casted_op2->value.data.x_bigint;
1919419177 ConstExprValue *pointee_val = const_ptr_pointee(ira->codegen, &casted_result_ptr->value);
19195 if (!pointee_val) return ira->codegen->builtin_types.entry_invalid;
1919619178 BigInt *dest_bigint = &pointee_val->data.x_bigint;
1919719179 switch (instruction->op) {
1919819180 case IrOverflowOpAdd:
......@@ -19293,7 +19275,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
1929319275 if (!ptr_val)
1929419276 return ira->codegen->builtin_types.entry_invalid;
1929519277 ConstExprValue *err_union_val = const_ptr_pointee(ira->codegen, ptr_val);
19296 if (!err_union_val) return ira->codegen->builtin_types.entry_invalid;
1929719278 if (err_union_val->special != ConstValSpecialRuntime) {
1929819279 ErrorTableEntry *err = err_union_val->data.x_err_union.err;
1929919280 assert(err);
......@@ -19342,7 +19323,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
1934219323 if (!ptr_val)
1934319324 return ira->codegen->builtin_types.entry_invalid;
1934419325 ConstExprValue *err_union_val = const_ptr_pointee(ira->codegen, ptr_val);
19345 if (!err_union_val) return ira->codegen->builtin_types.entry_invalid;
1934619326 if (err_union_val->special != ConstValSpecialRuntime) {
1934719327 ErrorTableEntry *err = err_union_val->data.x_err_union.err;
1934819328 if (err != nullptr) {