test(backend): lock LLVM type/ABI shapes before A7.1 extraction (A7.1 scaffolding step 1)

Test-first scaffolding for LLVM backend modularization (Phase A7.1) before the
type/ABI helpers move into src/backend/llvm/{types,abi}.zig. Visibility-only
change to the targets — no behavior change. Closes the ARCH-SAFETY "no generic
ABI snapshot" gap.

- 2 new emit_llvm.test.zig tests:
  - abiCoerceParamType across every C-ABI size bucket: <=8 -> i64, 9-16 ->
    [2 x i64], >16 -> ptr, HFA (all-float/all-double, <=4 fields) -> unchanged,
    string -> ptr, slice -> ptr, scalar -> unchanged. Built via a local
    internStruct helper (field slice in the module arena -> no testing-allocator
    leak); asserts against emitter.cached_* + LLVMArrayType2.
  - needsByval: true only for >16-byte non-HFA struct; false for <=16 / HFA /
    string / slice / non-struct.
- 1 new .ir snapshot: 1202-ffi-cc-c-large-aggregate (the canonical callconv(.c)
  >16-byte byval example that directly documents abiCoerceParamType) — pins the
  byval param path end-to-end (5 byval + entry reload + 2 sret from Arena.init).
  Path-free + idempotent (verified across two captures). Suite count unchanged
  (snapshot added to an existing example).
- Widened abiCoerceParamType + needsByval to pub (visibility only;
  abiCoerceParamTypeEx/materializeByvalArg/verifySizes stay private — move with
  callers in sub-step 2). No logic touched.
- Recorded the A7.1 coverage inventory + residual gaps (wasm32 usize->i32 branch,
  fn-ptr large-aggregate 1203/1204) in ARCH-SAFETY.md.

Gate: zig build, zig build test, bash tests/run_examples.sh -> 361/0 (no churn
beyond the new 1202 .ir).
This commit is contained in:
agra
2026-06-03 08:53:51 +03:00
parent 91b300580b
commit d6078c2e6b
3 changed files with 261 additions and 2 deletions

View File

