diff options
| author | LemonBoy <thatlemon@gmail.com> | 2021-04-25 16:40:41 +0200 |
|---|---|---|
| committer | LemonBoy <thatlemon@gmail.com> | 2021-04-25 16:40:41 +0200 |
| commit | 50a8124f45cd0994b52af3fd166dd3bda48f4b99 (patch) | |
| tree | 1e5c4a6bcd6a9b233f9aa198a07663aa9a9ddb37 /src/stage1/analyze.cpp | |
| parent | 37b05742ff1544bccf7c8ae9b12c6707a5a54df2 (diff) | |
| download | zig-50a8124f45cd0994b52af3fd166dd3bda48f4b99.tar.gz zig-50a8124f45cd0994b52af3fd166dd3bda48f4b99.zip | |
stage1: Change how the Frame alignment is computed
The code would previously assume every function would start at addresses
being multiples of 16, this is not true beside some specific cases.
Moreover LLVM picks different alignment values depending on whether it's
trying to generate dense or fast code.
Let's use the minimum guaranteed alignment as base value, computed
according to how big the opcodes are.
The alignment of function pointers is always 1, a safe value that won't
cause any error at runtime. Note that this was already the case before
this commit, here we're making this choice explicit.
Let the 'alignment' field for TypeInfo of fn types reflect the ABI
alignment used by the compiler, make this field behave similarly to the
'alignment' one for pointers.
Diffstat (limited to 'src/stage1/analyze.cpp')
| -rw-r--r-- | src/stage1/analyze.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp index 21ad55b8f7..e1e0c496f6 100644 --- a/src/stage1/analyze.cpp +++ b/src/stage1/analyze.cpp @@ -4770,10 +4770,10 @@ Error type_is_nonnull_ptr2(CodeGen *g, ZigType *type, bool *result) { } static uint32_t get_async_frame_align_bytes(CodeGen *g) { - 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; + // Due to how the frame structure is built the minimum alignment is the one + // of a usize (or pointer). + // label (grep this): [fn_frame_struct_layout] + return max(g->builtin_types.entry_usize->abi_align, target_fn_align(g->zig_target)); } uint32_t get_ptr_align(CodeGen *g, ZigType *type) { @@ -4789,11 +4789,8 @@ uint32_t get_ptr_align(CodeGen *g, ZigType *type) { return (ptr_type->data.pointer.explicit_alignment == 0) ? get_abi_alignment(g, ptr_type->data.pointer.child_type) : ptr_type->data.pointer.explicit_alignment; } else if (ptr_type->id == ZigTypeIdFn) { - // I tried making this use LLVMABIAlignmentOfType but it trips this assertion in LLVM: - // "Cannot getTypeInfo() on a type that is unsized!" - // when getting the alignment of `?fn() callconv(.C) void`. - // See http://lists.llvm.org/pipermail/llvm-dev/2018-September/126142.html - return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment; + return (ptr_type->data.fn.fn_type_id.alignment == 0) ? + target_fn_ptr_align(g->zig_target) : ptr_type->data.fn.fn_type_id.alignment; } else if (ptr_type->id == ZigTypeIdAnyFrame) { return get_async_frame_align_bytes(g); } else { |
