zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 72404db31f76635f11d0aa4dcc02c149ef885b3d (tree)
parent 6af6c3c9791b655b3adca08749baf89404b081ae
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun, 28 Feb 2021 22:01:13 -0700

stage1: update to LLVM 12 sret callsite requirements

Without this, the LLVM IR that zig generates cannot be compiled by LLVM.

Diffstat:
Msrc/stage1/codegen.cpp | 8+-------
Msrc/zig_llvm.cpp | 9+++++++++
Msrc/zig_llvm.h | 1+
3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp @@ -4037,12 +4037,6 @@ static void gen_set_stack_pointer(CodeGen *g, LLVMValueRef aligned_end_addr) { LLVMBuildCall(g->builder, write_register_fn_val, params, 2, ""); } -static void set_call_instr_sret(CodeGen *g, LLVMValueRef call_instr) { - unsigned attr_kind_id = LLVMGetEnumAttributeKindForName("sret", 4); - LLVMAttributeRef sret_attr = LLVMCreateEnumAttribute(LLVMGetGlobalContext(), attr_kind_id, 0); - LLVMAddCallSiteAttribute(call_instr, 1, sret_attr); -} - static void render_async_spills(CodeGen *g) { ZigType *fn_type = g->cur_fn->type_entry; ZigType *import = get_scope_import(&g->cur_fn->fndef_scope->base); @@ -4558,7 +4552,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn } else if (!ret_has_bits) { return nullptr; } else if (first_arg_ret) { - set_call_instr_sret(g, result); + ZigLLVMSetCallSret(result, get_llvm_type(g, src_return_type)); return result_loc; } else if (handle_is_ptr(g, src_return_type)) { LLVMValueRef store_instr = LLVMBuildStore(g->builder, result, result_loc); diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp @@ -940,6 +940,15 @@ void ZigLLVMSetTailCall(LLVMValueRef Call) { unwrap<CallInst>(Call)->setTailCallKind(CallInst::TCK_MustTail); } +void ZigLLVMSetCallSret(LLVMValueRef Call, LLVMTypeRef return_type) { + const AttributeList attr_set = unwrap<CallInst>(Call)->getAttributes(); + AttrBuilder attr_builder; + Type *llvm_type = unwrap<Type>(return_type); + attr_builder.addStructRetAttr(llvm_type); + const AttributeList new_attr_set = attr_set.addAttributes(unwrap<CallInst>(Call)->getContext(), 1, attr_builder); + unwrap<CallInst>(Call)->setAttributes(new_attr_set); +} + void ZigLLVMFunctionSetPrefixData(LLVMValueRef function, LLVMValueRef data) { unwrap<Function>(function)->setPrefixData(unwrap<Constant>(data)); } diff --git a/src/zig_llvm.h b/src/zig_llvm.h @@ -264,6 +264,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 ZigLLVMSetTailCall(LLVMValueRef Call); +ZIG_EXTERN_C void ZigLLVMSetCallSret(LLVMValueRef Call, LLVMTypeRef return_type); ZIG_EXTERN_C void ZigLLVMFunctionSetPrefixData(LLVMValueRef fn, LLVMValueRef data); ZIG_EXTERN_C void ZigLLVMFunctionSetCallingConv(LLVMValueRef function, enum ZigLLVM_CallingConv cc);