authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-14 13:54:33-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-14 13:55:45-04:00
log639c3811288b65173b3d9706b8e2001ee2419233
tree7c800c2e3853280c2eafd44d0456feb4096e0b4f
parent82af31ce368d16cc5cadac80faa3d8a4d4b1f752
signaturelock-open Commit is signed but in an unrecognized format.

fix coroutine alignment

zig returned the wrong alignment for coroutine promises in some cases

3 files changed, 9 insertions(+), 10 deletions(-)

src/analyze.cpp+6-7
......@@ -3953,14 +3953,14 @@ bool type_is_codegen_pointer(ZigType *type) {
39533953 return get_codegen_ptr_type(type) == type;
39543954}
39553955
3956uint32_t get_ptr_align(ZigType *type) {
3956uint32_t get_ptr_align(CodeGen *g, ZigType *type) {
39573957 ZigType *ptr_type = get_codegen_ptr_type(type);
39583958 if (ptr_type->id == ZigTypeIdPointer) {
39593959 return ptr_type->data.pointer.alignment;
39603960 } else if (ptr_type->id == ZigTypeIdFn) {
39613961 return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;
39623962 } else if (ptr_type->id == ZigTypeIdPromise) {
3963 return 1;
3963 return get_coro_frame_align_bytes(g);
39643964 } else {
39653965 zig_unreachable();
39663966 }
......@@ -6277,10 +6277,6 @@ uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry) {
62776277 return 1;
62786278 } else {
62796279 uint32_t llvm_alignment = LLVMABIAlignmentOfType(g->target_data_ref, type_entry->type_ref);
6280 // promises have at least alignment 8 so that we can have 3 extra bits when doing atomicrmw
6281 if (type_entry->id == ZigTypeIdPromise && llvm_alignment < 8) {
6282 return 8;
6283 }
62846280 return llvm_alignment;
62856281 }
62866282}
......@@ -6318,7 +6314,10 @@ bool type_is_global_error_set(ZigType *err_set_type) {
63186314}
63196315
63206316uint32_t get_coro_frame_align_bytes(CodeGen *g) {
6321 return g->pointer_size_bytes * 2;
6317 uint32_t a = g->pointer_size_bytes * 2;
6318 // promises have at least alignment 8 so that we can have 3 extra bits when doing atomicrmw
6319 if (a < 8) a = 8;
6320 return a;
63226321}
63236322
63246323bool type_can_fail(ZigType *type_entry) {
src/analyze.hpp+1-1
......@@ -54,7 +54,7 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *so
5454bool type_is_codegen_pointer(ZigType *type);
5555
5656ZigType *get_codegen_ptr_type(ZigType *type);
57uint32_t get_ptr_align(ZigType *type);
57uint32_t get_ptr_align(CodeGen *g, ZigType *type);
5858bool get_ptr_const(ZigType *type);
5959ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry);
6060ZigType *container_ref_type(ZigType *type_entry);
src/ir.cpp+2-2
......@@ -20023,8 +20023,8 @@ static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtr
2002320023 return dest_type;
2002420024 }
2002520025
20026 uint32_t src_align_bytes = get_ptr_align(src_type);
20027 uint32_t dest_align_bytes = get_ptr_align(dest_type);
20026 uint32_t src_align_bytes = get_ptr_align(ira->codegen, src_type);
20027 uint32_t dest_align_bytes = get_ptr_align(ira->codegen, dest_type);
2002820028
2002920029 if (dest_align_bytes > src_align_bytes) {
2003020030 ErrorMsg *msg = ir_add_error(ira, &instruction->base, buf_sprintf("cast increases pointer alignment"));