fix crash when pointer casting a runtime extern function
parent
780e567446
commit
dd5b2d1b04
|
@ -3992,9 +3992,10 @@ 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) {
|
||||
return (ptr_type->data.fn.fn_type_id.alignment == 0) ?
|
||||
LLVMABIAlignmentOfType(g->target_data_ref, ptr_type->data.fn.raw_type_ref) :
|
||||
ptr_type->data.fn.fn_type_id.alignment;
|
||||
// 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 `?extern fn() void`.
|
||||
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 get_coro_frame_align_bytes(g);
|
||||
} else {
|
||||
|
|
|
@ -219,3 +219,12 @@ test "alignment of structs" {
|
|||
b: *i32,
|
||||
}) == @alignOf(usize));
|
||||
}
|
||||
|
||||
test "alignment of extern() void" {
|
||||
var runtime_nothing = nothing;
|
||||
const casted1 = @ptrCast(*const u8, runtime_nothing);
|
||||
const casted2 = @ptrCast(extern fn () void, casted1);
|
||||
casted2();
|
||||
}
|
||||
|
||||
extern fn nothing() void {}
|
||||
|
|
Loading…
Reference in New Issue