authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-04-25 19:42:59+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-04-25 20:41:49+02:00
log82f1d592fae021fcfc737e3cb6c107b325fcf1ee
treee412103ef8f4de28e579b03f0ad6e473cd55daf9
parent0340ed3a9e3fd62e5f8021f2755a26fb3497123e

stage1: Use correct alignment for asyncCall frame


4 files changed, 11 insertions(+), 4 deletions(-)

src/stage1/analyze.cpp+1-1
...@@ -4769,7 +4769,7 @@ Error type_is_nonnull_ptr2(CodeGen *g, ZigType *type, bool *result) {...@@ -4769,7 +4769,7 @@ Error type_is_nonnull_ptr2(CodeGen *g, ZigType *type, bool *result) {
4769 return ErrorNone;4769 return ErrorNone;
4770}4770}
47714771
4772static uint32_t get_async_frame_align_bytes(CodeGen *g) {4772uint32_t get_async_frame_align_bytes(CodeGen *g) {
4773 // Due to how the frame structure is built the minimum alignment is the one4773 // Due to how the frame structure is built the minimum alignment is the one
4774 // of a usize (or pointer).4774 // of a usize (or pointer).
4775 // label (grep this): [fn_frame_struct_layout]4775 // label (grep this): [fn_frame_struct_layout]
src/stage1/analyze.hpp+1
...@@ -47,6 +47,7 @@ ZigType *get_test_fn_type(CodeGen *g);...@@ -47,6 +47,7 @@ ZigType *get_test_fn_type(CodeGen *g);
47ZigType *get_any_frame_type(CodeGen *g, ZigType *result_type);47ZigType *get_any_frame_type(CodeGen *g, ZigType *result_type);
48bool handle_is_ptr(CodeGen *g, ZigType *type_entry);48bool handle_is_ptr(CodeGen *g, ZigType *type_entry);
49Error emit_error_unless_callconv_allowed_for_target(CodeGen *g, AstNode *source_node, CallingConvention cc);49Error emit_error_unless_callconv_allowed_for_target(CodeGen *g, AstNode *source_node, CallingConvention cc);
50uint32_t get_async_frame_align_bytes(CodeGen *g);
5051
51bool type_has_bits(CodeGen *g, ZigType *type_entry);52bool type_has_bits(CodeGen *g, ZigType *type_entry);
52Error type_has_bits2(CodeGen *g, ZigType *type_entry, bool *result);53Error type_has_bits2(CodeGen *g, ZigType *type_entry, bool *result);
src/stage1/ir.cpp+6-2
...@@ -20659,8 +20659,12 @@ static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,...@@ -20659,8 +20659,12 @@ static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,
20659 get_fn_frame_type(ira->codegen, fn_entry), false);20659 get_fn_frame_type(ira->codegen, fn_entry), false);
20660 return ir_implicit_cast(ira, new_stack, needed_frame_type);20660 return ir_implicit_cast(ira, new_stack, needed_frame_type);
20661 } else {20661 } else {
20662 // XXX The stack alignment is hardcoded to 16 here and in
20663 // std.Target.stack_align.
20664 const uint32_t required_align = is_async_call_builtin ?
20665 get_async_frame_align_bytes(ira->codegen) : 16;
20662 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,20666 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
20663 false, false, PtrLenUnknown, target_fn_align(ira->codegen->zig_target), 0, 0, false);20667 false, false, PtrLenUnknown, required_align, 0, 0, false);
20664 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);20668 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
20665 ira->codegen->need_frame_size_prefix_data = true;20669 ira->codegen->need_frame_size_prefix_data = true;
20666 return ir_implicit_cast2(ira, new_stack_src, new_stack, u8_slice);20670 return ir_implicit_cast2(ira, new_stack_src, new_stack, u8_slice);
...@@ -30095,7 +30099,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig...@@ -30095,7 +30099,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig
30095 fn_type_id.alignment = align_bytes;30099 fn_type_id.alignment = align_bytes;
30096 result_type = get_fn_type(ira->codegen, &fn_type_id);30100 result_type = get_fn_type(ira->codegen, &fn_type_id);
30097 } else if (target_type->id == ZigTypeIdAnyFrame) {30101 } else if (target_type->id == ZigTypeIdAnyFrame) {
30098 if (align_bytes >= target_fn_align(ira->codegen->zig_target)) {30102 if (align_bytes >= get_async_frame_align_bytes(ira->codegen)) {
30099 result_type = target_type;30103 result_type = target_type;
30100 } else {30104 } else {
30101 ir_add_error(ira, &target->base, buf_sprintf("sub-aligned anyframe not allowed"));30105 ir_add_error(ira, &target->base, buf_sprintf("sub-aligned anyframe not allowed"));
test/compile_errors.zig+3-1
...@@ -2136,7 +2136,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2136,7 +2136,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2136 \\}2136 \\}
2137 \\fn func() callconv(.Async) void {}2137 \\fn func() callconv(.Async) void {}
2138 , &[_][]const u8{2138 , &[_][]const u8{
2139 "tmp.zig:4:21: error: expected type '[]align(16) u8', found '*[64]u8'",2139 // Split the check in two as the alignment value is target dependent.
2140 "tmp.zig:4:21: error: expected type '[]align(",
2141 ") u8', found '*[64]u8'",
2140 });2142 });
21412143
2142 cases.add("atomic orderings of fence Acquire or stricter",2144 cases.add("atomic orderings of fence Acquire or stricter",