stage1: upgrade to new LLVM sret attribute requirement

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.
This commit is contained in:
Andrew Kelley
2021-02-26 13:32:04 -07:00
parent 70e935db5b
commit 685b5c26b7
3 changed files with 12 additions and 1 deletions

View File

@@ -549,7 +549,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
} else if (want_first_arg_sret(g, &fn_type->data.fn.fn_type_id)) {
// Sret pointers must not be address 0
addLLVMArgAttr(llvm_fn, 0, "nonnull");
addLLVMArgAttr(llvm_fn, 0, "sret");
ZigLLVMAddSRetAttr(llvm_fn, get_llvm_type(g, fn_type->data.fn.fn_type_id.return_type));
if (cc_want_sret_attr(cc)) {
addLLVMArgAttr(llvm_fn, 0, "noalias");
}

View File

@@ -802,6 +802,16 @@ void ZigLLVMAddByValAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_v
func->setAttributes(new_attr_set);
}
void ZigLLVMAddSRetAttr(LLVMValueRef fn_ref, LLVMTypeRef type_val) {
Function *func = unwrap<Function>(fn_ref);
const AttributeList attr_set = func->getAttributes();
AttrBuilder attr_builder;
Type *llvm_type = unwrap<Type>(type_val);
attr_builder.addStructRetAttr(llvm_type);
const AttributeList new_attr_set = attr_set.addAttributes(func->getContext(), 1, attr_builder);
func->setAttributes(new_attr_set);
}
void ZigLLVMAddFunctionAttr(LLVMValueRef fn_ref, const char *attr_name, const char *attr_value) {
Function *func = unwrap<Function>(fn_ref);
const AttributeList attr_set = func->getAttributes();

View File

@@ -269,6 +269,7 @@ ZIG_EXTERN_C void ZigLLVMFunctionSetCallingConv(LLVMValueRef function, enum ZigL
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 ZigLLVMAddSRetAttr(LLVMValueRef fn_ref, LLVMTypeRef type_val);
ZIG_EXTERN_C void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn);
ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv);