Fix typeid comparison bug in ir.cpp

This commit is contained in:
gingerBill
2020-04-04 21:23:11 +01:00
parent b362ce9a22
commit 5e706bab56
2 changed files with 22 additions and 7 deletions
+16 -6
View File
@@ -1035,12 +1035,22 @@ void add_type_and_value(CheckerInfo *i, Ast *expr, AddressingMode mode, Type *ty
return;
}
expr->tav.mode = mode;
expr->tav.type = type;
if (mode == Addressing_Constant || mode == Addressing_Invalid) {
expr->tav.value = value;
} else if (mode == Addressing_Value && is_type_typeid(type)) {
expr->tav.value = value;
Ast *prev_expr = nullptr;
for (;;) {
if (prev_expr != expr) {
expr->tav.mode = mode;
expr->tav.type = type;
if (mode == Addressing_Constant || mode == Addressing_Invalid) {
expr->tav.value = value;
} else if (mode == Addressing_Value && is_type_typeid(type)) {
expr->tav.value = value;
}
prev_expr = expr;
} else {
break;
}
expr = unparen_expr(expr);
}
}
+6 -1
View File
@@ -7046,13 +7046,18 @@ irValue *ir_build_expr(irProcedure *proc, Ast *expr) {
}
irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) {
Ast *original_expr = expr;
expr = unparen_expr(expr);
// ir_push_debug_location(proc->module, expr, proc->debug_scope);
// defer (ir_pop_debug_location(proc->module));
TypeAndValue tv = type_and_value_of_expr(expr);
GB_ASSERT(tv.mode != Addressing_Invalid);
GB_ASSERT(tv.mode != Addressing_Type);
if (tv.mode == Addressing_Type) {
// HACK TODO(bill): This is hack but it should be safe in virtually all cases
irValue *v = ir_typeid(proc->module, tv.type);
return ir_emit_conv(proc, v, t_typeid);
}
if (tv.value.kind != ExactValue_Invalid) {
// NOTE(bill): Edge case