kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

commit 912dbabac0f3bde2a9d89a4a0613dd38064e77ef
parent fbd324f8653a7f3a4ffb2e5fdaf4b0248e7d2e57
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Mon, 25 May 2026 14:20:43 -0700

Keep CG API tests on public surface

Diffstat:
Mlang/c/parse/parse.c | 3+++
Mtest/api/cg_switch_test.c | 19++++++++++++-------
Mtest/api/cg_type_test.c | 228+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
Mtest/test.mk | 14++++++++------
4 files changed, 172 insertions(+), 92 deletions(-)

diff --git a/lang/c/parse/parse.c b/lang/c/parse/parse.c @@ -1224,6 +1224,9 @@ static void parse_external_decl(Parser* p) { if (specs.storage == DS_AUTO && specs.storage_explicit) { perr(p, "invalid storage-class specifier at file scope"); } + if (specs.storage == DS_REGISTER) { + perr(p, "invalid storage-class specifier at file scope"); + } if (accept_punct(p, ';')) return; diff --git a/test/api/cg_switch_test.c b/test/api/cg_switch_test.c @@ -17,14 +17,12 @@ #include <cfree/cg.h> #include <cfree/core.h> +#include <cfree/object.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "core/core.h" -#include "obj/obj.h" - static void* h_alloc(CfreeHeap* h, size_t n, size_t a) { (void)h; (void)a; @@ -66,6 +64,12 @@ static int g_fail; } \ } while (0) +static CfreeObjBuilder* new_obj(CfreeCompiler* c) { + CfreeObjBuilder* ob = NULL; + if (cfree_obj_builder_new(c, &ob) != CFREE_OK) return NULL; + return ob; +} + /* ---- Helpers --------------------------------------------------------- */ typedef struct SwitchShape { @@ -112,15 +116,16 @@ static void build_switch_fn(CfreeCompiler* c, CfreeCgTypeId i32_ty, memset(&opts, 0, sizeof opts); opts.opt_level = opt_level; - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); - EXPECT(ob != NULL, "[%s/O%d] obj_new failed", sh->name, opt_level); + ob = new_obj(c); + EXPECT(ob != NULL, "[%s/O%d] obj builder allocation failed", sh->name, + opt_level); if (!ob) return; cg = NULL; (void)cfree_cg_new(c, &cg); if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "[%s/O%d] cg_new failed", sh->name, opt_level); if (!cg) { - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); return; } @@ -202,7 +207,7 @@ static void build_switch_fn(CfreeCompiler* c, CfreeCgTypeId i32_ty, free(case_lbls); free(cases); cfree_cg_free(cg); - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); } /* ---- Shapes ---------------------------------------------------------- */ diff --git a/test/api/cg_type_test.c b/test/api/cg_type_test.c @@ -1,15 +1,13 @@ #include <cfree/cg.h> #include <cfree/compile.h> #include <cfree/core.h> +#include <cfree/frontend.h> #include <cfree/object.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "core/core.h" -#include "obj/obj.h" - static void* h_alloc(CfreeHeap* h, size_t n, size_t a) { (void)h; (void)a; @@ -61,21 +59,65 @@ static int g_fail; } \ } while (0) +static CfreeObjBuilder* new_obj(CfreeCompiler* c) { + CfreeObjBuilder* ob = NULL; + if (cfree_obj_builder_new(c, &ob) != CFREE_OK) return NULL; + return ob; +} + +static int open_emitted_obj(CfreeCompiler* c, CfreeObjBuilder* ob, + CfreeWriter** writer_out, + CfreeObjFile** file_out) { + CfreeWriter* w = NULL; + CfreeObjFile* f = NULL; + CfreeSlice bytes; + size_t len = 0; + const CfreeContext* ctx; + + if (!writer_out || !file_out) return 0; + *writer_out = NULL; + *file_out = NULL; + if (cfree_writer_mem(&g_heap, &w) != CFREE_OK || !w) return 0; + if (cfree_obj_builder_emit(ob, w) != CFREE_OK) { + cfree_writer_close(w); + return 0; + } + bytes.data = cfree_writer_mem_bytes(w, &len); + bytes.len = len; + ctx = cfree_compiler_context(c); + if (cfree_obj_open(ctx, CFREE_SLICE_LIT("<cg-api-test>"), &bytes, &f) != + CFREE_OK) { + cfree_writer_close(w); + return 0; + } + *writer_out = w; + *file_out = f; + return 1; +} + +typedef struct PanicRunCtx { + void (*fn)(void*); + void* arg; +} PanicRunCtx; + +static CfreeStatus run_expected_panic(CfreeCompiler* c, void* arg) { + PanicRunCtx* ctx = (PanicRunCtx*)arg; + (void)c; + ctx->fn(ctx->arg); + return CFREE_OK; +} + static int expect_panic_contains(CfreeCompiler* c, void (*fn)(void*), void* arg, const char* expected) { - PanicSave saved; - int panicked = 0; + PanicRunCtx ctx; + CfreeStatus st; + ctx.fn = fn; + ctx.arg = arg; g_last_diag[0] = '\0'; - compiler_panic_save((Compiler*)c, &saved); g_suppress_expected_panic_diag++; - if (setjmp(((Compiler*)c)->panic)) { - panicked = 1; - } else { - fn(arg); - } + st = cfree_frontend_run(c, run_expected_panic, &ctx); g_suppress_expected_panic_diag--; - compiler_panic_restore((Compiler*)c, &saved); - return panicked && strstr(g_last_diag, expected) != NULL; + return st == CFREE_ERR && strstr(g_last_diag, expected) != NULL; } static void exercise_cg_handles(CfreeCompiler* c, CfreeCgTypeId i32_ty, @@ -95,7 +137,7 @@ static void exercise_cg_handles(CfreeCompiler* c, CfreeCgTypeId i32_ty, memset(&opts, 0, sizeof(opts)); opts.opt_level = opt_level; - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); + ob = new_obj(c); EXPECT(ob != NULL, "obj builder allocation failed"); if (!ob) return; cg = NULL; @@ -103,7 +145,7 @@ static void exercise_cg_handles(CfreeCompiler* c, CfreeCgTypeId i32_ty, if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "cg allocation failed"); if (!cg) { - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); return; } @@ -155,7 +197,7 @@ static void exercise_cg_handles(CfreeCompiler* c, CfreeCgTypeId i32_ty, cfree_cg_func_end(cg); cfree_cg_free(cg); - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); } static void exercise_cg_scalar_local(CfreeCompiler* c, CfreeCgTypeId i32_ty, @@ -173,7 +215,7 @@ static void exercise_cg_scalar_local(CfreeCompiler* c, CfreeCgTypeId i32_ty, memset(&opts, 0, sizeof opts); opts.opt_level = opt_level; - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); + ob = new_obj(c); EXPECT(ob != NULL, "obj builder allocation failed"); if (!ob) return; cg = NULL; @@ -181,7 +223,7 @@ static void exercise_cg_scalar_local(CfreeCompiler* c, CfreeCgTypeId i32_ty, if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "cg allocation failed"); if (!cg) { - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); return; } @@ -221,7 +263,7 @@ static void exercise_cg_scalar_local(CfreeCompiler* c, CfreeCgTypeId i32_ty, cfree_cg_func_end(cg); cfree_cg_free(cg); - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); } static void exercise_cg_late_local_addr(CfreeCompiler* c, CfreeCgTypeId i32_ty, @@ -239,7 +281,7 @@ static void exercise_cg_late_local_addr(CfreeCompiler* c, CfreeCgTypeId i32_ty, memset(&opts, 0, sizeof opts); opts.opt_level = opt_level; - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); + ob = new_obj(c); EXPECT(ob != NULL, "obj builder allocation failed"); if (!ob) return; cg = NULL; @@ -247,7 +289,7 @@ static void exercise_cg_late_local_addr(CfreeCompiler* c, CfreeCgTypeId i32_ty, if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "cg allocation failed"); if (!cg) { - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); return; } @@ -288,16 +330,26 @@ static void exercise_cg_late_local_addr(CfreeCompiler* c, CfreeCgTypeId i32_ty, cfree_cg_func_end(cg); cfree_cg_free(cg); - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); } -static uint32_t text_size(const ObjBuilder* ob) { +static uint32_t text_size(CfreeCompiler* c, CfreeObjBuilder* ob) { uint32_t total = 0; - uint32_t n = obj_section_count(ob); + CfreeWriter* w = NULL; + CfreeObjFile* f = NULL; + uint32_t n; + if (!open_emitted_obj(c, ob, &w, &f)) { + EXPECT(0, "failed to inspect emitted object"); + return 0; + } + n = cfree_obj_nsections(f); for (uint32_t i = 0; i < n; ++i) { - const Section* sec = obj_section_get(ob, i); - if (sec && sec->kind == SEC_TEXT) total += sec->bytes.total; + CfreeObjSecInfo sec; + if (cfree_obj_section(f, i, &sec) != CFREE_OK) continue; + if (sec.kind == CFREE_SEC_TEXT) total += (uint32_t)sec.size; } + cfree_obj_free(f); + cfree_writer_close(w); return total; } @@ -313,7 +365,7 @@ static void exercise_cg_data_entsize(CfreeCompiler* c, CfreeCgTypeId i8_ty) { int found = 0; memset(&opts, 0, sizeof opts); - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); + ob = new_obj(c); EXPECT(ob != NULL, "entsize obj builder allocation failed"); if (!ob) return; cg = NULL; @@ -321,7 +373,7 @@ static void exercise_cg_data_entsize(CfreeCompiler* c, CfreeCgTypeId i8_ty) { if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "entsize cg allocation failed"); if (!cg) { - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); return; } @@ -349,20 +401,35 @@ static void exercise_cg_data_entsize(CfreeCompiler* c, CfreeCgTypeId i8_ty) { cfree_cg_data_begin(cg, sym, data_attrs); cfree_cg_data_bytes(cg, bytes, sizeof bytes); cfree_cg_data_end(cg); + cfree_cg_free(cg); - for (uint32_t i = 0; i < obj_section_count((ObjBuilder*)ob); ++i) { - const Section* sec = obj_section_get((ObjBuilder*)ob, i); - if (!sec) continue; - if ((sec->flags & (SF_MERGE | SF_STRINGS)) == (SF_MERGE | SF_STRINGS)) { - found = 1; - EXPECT(sec->entsize == 1, - "merge string section entsize should be 1, got %u", sec->entsize); + { + CfreeWriter* w = NULL; + CfreeObjFile* f = NULL; + uint32_t n; + if (!open_emitted_obj(c, ob, &w, &f)) { + EXPECT(0, "failed to inspect entsize object"); + cfree_obj_builder_free(ob); + return; + } + n = cfree_obj_nsections(f); + for (uint32_t i = 0; i < n; ++i) { + CfreeObjSecInfo sec; + if (cfree_obj_section(f, i, &sec) != CFREE_OK) continue; + if ((sec.flags & (CFREE_SF_MERGE | CFREE_SF_STRINGS)) == + (CFREE_SF_MERGE | CFREE_SF_STRINGS)) { + found = 1; + EXPECT(sec.entsize == 1, + "merge string section entsize should be 1, got %u", + sec.entsize); + } } + cfree_obj_free(f); + cfree_writer_close(w); } EXPECT(found, "expected merge string data section"); - cfree_cg_free(cg); - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); } static CfreeCgSym begin_i32_func(CfreeCompiler* c, CfreeCg* cg, @@ -396,7 +463,7 @@ static void exercise_cg_literal_folds(CfreeCompiler* c, CfreeCgTypeId i32_ty) { memset(&opts, 0, sizeof opts); opts.opt_level = 1; - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); + ob = new_obj(c); EXPECT(ob != NULL, "literal fold obj builder allocation failed"); if (!ob) return; cg = NULL; @@ -404,7 +471,7 @@ static void exercise_cg_literal_folds(CfreeCompiler* c, CfreeCgTypeId i32_ty) { if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "literal fold cg allocation failed"); if (!cg) { - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); return; } @@ -445,10 +512,10 @@ static void exercise_cg_literal_folds(CfreeCompiler* c, CfreeCgTypeId i32_ty) { } cfree_cg_free(cg); - EXPECT(text_size((ObjBuilder*)ob) <= 128, + EXPECT(text_size(c, ob) <= 128, "literal folds should avoid arithmetic materialization, text size=%u", - text_size((ObjBuilder*)ob)); - obj_free((ObjBuilder*)ob); + text_size(c, ob)); + cfree_obj_builder_free(ob); } static uint32_t cg_emit_delayed_chain(CfreeCompiler* c, CfreeCgTypeId i32_ty, @@ -467,7 +534,7 @@ static uint32_t cg_emit_delayed_chain(CfreeCompiler* c, CfreeCgTypeId i32_ty, memset(&opts, 0, sizeof opts); opts.opt_level = 1; - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); + ob = new_obj(c); EXPECT(ob != NULL, "delayed chain obj builder allocation failed"); if (!ob) return 0; cg = NULL; @@ -475,7 +542,7 @@ static uint32_t cg_emit_delayed_chain(CfreeCompiler* c, CfreeCgTypeId i32_ty, if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "delayed chain cg allocation failed"); if (!cg) { - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); return 0; } @@ -515,8 +582,8 @@ static uint32_t cg_emit_delayed_chain(CfreeCompiler* c, CfreeCgTypeId i32_ty, cfree_cg_func_end(cg); cfree_cg_free(cg); - size = text_size((ObjBuilder*)ob); - obj_free((ObjBuilder*)ob); + size = text_size(c, ob); + cfree_obj_builder_free(ob); return size; } @@ -536,7 +603,7 @@ static uint32_t cg_emit_unary_chain(CfreeCompiler* c, CfreeCgTypeId i32_ty, memset(&opts, 0, sizeof opts); opts.opt_level = 1; - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); + ob = new_obj(c); EXPECT(ob != NULL, "unary chain obj builder allocation failed"); if (!ob) return 0; cg = NULL; @@ -544,7 +611,7 @@ static uint32_t cg_emit_unary_chain(CfreeCompiler* c, CfreeCgTypeId i32_ty, if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "unary chain cg allocation failed"); if (!cg) { - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); return 0; } @@ -582,8 +649,8 @@ static uint32_t cg_emit_unary_chain(CfreeCompiler* c, CfreeCgTypeId i32_ty, cfree_cg_func_end(cg); cfree_cg_free(cg); - size = text_size((ObjBuilder*)ob); - obj_free((ObjBuilder*)ob); + size = text_size(c, ob); + cfree_obj_builder_free(ob); return size; } @@ -602,7 +669,7 @@ static uint32_t cg_emit_local_shadow(CfreeCompiler* c, CfreeCgTypeId i32_ty, memset(&opts, 0, sizeof opts); opts.opt_level = 1; - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); + ob = new_obj(c); EXPECT(ob != NULL, "local shadow obj builder allocation failed"); if (!ob) return 0; cg = NULL; @@ -610,7 +677,7 @@ static uint32_t cg_emit_local_shadow(CfreeCompiler* c, CfreeCgTypeId i32_ty, if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "local shadow cg allocation failed"); if (!cg) { - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); return 0; } @@ -647,8 +714,8 @@ static uint32_t cg_emit_local_shadow(CfreeCompiler* c, CfreeCgTypeId i32_ty, cfree_cg_func_end(cg); cfree_cg_free(cg); - size = text_size((ObjBuilder*)ob); - obj_free((ObjBuilder*)ob); + size = text_size(c, ob); + cfree_obj_builder_free(ob); return size; } @@ -668,7 +735,7 @@ static uint32_t cg_emit_delayed_cmp(CfreeCompiler* c, CfreeCgTypeId i32_ty, memset(&opts, 0, sizeof opts); opts.opt_level = 1; - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); + ob = new_obj(c); EXPECT(ob != NULL, "delayed cmp obj builder allocation failed"); if (!ob) return 0; cg = NULL; @@ -676,7 +743,7 @@ static uint32_t cg_emit_delayed_cmp(CfreeCompiler* c, CfreeCgTypeId i32_ty, if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "delayed cmp cg allocation failed"); if (!cg) { - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); return 0; } @@ -718,8 +785,8 @@ static uint32_t cg_emit_delayed_cmp(CfreeCompiler* c, CfreeCgTypeId i32_ty, cfree_cg_func_end(cg); cfree_cg_free(cg); - size = text_size((ObjBuilder*)ob); - obj_free((ObjBuilder*)ob); + size = text_size(c, ob); + cfree_obj_builder_free(ob); return size; } @@ -740,7 +807,7 @@ static uint32_t cg_emit_delayed_store(CfreeCompiler* c, CfreeCgTypeId i32_ty, memset(&opts, 0, sizeof opts); opts.opt_level = 1; - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); + ob = new_obj(c); EXPECT(ob != NULL, "delayed store obj builder allocation failed"); if (!ob) return 0; cg = NULL; @@ -748,7 +815,7 @@ static uint32_t cg_emit_delayed_store(CfreeCompiler* c, CfreeCgTypeId i32_ty, if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "delayed store cg allocation failed"); if (!cg) { - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); return 0; } @@ -795,8 +862,8 @@ static uint32_t cg_emit_delayed_store(CfreeCompiler* c, CfreeCgTypeId i32_ty, cfree_cg_func_end(cg); cfree_cg_free(cg); - size = text_size((ObjBuilder*)ob); - obj_free((ObjBuilder*)ob); + size = text_size(c, ob); + cfree_obj_builder_free(ob); return size; } @@ -817,7 +884,7 @@ static uint32_t cg_emit_delayed_pressure(CfreeCompiler* c, CfreeCgTypeId i32_ty, memset(&opts, 0, sizeof opts); opts.opt_level = 1; - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); + ob = new_obj(c); EXPECT(ob != NULL, "delayed pressure obj builder allocation failed"); if (!ob) return 0; cg = NULL; @@ -825,7 +892,7 @@ static uint32_t cg_emit_delayed_pressure(CfreeCompiler* c, CfreeCgTypeId i32_ty, if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "delayed pressure cg allocation failed"); if (!cg) { - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); return 0; } @@ -875,8 +942,8 @@ static uint32_t cg_emit_delayed_pressure(CfreeCompiler* c, CfreeCgTypeId i32_ty, cfree_cg_func_end(cg); cfree_cg_free(cg); - size = text_size((ObjBuilder*)ob); - obj_free((ObjBuilder*)ob); + size = text_size(c, ob); + cfree_obj_builder_free(ob); return size; } @@ -905,7 +972,7 @@ static uint32_t cg_emit_local_shadow_boundary(CfreeCompiler* c, memset(&opts, 0, sizeof opts); opts.opt_level = 1; - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); + ob = new_obj(c); EXPECT(ob != NULL, "local shadow boundary obj builder allocation failed"); if (!ob) return 0; cg = NULL; @@ -913,7 +980,7 @@ static uint32_t cg_emit_local_shadow_boundary(CfreeCompiler* c, if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "local shadow boundary cg allocation failed"); if (!cg) { - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); return 0; } @@ -984,8 +1051,8 @@ static uint32_t cg_emit_local_shadow_boundary(CfreeCompiler* c, cfree_cg_func_end(cg); cfree_cg_free(cg); - size = text_size((ObjBuilder*)ob); - obj_free((ObjBuilder*)ob); + size = text_size(c, ob); + cfree_obj_builder_free(ob); return size; } @@ -1007,7 +1074,7 @@ static uint32_t cg_emit_local_shadow_partial_store(CfreeCompiler* c, memset(&opts, 0, sizeof opts); opts.opt_level = 1; - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); + ob = new_obj(c); EXPECT(ob != NULL, "partial shadow obj builder allocation failed"); if (!ob) return 0; cg = NULL; @@ -1015,7 +1082,7 @@ static uint32_t cg_emit_local_shadow_partial_store(CfreeCompiler* c, if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "partial shadow cg allocation failed"); if (!cg) { - obj_free((ObjBuilder*)ob); + cfree_obj_builder_free(ob); return 0; } @@ -1059,8 +1126,8 @@ static uint32_t cg_emit_local_shadow_partial_store(CfreeCompiler* c, cfree_cg_func_end(cg); cfree_cg_free(cg); - size = text_size((ObjBuilder*)ob); - obj_free((ObjBuilder*)ob); + size = text_size(c, ob); + cfree_obj_builder_free(ob); return size; } @@ -1144,14 +1211,17 @@ static CfreeCg* cg_begin_bad_store_func(CfreeCompiler* c, const char* name) { CfreeCgSym sym; memset(&opts, 0, sizeof opts); - ob = (CfreeObjBuilder*)obj_new((Compiler*)c); + ob = new_obj(c); EXPECT(ob != NULL, "bad-store obj builder allocation failed"); if (!ob) return NULL; cg = NULL; (void)cfree_cg_new(c, &cg); if (cg) (void)cfree_cg_begin_obj(cg, ob, &opts); EXPECT(cg != NULL, "bad-store cg allocation failed"); - if (!cg) return NULL; + if (!cg) { + cfree_obj_builder_free(ob); + return NULL; + } memset(&sig, 0, sizeof sig); sig.ret = cfree_cg_builtin_types(c).id[CFREE_CG_BUILTIN_VOID]; @@ -1262,9 +1332,9 @@ static void exercise_cg_begin_end_two_objects(CfreeCompiler* c) { CfreeCodeOptions opts; memset(&opts, 0, sizeof(opts)); - ob1 = (CfreeObjBuilder*)obj_new((Compiler*)c); - ob2 = (CfreeObjBuilder*)obj_new((Compiler*)c); - EXPECT(ob1 && ob2, "obj_new failed for cg begin/end session"); + ob1 = new_obj(c); + ob2 = new_obj(c); + EXPECT(ob1 && ob2, "obj builder allocation failed for cg begin/end session"); EXPECT(cfree_cg_new(c, &cg) == CFREE_OK && cg, "cg session new failed"); if (cg && ob1) { EXPECT(cfree_cg_begin_obj(cg, ob1, &opts) == CFREE_OK, diff --git a/test/test.mk b/test/test.mk @@ -26,7 +26,7 @@ # asm_parse / cfree_disasm_iter_* are still stubs; the harness builds # and runs end-to-end so the wiring stays exercised. See doc/ASM.md. -.PHONY: test test-driver test-pp test-pp-err test-elf test-coff test-coff-mingw-import test-coff-windows-ucrt test-ar test-ar-driver test-strip-driver test-objcopy-driver test-objdump-driver test-link test-cg-api test-toy test-opt test-dwarf test-debug test-parse test-parse-err test-asm test-wasm-front test-isa test-aa64-inline test-rv64-inline test-rv64-jit test-emu test-x64-inline test-x64-dbg test-rt-headers test-rt-runtime test-musl test-musl-rv64 test-glibc test-glibc-rv64 test-lib-deps test-smoke-x64 test-smoke-rv64 test-bounce test-cbackend rv64-doctor +.PHONY: test test-driver test-pp test-pp-err test-elf test-coff test-coff-mingw-import test-coff-windows-ucrt test-ar test-ar-driver test-strip-driver test-objcopy-driver test-objdump-driver test-link test-cg-api test-abi-classify test-toy test-opt test-dwarf test-debug test-parse test-parse-err test-asm test-wasm-front test-isa test-aa64-inline test-rv64-inline test-rv64-jit test-emu test-x64-inline test-x64-dbg test-rt-headers test-rt-runtime test-musl test-musl-rv64 test-glibc test-glibc-rv64 test-lib-deps test-smoke-x64 test-smoke-rv64 test-bounce test-cbackend rv64-doctor test: test-driver test-pp test-pp-err test-elf test-coff test-ar test-ar-driver test-strip-driver test-objcopy-driver test-objdump-driver test-link test-toy test-dwarf test-debug test-parse test-parse-err test-asm test-isa test-aa64-inline test-rv64-inline test-rv64-jit test-emu test-x64-inline test-x64-dbg test-rt-headers test-lib-deps # `test-cbackend` is intentionally not in the default `test` target: the @@ -144,22 +144,24 @@ CG_API_TEST_BIN = build/test/cg_api_test CG_SWITCH_TEST_BIN = build/test/cg_switch_test ABI_CLASSIFY_TEST_BIN = build/test/abi_classify_test -test-cg-api: $(CG_API_TEST_BIN) $(CG_SWITCH_TEST_BIN) $(ABI_CLASSIFY_TEST_BIN) +test-cg-api: $(CG_API_TEST_BIN) $(CG_SWITCH_TEST_BIN) $(CG_API_TEST_BIN) $(CG_SWITCH_TEST_BIN) + +test-abi-classify: $(ABI_CLASSIFY_TEST_BIN) $(ABI_CLASSIFY_TEST_BIN) $(CG_API_TEST_BIN): test/api/cg_type_test.c $(LIB_AR) @mkdir -p $(dir $@) - $(CC) $(TEST_HOST_CFLAGS) -Isrc test/api/cg_type_test.c $(LIB_AR) -o $@ + $(CC) $(TEST_HOST_CFLAGS) test/api/cg_type_test.c $(LIB_AR) -o $@ $(CG_SWITCH_TEST_BIN): test/api/cg_switch_test.c $(LIB_AR) @mkdir -p $(dir $@) - $(CC) $(TEST_HOST_CFLAGS) -Isrc test/api/cg_switch_test.c $(LIB_AR) -o $@ + $(CC) $(TEST_HOST_CFLAGS) test/api/cg_switch_test.c $(LIB_AR) -o $@ -$(ABI_CLASSIFY_TEST_BIN): test/api/abi_classify_test.c $(LIB_AR) +$(ABI_CLASSIFY_TEST_BIN): test/api/abi_classify_test.c $(LIB_OBJS) @mkdir -p $(dir $@) - $(CC) $(TEST_HOST_CFLAGS) -Isrc test/api/abi_classify_test.c $(LIB_AR) -o $@ + $(CC) $(TEST_HOST_CFLAGS) -Isrc test/api/abi_classify_test.c $(LIB_OBJS) -o $@ test-toy: bin @CFREE=$(abspath $(BIN)) test/toy/run.sh