diff --git a/src/codegen.cpp b/src/codegen.cpp index d664a21ecc..2170da10ac 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2216,7 +2216,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ assert(handle_is_ptr(ty)); switch (fn_walk->id) { case FnWalkIdAttrs: - addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "byval"); + ZigLLVMAddByValAttr(llvm_fn, fn_walk->data.attrs.gen_i + 1, get_llvm_type(g, ty)); addLLVMArgAttrInt(llvm_fn, fn_walk->data.attrs.gen_i, "align", get_abi_alignment(g, ty)); // Byvalue parameters must not have address 0 addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull"); diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index c033d7af96..b82d0c51ba 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -723,6 +723,16 @@ void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state) { } } +void ZigLLVMAddByValAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_val) { + Function *func = unwrap(fn_ref); + const AttributeList attr_set = func->getAttributes(); + AttrBuilder attr_builder; + Type *llvm_type = unwrap(type_val); + attr_builder.addByValAttr(llvm_type); + const AttributeList new_attr_set = attr_set.addAttributes(func->getContext(), ArgNo, attr_builder); + func->setAttributes(new_attr_set); +} + void ZigLLVMAddFunctionAttr(LLVMValueRef fn_ref, const char *attr_name, const char *attr_value) { Function *func = unwrap(fn_ref); const AttributeList attr_set = func->getAttributes(); diff --git a/src/zig_llvm.h b/src/zig_llvm.h index 210f245efe..10b6d24364 100644 --- a/src/zig_llvm.h +++ b/src/zig_llvm.h @@ -213,6 +213,7 @@ ZIG_EXTERN_C struct ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigne ZIG_EXTERN_C void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state); ZIG_EXTERN_C void ZigLLVMAddFunctionAttr(LLVMValueRef fn, const char *attr_name, const char *attr_value); +ZIG_EXTERN_C void ZigLLVMAddByValAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_val); ZIG_EXTERN_C void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn); ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv);