mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 00:08:56 +00:00
fix coroutine alignment
zig returned the wrong alignment for coroutine promises in some cases
This commit is contained in:
parent
82af31ce36
commit
639c381128
@ -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) {
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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"));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user