| author | |
| committer | |
| log | 685b5c26b703d54381a74b71361816ad85ec8584 |
| tree | 59bb0fd0944f029a418339e554494fb4ee7af0dd |
| parent | 70e935db5bc16e5a7144dd0de3176d53dd892301 |
LLVM 12 requires sret attributes to have the struct type as a parameter,
and provides no C function for supplying it. Therefore, we must add
another C++ wrapper API for adding the sret attribute.
Fixes ability to build from source in the llvm12 branch.3 files changed, 12 insertions(+), 1 deletions(-)
src/stage1/codegen.cpp+1-1| ... | @@ -549,7 +549,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) { | ... | @@ -549,7 +549,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) { |
| 549 | } else if (want_first_arg_sret(g, &fn_type->data.fn.fn_type_id)) { | 549 | } else if (want_first_arg_sret(g, &fn_type->data.fn.fn_type_id)) { |
| 550 | // Sret pointers must not be address 0 | 550 | // Sret pointers must not be address 0 |
| 551 | addLLVMArgAttr(llvm_fn, 0, "nonnull"); | 551 | addLLVMArgAttr(llvm_fn, 0, "nonnull"); |
| 552 | addLLVMArgAttr(llvm_fn, 0, "sret"); | 552 | ZigLLVMAddSRetAttr(llvm_fn, get_llvm_type(g, fn_type->data.fn.fn_type_id.return_type)); |
| 553 | if (cc_want_sret_attr(cc)) { | 553 | if (cc_want_sret_attr(cc)) { |
| 554 | addLLVMArgAttr(llvm_fn, 0, "noalias"); | 554 | addLLVMArgAttr(llvm_fn, 0, "noalias"); |
| 555 | } | 555 | } |
src/zig_llvm.cpp+10| ... | @@ -802,6 +802,16 @@ void ZigLLVMAddByValAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_v | ... | @@ -802,6 +802,16 @@ void ZigLLVMAddByValAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_v |
| 802 | func->setAttributes(new_attr_set); | 802 | func->setAttributes(new_attr_set); |
| 803 | } | 803 | } |
| 804 | 804 | ||
| 805 | void ZigLLVMAddSRetAttr(LLVMValueRef fn_ref, LLVMTypeRef type_val) { | ||
| 806 | Function *func = unwrap<Function>(fn_ref); | ||
| 807 | const AttributeList attr_set = func->getAttributes(); | ||
| 808 | AttrBuilder attr_builder; | ||
| 809 | Type *llvm_type = unwrap<Type>(type_val); | ||
| 810 | attr_builder.addStructRetAttr(llvm_type); | ||
| 811 | const AttributeList new_attr_set = attr_set.addAttributes(func->getContext(), 1, attr_builder); | ||
| 812 | func->setAttributes(new_attr_set); | ||
| 813 | } | ||
| 814 | |||
| 805 | void ZigLLVMAddFunctionAttr(LLVMValueRef fn_ref, const char *attr_name, const char *attr_value) { | 815 | void ZigLLVMAddFunctionAttr(LLVMValueRef fn_ref, const char *attr_name, const char *attr_value) { |
| 806 | Function *func = unwrap<Function>(fn_ref); | 816 | Function *func = unwrap<Function>(fn_ref); |
| 807 | const AttributeList attr_set = func->getAttributes(); | 817 | const AttributeList attr_set = func->getAttributes(); |
src/zig_llvm.h+1| ... | @@ -269,6 +269,7 @@ ZIG_EXTERN_C void ZigLLVMFunctionSetCallingConv(LLVMValueRef function, enum ZigL | ... | @@ -269,6 +269,7 @@ ZIG_EXTERN_C void ZigLLVMFunctionSetCallingConv(LLVMValueRef function, enum ZigL |
| 269 | 269 | ||
| 270 | ZIG_EXTERN_C void ZigLLVMAddFunctionAttr(LLVMValueRef fn, const char *attr_name, const char *attr_value); | 270 | ZIG_EXTERN_C void ZigLLVMAddFunctionAttr(LLVMValueRef fn, const char *attr_name, const char *attr_value); |
| 271 | ZIG_EXTERN_C void ZigLLVMAddByValAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_val); | 271 | ZIG_EXTERN_C void ZigLLVMAddByValAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_val); |
| 272 | ZIG_EXTERN_C void ZigLLVMAddSRetAttr(LLVMValueRef fn_ref, LLVMTypeRef type_val); | ||
| 272 | ZIG_EXTERN_C void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn); | 273 | ZIG_EXTERN_C void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn); |
| 273 | 274 | ||
| 274 | ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv); | 275 | ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv); |