authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-10 14:03:15-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-10 14:04:19-04:00
log011df61f8a2a138e8023f7c89239f187c2dd4316
tree8bd05e3168d5a3fd518a80e1455ca48fe53e0e3e
parent3f8b26c06aafbf0860faf58b12c2124677a816fd

fix not verifying GlobalLinkage and AtomicOrder types

thanks to aep4Ayai on IRC

3 files changed, 35 insertions(+), 18 deletions(-)

src/all_types.hpp-6
......@@ -1439,12 +1439,6 @@ struct CodeGen {
14391439 TypeTableEntry *entry_null;
14401440 TypeTableEntry *entry_var;
14411441 TypeTableEntry *entry_pure_error;
1442 TypeTableEntry *entry_os_enum;
1443 TypeTableEntry *entry_arch_enum;
1444 TypeTableEntry *entry_environ_enum;
1445 TypeTableEntry *entry_oformat_enum;
1446 TypeTableEntry *entry_atomic_order_enum;
1447 TypeTableEntry *entry_global_linkage_enum;
14481442 TypeTableEntry *entry_arg_tuple;
14491443 } builtin_types;
14501444
src/ir.cpp+20-12
......@@ -8792,11 +8792,25 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out)
87928792 return ir_resolve_bool(ira, value, out);
87938793}
87948794
8795static ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
8796 Tld *tld = codegen->compile_var_import->decls_scope->decl_table.get(buf_create_from_str(name));
8797 resolve_top_level_decl(codegen, tld, false, nullptr);
8798 assert(tld->id == TldIdVar);
8799 TldVar *tld_var = (TldVar *)tld;
8800 ConstExprValue *var_value = tld_var->var->value;
8801 assert(var_value != nullptr);
8802 return var_value;
8803}
8804
87958805static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) {
87968806 if (type_is_invalid(value->value.type))
87978807 return false;
87988808
8799 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_atomic_order_enum);
8809 ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder");
8810 assert(atomic_order_val->type->id == TypeTableEntryIdMetaType);
8811 TypeTableEntry *atomic_order_type = atomic_order_val->data.x_type;
8812
8813 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type);
88008814 if (type_is_invalid(casted_value->value.type))
88018815 return false;
88028816
......@@ -8812,7 +8826,11 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
88128826 if (type_is_invalid(value->value.type))
88138827 return false;
88148828
8815 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_linkage_enum);
8829 ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage");
8830 assert(global_linkage_val->type->id == TypeTableEntryIdMetaType);
8831 TypeTableEntry *global_linkage_type = global_linkage_val->data.x_type;
8832
8833 IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type);
88168834 if (type_is_invalid(casted_value->value.type))
88178835 return false;
88188836
......@@ -8863,16 +8881,6 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
88638881 return result;
88648882}
88658883
8866static ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
8867 Tld *tld = codegen->compile_var_import->decls_scope->decl_table.get(buf_create_from_str(name));
8868 resolve_top_level_decl(codegen, tld, false, nullptr);
8869 assert(tld->id == TldIdVar);
8870 TldVar *tld_var = (TldVar *)tld;
8871 ConstExprValue *var_value = tld_var->var->value;
8872 assert(var_value != nullptr);
8873 return var_value;
8874}
8875
88768884static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
88778885 IrInstructionReturn *return_instruction)
88788886{
test/compile_errors.zig+15
......@@ -2112,4 +2112,19 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
21122112 ".tmp_source.zig:15:4: error: variable of type '(bound fn(&const Foo))' must be const or comptime",
21132113 ".tmp_source.zig:17:4: error: unreachable code");
21142114
2115 cases.add("wrong types given to atomic order args in cmpxchg",
2116 \\export fn entry() {
2117 \\ var x: i32 = 1234;
2118 \\ while (!@cmpxchg(&x, 1234, 5678, u32(1234), u32(1234))) {}
2119 \\}
2120 ,
2121 ".tmp_source.zig:3:41: error: expected type 'AtomicOrder', found 'u32'");
2122
2123 cases.add("wrong types given to setGlobalLinkage",
2124 \\export fn entry() {
2125 \\ @setGlobalLinkage(entry, u32(1234));
2126 \\}
2127 ,
2128 ".tmp_source.zig:2:33: error: expected type 'GlobalLinkage', found 'u32'");
2129
21152130}