authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-21 13:25:05-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-21 13:25:05-05:00
logce444771c5a4da1d6caab0959e5c8dd5f2df820e
tree3095ef0192e7fb17ad36d125e7ba127cb57a6f50
parent8d73703d524e06e17320e025ff970c86ebc01d22
signaturelock-open Commit is signed but in an unrecognized format.

fix incorrect `@typeInfo` for sentinels


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

src/ir.cpp+27-1
...@@ -14467,6 +14467,32 @@ static bool optional_value_is_null(ZigValue *val) {...@@ -14467,6 +14467,32 @@ static bool optional_value_is_null(ZigValue *val) {
14467 }14467 }
14468}14468}
1446914469
14470static void set_optional_value_to_null(ZigValue *val) {
14471 assert(val->special == ConstValSpecialStatic);
14472 if (val->type->id == ZigTypeIdNull) return; // nothing to do
14473 assert(val->type->id == ZigTypeIdOptional);
14474 if (get_codegen_ptr_type(val->type) != nullptr) {
14475 val->data.x_ptr.special = ConstPtrSpecialNull;
14476 } else if (is_opt_err_set(val->type)) {
14477 val->data.x_err_set = nullptr;
14478 } else {
14479 val->data.x_optional = nullptr;
14480 }
14481}
14482
14483static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) {
14484 assert(opt_val->special == ConstValSpecialStatic);
14485 assert(opt_val->type->id == ZigTypeIdOptional);
14486 if (payload == nullptr) {
14487 set_optional_value_to_null(opt_val);
14488 } else if (is_opt_err_set(opt_val->type)) {
14489 assert(payload->type->id == ZigTypeIdErrorSet);
14490 opt_val->data.x_err_set = payload->data.x_err_set;
14491 } else {
14492 opt_val->data.x_optional = payload;
14493 }
14494}
14495
14470static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,14496static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,
14471 ZigValue *op1_val, ZigValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id,14497 ZigValue *op1_val, ZigValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id,
14472 bool one_possible_value) {14498 bool one_possible_value) {
...@@ -22731,7 +22757,7 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_ent...@@ -22731,7 +22757,7 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_ent
22731 fields[6]->special = ConstValSpecialStatic;22757 fields[6]->special = ConstValSpecialStatic;
22732 if (attrs_type->data.pointer.child_type->id != ZigTypeIdOpaque) {22758 if (attrs_type->data.pointer.child_type->id != ZigTypeIdOpaque) {
22733 fields[6]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type);22759 fields[6]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type);
22734 fields[6]->data.x_optional = attrs_type->data.pointer.sentinel;22760 set_optional_payload(fields[6], attrs_type->data.pointer.sentinel);
22735 } else {22761 } else {
22736 fields[6]->type = ira->codegen->builtin_types.entry_null;22762 fields[6]->type = ira->codegen->builtin_types.entry_null;
22737 }22763 }