diff --git a/src/analyze.cpp b/src/analyze.cpp index 9af4f7347c..d403433c5c 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -3953,14 +3953,14 @@ bool type_is_codegen_pointer(ZigType *type) { return get_codegen_ptr_type(type) == type; } -uint32_t get_ptr_align(ZigType *type) { +uint32_t get_ptr_align(CodeGen *g, ZigType *type) { ZigType *ptr_type = get_codegen_ptr_type(type); if (ptr_type->id == ZigTypeIdPointer) { return ptr_type->data.pointer.alignment; } else if (ptr_type->id == ZigTypeIdFn) { return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment; } else if (ptr_type->id == ZigTypeIdPromise) { - return 1; + return get_coro_frame_align_bytes(g); } else { zig_unreachable(); } @@ -6277,10 +6277,6 @@ uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry) { return 1; } else { uint32_t llvm_alignment = LLVMABIAlignmentOfType(g->target_data_ref, type_entry->type_ref); - // promises have at least alignment 8 so that we can have 3 extra bits when doing atomicrmw - if (type_entry->id == ZigTypeIdPromise && llvm_alignment < 8) { - return 8; - } return llvm_alignment; } } @@ -6318,7 +6314,10 @@ bool type_is_global_error_set(ZigType *err_set_type) { } uint32_t get_coro_frame_align_bytes(CodeGen *g) { - return g->pointer_size_bytes * 2; + uint32_t a = g->pointer_size_bytes * 2; + // promises have at least alignment 8 so that we can have 3 extra bits when doing atomicrmw + if (a < 8) a = 8; + return a; } bool type_can_fail(ZigType *type_entry) { diff --git a/src/analyze.hpp b/src/analyze.hpp index 02f3d65800..76f2000cf7 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -54,7 +54,7 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *so bool type_is_codegen_pointer(ZigType *type); ZigType *get_codegen_ptr_type(ZigType *type); -uint32_t get_ptr_align(ZigType *type); +uint32_t get_ptr_align(CodeGen *g, ZigType *type); bool get_ptr_const(ZigType *type); ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry); ZigType *container_ref_type(ZigType *type_entry); diff --git a/src/ir.cpp b/src/ir.cpp index 7448d3fffe..fd23992a9e 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -20023,8 +20023,8 @@ static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtr return dest_type; } - uint32_t src_align_bytes = get_ptr_align(src_type); - uint32_t dest_align_bytes = get_ptr_align(dest_type); + uint32_t src_align_bytes = get_ptr_align(ira->codegen, src_type); + uint32_t dest_align_bytes = get_ptr_align(ira->codegen, dest_type); if (dest_align_bytes > src_align_bytes) { ErrorMsg *msg = ir_add_error(ira, &instruction->base, buf_sprintf("cast increases pointer alignment"));