Pass some more C ABI tests

This commit is contained in:
David Gonzalez Martin 2025-06-13 19:04:35 -06:00
parent 14ff80bcc5
commit 7abff8975e
2 changed files with 44 additions and 3 deletions

View File

@ -10121,9 +10121,46 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type
switch (semantic_call_argument_value.id)
{
.aggregate_initialization =>
{
>is_constant = semantic_call_argument_value.content.aggregate_initialization.is_constant;
if (is_constant)
{
>linkage: LLVMLinkage = .internal;
>thread_local_mode: LLVMThreadLocalMode = .none;
>externally_initialized: u1 = 0;
>alignment = get_byte_alignment(semantic_argument_type);
>unnamed_address: LLVMUnnamedAddress = .global;
>global = llvm_create_global_variable(module.llvm.module, semantic_argument_type.llvm.memory, is_constant, linkage, semantic_call_argument_value.llvm, "const.struct", thread_local_mode, externally_initialized, alignment, unnamed_address);
for (i: 0..coerce_fields.length)
{
>gep = LLVMBuildStructGEP2(module.llvm.builder, coerce_to_type.llvm.abi, global, #truncate(i), "");
>field = &coerce_fields[i];
>maybe_undef: u1 = 0;
if (maybe_undef)
{
#trap();
}
>load = create_load(module, {
.type = field.type,
.pointer = gep,
.alignment = alignment,
zero,
});
llvm_abi_argument_value_buffer[abi_argument_count] = load;
abi_argument_count += 1;
}
}
else
{
#trap();
}
}
.zero =>
{
#trap();
@ -13871,6 +13908,10 @@ names: [_][]u8 =
"c_abi1",
"c_med_struct_ints",
"c_ret_struct_array",
"c_split_struct_ints",
"c_string_to_slice",
"c_struct_with_array",
"c_function_pointer",
];
[export] main = fn [cc(c)] (argument_count: u32, argv: &&u8, envp: &&u8) s32

View File

@ -853,7 +853,7 @@ fn AbiSystemVClassifyResult abi_system_v_classify_type(Type* type, AbiSystemVCla
u64 vector_size = 16;
if (byte_size > 16 && (byte_size != get_byte_size(element_type) || byte_size > vector_size))
if (byte_size > 16 && (byte_size != element_size || byte_size > vector_size))
{
unreachable();
}
@ -5554,7 +5554,7 @@ fn LLVMValueRef emit_call(Module* module, Value* value, LLVMValueRef left_llvm,
bool externally_initialized = false;
auto alignment = get_byte_alignment(semantic_argument_type);
auto global = llvm_module_create_global_variable(module->llvm.module, semantic_argument_type->llvm.memory, is_constant, linkage_type, semantic_call_argument_value->llvm, string_literal("conststruct"), thread_local_mode, externally_initialized, alignment, LLVMGlobalUnnamedAddr);
auto global = llvm_module_create_global_variable(module->llvm.module, semantic_argument_type->llvm.memory, is_constant, linkage_type, semantic_call_argument_value->llvm, string_literal("const.struct"), thread_local_mode, externally_initialized, alignment, LLVMGlobalUnnamedAddr);
for (u32 i = 0; i < coerce_fields.length; i += 1)
{