Commit 011df61f8a
Changed files (3)
src/all_types.hpp
@@ -1439,12 +1439,6 @@ struct CodeGen {
TypeTableEntry *entry_null;
TypeTableEntry *entry_var;
TypeTableEntry *entry_pure_error;
- TypeTableEntry *entry_os_enum;
- TypeTableEntry *entry_arch_enum;
- TypeTableEntry *entry_environ_enum;
- TypeTableEntry *entry_oformat_enum;
- TypeTableEntry *entry_atomic_order_enum;
- TypeTableEntry *entry_global_linkage_enum;
TypeTableEntry *entry_arg_tuple;
} builtin_types;
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)
{
test/compile_errors.zig
@@ -2112,4 +2112,19 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
".tmp_source.zig:15:4: error: variable of type '(bound fn(&const Foo))' must be const or comptime",
".tmp_source.zig:17:4: error: unreachable code");
+ cases.add("wrong types given to atomic order args in cmpxchg",
+ \\export fn entry() {
+ \\ var x: i32 = 1234;
+ \\ while (!@cmpxchg(&x, 1234, 5678, u32(1234), u32(1234))) {}
+ \\}
+ ,
+ ".tmp_source.zig:3:41: error: expected type 'AtomicOrder', found 'u32'");
+
+ cases.add("wrong types given to setGlobalLinkage",
+ \\export fn entry() {
+ \\ @setGlobalLinkage(entry, u32(1234));
+ \\}
+ ,
+ ".tmp_source.zig:2:33: error: expected type 'GlobalLinkage', found 'u32'");
+
}