add realloc (and update c_allocator)

This commit is contained in:
2026-07-11 13:42:55 +02:00
parent 90869dcb4d
commit 6dd6b7ff54
6 changed files with 122 additions and 5 deletions
+4
View File
@@ -3282,6 +3282,7 @@ allocator_contract_c_allocator_global_lowers :: proc(t: ^testing.T) {
found_c_allocator := false
found_anyopaque_context := false
found_alloc_callback := false
found_realloc_callback := false
found_free_callback := false
for global in hir_module.globals {
if symbol.resolve(&symbols, global.name) != "c_allocator" {
@@ -3303,6 +3304,7 @@ allocator_contract_c_allocator_global_lowers :: proc(t: ^testing.T) {
}
}
found_alloc_callback = found_alloc_callback || name == "alloc" && callable && !callback_pointer.many
found_realloc_callback = found_realloc_callback || name == "realloc" && callable && !callback_pointer.many
found_free_callback = found_free_callback || name == "free" && callable && !callback_pointer.many
}
}
@@ -3312,6 +3314,7 @@ allocator_contract_c_allocator_global_lowers :: proc(t: ^testing.T) {
testing.expect(t, found_c_allocator)
testing.expect(t, found_anyopaque_context)
testing.expect(t, found_alloc_callback)
testing.expect(t, found_realloc_callback)
testing.expect(t, found_free_callback)
}
@@ -3346,6 +3349,7 @@ milestone_25_c_allocator_emits_libc_alloc_declarations :: proc(t: ^testing.T) {
testing.expect_value(t, len(diagnostics.items), 0)
testing.expect(t, strings.contains(llvm_text, "declare ptr @malloc(i64)"))
testing.expect(t, strings.contains(llvm_text, "declare ptr @realloc(ptr, i64)"))
testing.expect(t, strings.contains(llvm_text, "declare i32 @posix_memalign(ptr, i64, i64)"))
testing.expect(t, strings.contains(llvm_text, "declare void @free(ptr)"))
}