diff --git a/src/analyze.cpp b/src/analyze.cpp index a20c2091c..e0539df10 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1224,6 +1224,9 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { fn_type->data.fn.gen_param_count = gen_param_types.length; + for (size_t i = 0; i < gen_param_types.length; i += 1) { + assert(gen_param_types.items[i] != nullptr); + } fn_type->data.fn.raw_type_ref = LLVMFunctionType(gen_return_type->type_ref, gen_param_types.items, (unsigned int)gen_param_types.length, fn_type_id->is_var_args); fn_type->type_ref = LLVMPointerType(fn_type->data.fn.raw_type_ref, 0); diff --git a/src/ir.cpp b/src/ir.cpp index 30f40b3a1..77b34e755 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -19643,7 +19643,7 @@ static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnP return ira->codegen->builtin_types.entry_invalid; if (type_requires_comptime(param_type)) { if (!calling_convention_allows_zig_types(fn_type_id.cc)) { - ir_add_error(ira, &instruction->base, + ir_add_error(ira, param_type_value, buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'", buf_ptr(¶m_type->name), calling_convention_name(fn_type_id.cc))); return ira->codegen->builtin_types.entry_invalid; @@ -19654,6 +19654,12 @@ static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnP out_val->data.x_type = get_generic_fn_type(ira->codegen, &fn_type_id); return ira->codegen->builtin_types.entry_type; } + if (!type_has_bits(param_type) && !calling_convention_allows_zig_types(fn_type_id.cc)) { + ir_add_error(ira, param_type_value, + buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'", + buf_ptr(¶m_type->name), calling_convention_name(fn_type_id.cc))); + return ira->codegen->builtin_types.entry_invalid; + } param_info->type = param_type; } diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 185ca6297..dda45a589 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -1291,6 +1291,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ \\extern fn bar(x: *void) void { } , + ".tmp_source.zig:1:30: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'", ".tmp_source.zig:7:18: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'", );