aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-09-04 11:58:31 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-09-04 11:58:31 -0400
commitdbde8254d02241d893140cb499ad25e8cbb3438a (patch)
treeaf5be3723d32a378891fac4320e6a4b9a4edd674 /src/codegen.cpp
parentf7f11e237c96a357e9a5e8b4a8ce2c6a7499de3b (diff)
parent2bd2a8ea3430b92f0c41d602d12982f776a9a524 (diff)
downloadzig-dbde8254d02241d893140cb499ad25e8cbb3438a.tar.gz
zig-dbde8254d02241d893140cb499ad25e8cbb3438a.zip
Merge remote-tracking branch 'origin/master' into llvm7
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 318f8e4f19..e4405867ba 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -2618,6 +2618,9 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
IrInstructionPtrCast *instruction)
{
TypeTableEntry *wanted_type = instruction->base.value.type;
+ if (!type_has_bits(wanted_type)) {
+ return nullptr;
+ }
LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
return LLVMBuildBitCast(g->builder, ptr, wanted_type->type_ref, "");
}
@@ -3036,6 +3039,12 @@ 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, 1);
+ LLVMAddCallSiteAttribute(call_instr, 1, sret_attr);
+}
+
static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCall *instruction) {
LLVMValueRef fn_val;
TypeTableEntry *fn_type;
@@ -3131,6 +3140,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
} else if (!ret_has_bits) {
return nullptr;
} else if (first_arg_ret) {
+ set_call_instr_sret(g, result);
return instruction->tmp_ptr;
} else if (handle_is_ptr(src_return_type)) {
auto store_instr = LLVMBuildStore(g->builder, result, instruction->tmp_ptr);
@@ -4573,8 +4583,9 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f
args.append(allocator_val);
args.append(coro_size);
args.append(alignment_val);
- ZigLLVMBuildCall(g->builder, alloc_fn_val, args.items, args.length,
+ LLVMValueRef call_instruction = ZigLLVMBuildCall(g->builder, alloc_fn_val, args.items, args.length,
get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_FnInlineAuto, "");
+ set_call_instr_sret(g, call_instruction);
LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, sret_ptr, err_union_err_index, "");
LLVMValueRef err_val = LLVMBuildLoad(g->builder, err_val_ptr, "");
LLVMBuildStore(g->builder, err_val, err_code_ptr);