@@ -0,0 +1,182 @@
@__sx_default_context = internal global { { ptr, ptr, ptr }, ptr } { { ptr, ptr, ptr } { ptr null, ptr @__thunk_CAllocator_Allocator_alloc, ptr @__thunk_CAllocator_Allocator_dealloc }, ptr null }
; Function Attrs: nounwind
declare void @out(ptr) #0
declare ptr @malloc(i64)
declare void @free(ptr)
declare ptr @memcpy(ptr, ptr, i64)
declare ptr @memset(ptr, i32, i64)
; Function Attrs: nounwind
define internal ptr @CAllocator.alloc(ptr %0, ptr %1, i64 %2) #0 {
entry:
%alloca = alloca ptr, align 8
store ptr %1, ptr %alloca, align 8
%allocaN = alloca i64, align 8
store i64 %2, ptr %allocaN, align 8
%load = load i64, ptr %allocaN, align 8
%call = call ptr @malloc(i64 %load)
ret ptr %call
}
; Function Attrs: nounwind
define internal void @CAllocator.dealloc(ptr %0, ptr %1, ptr %2) #0 {
entry:
%alloca = alloca ptr, align 8
store ptr %1, ptr %alloca, align 8
%allocaN = alloca ptr, align 8
store ptr %2, ptr %allocaN, align 8
%load = load ptr, ptr %allocaN, align 8
call void @free(ptr %load)
ret void
}
; Function Attrs: nounwind
declare i64 @GPA.init(ptr) #0
; Function Attrs: nounwind
declare ptr @GPA.alloc(ptr, ptr, i64) #0
; Function Attrs: nounwind
declare void @GPA.dealloc(ptr, ptr, ptr) #0
; Function Attrs: nounwind
declare void @Arena.add_chunk(ptr, ptr, i64) #0
; Function Attrs: nounwind
declare void @Arena.init(ptr sret({ ptr, i64, { ptr, ptr, ptr } }), ptr, ptr, i64) #0
; Function Attrs: nounwind
declare void @Arena.reset(ptr, ptr) #0
; Function Attrs: nounwind
declare void @Arena.deinit(ptr, ptr) #0
; Function Attrs: nounwind
declare ptr @Arena.alloc(ptr, ptr, i64) #0
; Function Attrs: nounwind
declare void @Arena.dealloc(ptr, ptr, ptr) #0
; Function Attrs: nounwind
declare ptr @BufAlloc.init(ptr, ptr, i64) #0
; Function Attrs: nounwind
declare void @BufAlloc.reset(ptr, ptr) #0
; Function Attrs: nounwind
declare ptr @BufAlloc.alloc(ptr, ptr, i64) #0
; Function Attrs: nounwind
declare void @BufAlloc.dealloc(ptr, ptr, ptr) #0
; Function Attrs: nounwind
declare void @TrackingAllocator.init(ptr sret({ { ptr, ptr, ptr }, i64, i64, i64 }), ptr, ptr) #0
; Function Attrs: nounwind
declare i64 @TrackingAllocator.leak_count(ptr, ptr) #0
; Function Attrs: nounwind
declare void @TrackingAllocator.report(ptr, ptr) #0
; Function Attrs: nounwind
declare ptr @TrackingAllocator.alloc(ptr, ptr, i64) #0
; Function Attrs: nounwind
declare void @TrackingAllocator.dealloc(ptr, ptr, ptr) #0
; Function Attrs: nounwind
declare ptr @cstring(ptr, i64) #0
; Function Attrs: nounwind
declare ptr @int_to_string(ptr, i64) #0
; Function Attrs: nounwind
declare ptr @bool_to_string(ptr, i1) #0
; Function Attrs: nounwind
declare ptr @float_to_string(ptr, double) #0
; Function Attrs: nounwind
declare void @hex_group(ptr, ptr, i64, i64) #0
; Function Attrs: nounwind
declare ptr @int_to_hex_string(ptr, i64) #0
; Function Attrs: nounwind
declare ptr @concat(ptr, ptr, ptr) #0
; Function Attrs: nounwind
declare ptr @substr(ptr, ptr, i64, i64) #0
; Function Attrs: nounwind
declare ptr @xml_escape(ptr, ptr) #0
; Function Attrs: nounwind
declare ptr @path_join(ptr, ptr) #0
; Function Attrs: nounwind
declare ptr @any_to_string(ptr, [2 x i64]) #0
; Function Attrs: nounwind
declare ptr @build_format(ptr, ptr) #0
; Function Attrs: nounwind
define internal i64 @accept_c(ptr %0) #0 {
entry:
%byval.load = load { i64, i64, i64, i64 }, ptr %0, align 8
%alloca = alloca { i64, i64, i64, i64 }, align 8
store { i64, i64, i64, i64 } %byval.load, ptr %alloca, align 8
%load = load { i64, i64, i64, i64 }, ptr %alloca, align 8
%sg = extractvalue { i64, i64, i64, i64 } %load, 0
%loadN = load { i64, i64, i64, i64 }, ptr %alloca, align 8
%sgN = extractvalue { i64, i64, i64, i64 } %loadN, 1
%add = add i64 %sg, %sgN
%loadN = load { i64, i64, i64, i64 }, ptr %alloca, align 8
%sgN = extractvalue { i64, i64, i64, i64 } %loadN, 2
%addN = add i64 %add, %sgN
%loadN = load { i64, i64, i64, i64 }, ptr %alloca, align 8
%sgN = extractvalue { i64, i64, i64, i64 } %loadN, 3
%addN = add i64 %addN, %sgN
ret i64 %addN
}
; Function Attrs: nounwind
define i32 @main() #0 {
entry:
%alloca = alloca { i64, i64, i64, i64 }, align 8
store { i64, i64, i64, i64 } { i64 1, i64 10, i64 100, i64 1000 }, ptr %alloca, align 8
%load = load { i64, i64, i64, i64 }, ptr %alloca, align 8
%byval.tmp = alloca { i64, i64, i64, i64 }, align 8
store { i64, i64, i64, i64 } %load, ptr %byval.tmp, align 8
%call = call i64 @accept_c(ptr %byval.tmp)
%icmp = icmp ne i64 %call, 1111
br i1 %icmp, label %if.then.0, label %if.merge.1
if.then.0: ; preds = %entry
ret i32 1
if.merge.1: ; preds = %entry
ret i32 0
}
; Function Attrs: nounwind
define internal ptr @__thunk_CAllocator_Allocator_alloc(ptr %0, ptr %1, i64 %2) #0 {
entry:
%call = call ptr @CAllocator.alloc(ptr %0, ptr %1, i64 %2)
ret ptr %call
}
; Function Attrs: nounwind
define internal void @__thunk_CAllocator_Allocator_dealloc(ptr %0, ptr %1, ptr %2) #0 {
entry:
call void @CAllocator.dealloc(ptr %0, ptr %1, ptr %2)
ret void
}