From 011df61f8a2a138e8023f7c89239f187c2dd4316 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 10 Sep 2017 14:03:15 -0400 Subject: fix not verifying GlobalLinkage and AtomicOrder types thanks to aep4Ayai on IRC --- src/ir.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 487f5897e4..73f7b1df1e 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -8792,11 +8792,25 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out) return ir_resolve_bool(ira, value, out); } +static ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) { + Tld *tld = codegen->compile_var_import->decls_scope->decl_table.get(buf_create_from_str(name)); + resolve_top_level_decl(codegen, tld, false, nullptr); + assert(tld->id == TldIdVar); + TldVar *tld_var = (TldVar *)tld; + ConstExprValue *var_value = tld_var->var->value; + assert(var_value != nullptr); + return var_value; +} + static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) { if (type_is_invalid(value->value.type)) return false; - IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_atomic_order_enum); + ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder"); + assert(atomic_order_val->type->id == TypeTableEntryIdMetaType); + TypeTableEntry *atomic_order_type = atomic_order_val->data.x_type; + + IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type); if (type_is_invalid(casted_value->value.type)) return false; @@ -8812,7 +8826,11 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob if (type_is_invalid(value->value.type)) return false; - IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_linkage_enum); + ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage"); + assert(global_linkage_val->type->id == TypeTableEntryIdMetaType); + TypeTableEntry *global_linkage_type = global_linkage_val->data.x_type; + + IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type); if (type_is_invalid(casted_value->value.type)) return false; @@ -8863,16 +8881,6 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { return result; } -static ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) { - Tld *tld = codegen->compile_var_import->decls_scope->decl_table.get(buf_create_from_str(name)); - resolve_top_level_decl(codegen, tld, false, nullptr); - assert(tld->id == TldIdVar); - TldVar *tld_var = (TldVar *)tld; - ConstExprValue *var_value = tld_var->var->value; - assert(var_value != nullptr); - return var_value; -} - static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *return_instruction) { -- cgit v1.2.3