From abc30f79489b68f6dc0ee4b408c63a8e783215d1 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 20 Sep 2021 16:48:42 -0700 Subject: stage2: improve handling of 0 bit types * Sema: zirAtomicLoad handles 0-bit types correctly * LLVM backend: when lowering function types, elide parameters with 0-bit types. * Type: abiSize handles u0/i0 correctly --- src/codegen/llvm.zig | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/codegen') diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 2e835260af..2f703e2d68 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -541,17 +541,21 @@ pub const DeclGen = struct { defer self.gpa.free(fn_param_types); zig_fn_type.fnParamTypes(fn_param_types); - const llvm_param = try self.gpa.alloc(*const llvm.Type, fn_param_len); - defer self.gpa.free(llvm_param); - - for (fn_param_types) |fn_param, i| { - llvm_param[i] = try self.llvmType(fn_param); + const llvm_param_buffer = try self.gpa.alloc(*const llvm.Type, fn_param_len); + defer self.gpa.free(llvm_param_buffer); + + var llvm_params_len: c_uint = 0; + for (fn_param_types) |fn_param| { + if (fn_param.hasCodeGenBits()) { + llvm_param_buffer[llvm_params_len] = try self.llvmType(fn_param); + llvm_params_len += 1; + } } const fn_type = llvm.functionType( try self.llvmType(return_type), - llvm_param.ptr, - @intCast(c_uint, fn_param_len), + llvm_param_buffer.ptr, + llvm_params_len, .False, ); const llvm_fn = self.llvmModule().addFunction(decl.name, fn_type); -- cgit v1.2.3