Skip to content

gcc backend [via libgccjit] - #239

Open
SamuelMarks wants to merge 7 commits into
edgcpp:mainfrom
SamuelMarks:gcc_backend
Open

SamuelMarks wants to merge 7 commits into
edgcpp:mainfrom
SamuelMarks:gcc_backend

Conversation

@SamuelMarks

@SamuelMarks SamuelMarks commented Oct 7, 2026 •

Copy link
Copy Markdown

Native GCC (libgccjit) Code Generation Backend (BACK_END_IS_GCC_GEN_BE)

Executive Summary

This pull request introduces a complete, native GCC (libgccjit) code generation backend (gcc_gen_be / BACK_END_IS_GCC_GEN_BE=1) for the EDG C/C++ Front End (cpfe), enabling direct lowering of EDG Intermediate Language (IL) ASTs into GCC GIMPLE/RTL and native machine code artifacts (.s assembly, .o relocatable object files, shared libraries, and linked executables) without emitting intermediate C or C++ source files (c_gen_be / cp_gen_be).

Across 7 commits (106 files changed, 38,912 insertions(+), 512 deletions(-)), this branch delivers:

  1. Modular 16-Subsystem Backend Architecture (src/gcc_gen_be_*.[ch]): Decoupled subsystems for error handling, context/scope state machines, dynamic hash-map memoization, cross-platform libgccjit dynamic symbol loading, source locations, type lowering, declarations, expressions, statements/coroutines, Itanium C++ ABI RTTI/vtables/mangling, global/TLS destructors, DWARF debug metadata, 9-target ABI parameter/return classification & register coercion, compiler builtins/SIMD, multi-personality exception handling (DWARF LSDA, Windows SEH, ARM EHABI, SjLj), and multi-TU driver orchestration.
  2. Strict Error Percolation & noexcept Invariants: Universal [[nodiscard]] / __attribute__((warn_unused_result)) enforcement attached directly to enum gcc_gen_be_error (gcc_gen_be_error_t, 82 distinct error codes), GCC_GEN_BE_CHECK / GCC_GEN_BE_CHECK_CLEANUP percolation macros, out-parameter idioms, -Werror=unused-result, and GCC_GEN_BE_NOEXCEPT across every backend API.
  3. Production Runtime EH & RTTI Bridge (lib_src/gcc_be_eh_rt.c): Native runtime support for SjLj exception frame registration (__gcc_be_eh_chain, __gcc_be_eh_register_frame, __gcc_be_eh_unregister_frame) and Itanium C++ ABI _ZTI hierarchy matching (__cxa_type_match) across single (__si_class_type_info), multiple/virtual (__vmi_class_type_info), and pointer (__pointer_type_info) inheritance graphs with base subobject pointer adjustment.
  4. Full C & C++20/23 Language Lowering:
    • C++20 Coroutines: Frame layout synthesis, ramp allocation (get_return_object_on_allocation_failure), resume/destroy state-machine dispatchers, co_await/co_yield/co_return, symmetric transfer, std::noop_coroutine singleton, and Heap Allocation Elision Optimization (HALO).
    • Exception Handling: DWARF .gcc_except_table LSDA generation (ULEB128/SLEB128 call-site, action, and @TType tables), Windows x64/ARM64 .pdata/.xdata SEH (__try/__except/__finally), ARM EHABI (.ARM.extab/.ARM.exidx compact PR0 & generic PR1), partial array construction cleanups, constructor base/member subobject cleanups, noexcept termination filters, and dynamic exception specifications.
    • RTTI, Mangling & Virtual Dispatch: Complete Itanium C++ ABI mangler (_Z...) with substitution tables (S_, S0_, ...), vtable (_ZTV) and VTT (_ZTT) synthesis, virtual-base offset (vcall) and covariant return adjustment thunks, C1/C2 constructor and D1/D2/D0 deleting destructor clones, and cross-platform COMDAT/weak-ODR sections (ELF, Mach-O, COFF/PE).
    • Multi-Target Calling Conventions (9 ABIs): System V AMD64, AArch64 AAPCS64, Apple Darwin ARM64, Windows x64, RISC-V LP64D, System V i386, PowerPC64 ELFv2 (ppc64le), IBM s390x, and 32-bit ARM AAPCS32 — complete with cumulative GP/FP register pressure tracking, eightbyte/HFA/HVA register coercion, sret/invisible-reference lowering, and target-aware va_arg/va_list state machines.
    • Extended Numerics, Bitfields & SIMD: IEEE 754 decimal floating-point (_Decimal32/_Decimal64/_Decimal128 via libgcc BID helpers), ISO/IEC TR 18037 fixed-point (_Fract, _Accum, _Sat), extended floats (_Float16, __bf16, __float80, _Float128), 128-bit integers (__int128), bitfield container packing/extraction, and SIMD vector intrinsics (__builtin_shufflevector, __builtin_convertvector, C11 __atomic_*, overflow builtins).
  5. 100% Test & Doxygen Documentation Coverage (tests/gcc_be/, dev_tools/): 13 end-to-end compile-link-execute test suites (cpfe --gcc_gen_be), 24 isolated subsystem unit test executables, and automated verification scripts enforcing 100.00% function, line, branch, and Doxygen documentation coverage.

Commit-by-Commit Breakdown (All 7 Commits)

# Commit Summary Scale
1 cc0d088356 GCC [libgccjit] backend (initial pass) — Introduces cmake/FindLibGCCJIT.cmake, EDG_ENABLE_GCC_BACKEND, BACK_END_IS_GCC_GEN_BE in src/host_envir.h, initial monolithic src/gcc_gen_be.[ch], and initial tests/gcc_be/ harness. 11 files, +1,652 / -4
2 533a5b95ac Modularize GCC backend into dedicated subsystems and expand CLI options — Decomposes monolithic src/gcc_gen_be.[ch] into 10 focused compilation units (cache, context, decl, error, expr, lib_loader, location, main, stmt, type) and adds optimization/codegen CLI flags (-O0..-O3, -Os, -Ofast, -g, -fPIC, -fPIE, -fdump-*). 40 files, +3,588 / -1,466
3 516331dafa Enforce universal error codes, percolation, and noexcept across GCC backend — Attaches GCC_GEN_BE_NODISCARD directly to enum gcc_gen_be_error, introduces GCC_GEN_BE_NOEXCEPT, converts all backend functions (including gcc_gen_be() and back_end()) to return gcc_gen_be_error_t with out-parameters, and percolates all fallible operations via GCC_GEN_BE_CHECK(). 20 files, +320 / -222
4 8904394694 Implement subsystem unit tests, dynamic caching, and context stacks in GCC backend — Replaces fixed-size arrays with dynamically resizing control-flow/cleanup stacks in gcc_gen_be_context, converts be_cache_map to dynamically resizing hash tables with hit/miss metrics, bridges backend errors to EDG's f_error diagnostics, loads optional modern libgccjit symbols, and adds standalone subsystem unit test binaries. 28 files, +1,994 / -186
5 5f9218bc60 Implement ABI, builtins, RTTI, EH, and dtor subsystems in GCC backend — Adds 5 new subsystems (gcc_gen_be_abi, gcc_gen_be_builtin, gcc_gen_be_rtti, gcc_gen_be_eh, gcc_gen_be_dtor, gcc_gen_be_debug), implements lexical scope shadowing stacks, VLA stack save/restore, __cxa_atexit / __cxa_thread_atexit, vtable/VTT/thunk/RTTI emission, and adds dev_tools/check_gcc_be_doc_coverage.py & dev_tools/check_gcc_be_coverage.sh (removing legacy dev-init.py). 63 files, +3,298 / -1,050
6 cf7106287b Implement target ABI classification, CLI driver flags, and DWARF debug in GCC backend — Implements System V AMD64, AAPCS64, Darwin ARM64, and Win64 ABI classifiers, adds target/math/linker CLI flags (-march, -mcpu, -mtune, -mfpu, -mcmodel, -m32, -m64, -ffast-math, -shared, -static, -L, -l), implements multi-TU compilation and artifact emission, adds DWARF DIE emission, and expands EH/coroutine lowering. 67 files, +7,334 / -1,657
7 4a57745410 Complete GCC backend lowering for EH, coroutines, RTTI, multi-target ABI, and SIMD — Completes DWARF LSDA / Windows SEH / ARM EHABI unwind tables, adds lib_src/gcc_be_eh_rt.c runtime bridge, completes C++20 coroutine state-machine lowering (symmetric transfer, HALO, noop_coroutine), expands ABI classification to 9 targets with register pressure & coercion, adds full Itanium mangling with substitutions, C1/C2/D0/D1/D2 clones, COMDAT sections, IEEE 754 decimal floats, ISO fixed-point arithmetic, SIMD shuffle/convertvector, util/eccp.sh --gcc-be integration, CMakePresets.json, and 100% test/doc coverage. 98 files, +27,968 / -3,169

Subsystem Architecture & Technical Deep-Dive

1. Error Handling & Diagnostic Infrastructure (src/gcc_gen_be_error.[ch])

  • Non-Discardable Status Type: enum GCC_GEN_BE_NODISCARD gcc_gen_be_error (typedef enum gcc_gen_be_error gcc_gen_be_error_t) applies [[nodiscard]] (C++17+), __attribute__((warn_unused_result)) (GCC/Clang), or _Check_return_ (MSVC) directly on the enum type, combined with -Wunused-result -Werror=unused-result in CMake.
  • Comprehensive Error Taxonomy: Defines 82 specific error codes spanning memory allocation (GCC_GEN_BE_ERROR_OOM), dynamic loader failures (GCC_GEN_BE_ERROR_LIBGCCJIT_LOAD_FAILED, GCC_GEN_BE_ERROR_LIBGCCJIT_SYMBOL_MISSING), AST lowering errors, ABI classification/coercion failures (GCC_GEN_BE_ERROR_ABI_CLASSIFICATION_FAILED, GCC_GEN_BE_ERROR_COERCION_FAILED, GCC_GEN_BE_ERROR_VA_ARG_LOWERING_FAILED), mangling/RTTI/vtable failures, coroutine lowering errors (GCC_GEN_BE_ERROR_COROUTINE_FRAME_FAILED, GCC_GEN_BE_ERROR_CORO_TRANSFER_FAILED, GCC_GEN_BE_ERROR_CORO_HALO_FAILED), unwind/LSDA errors (GCC_GEN_BE_ERROR_LSDA_ENCODE_FAILED, GCC_GEN_BE_ERROR_EH_CFG_EDGE_FAILED), decimal/fixed-point errors, and DWARF metadata errors.
  • Percolation & Diagnostics:
    • GCC_GEN_BE_CHECK(expr) and GCC_GEN_BE_CHECK_CLEANUP(expr, err_var, cleanup_label) ensure zero silent failures or swallowed errors.
    • gcc_gen_be_error_string() maps every enum value to a deterministic diagnostic string via an out-parameter.
    • gcc_gen_be_report_diagnostic() bridges backend errors into EDG's native diagnostic stream (f_error) and error counters.

2. Context, Control-Flow Stacks & Lexical Scoping (src/gcc_gen_be_context.[ch])

  • Singleton Context State (gcc_gen_be_context_t): Encapsulates the active gcc_jit_context *, active basic block (gcc_jit_block *), thread ownership ID (gcc_gen_be_check_thread_safety()), and dynamically resizing stacks:
    • Loop & Switch control flow: break_stack, continue_stack, switch_exit_stack, block_stack.
    • Exception & RAII unwinding: landing_pad_stack, cleanup_stack (gcc_gen_be_push_cleanup, gcc_gen_be_execute_cleanups, gcc_gen_be_register_cleanup, gcc_gen_be_emit_cleanups), and active_seh_finally_stack (gcc_gen_be_seh_finally_entry_t).
    • Lexical scoping: scope_stack (gcc_gen_be_push_scope, gcc_gen_be_pop_scope) supporting nested variable shadowing and lifetime-bound RAII destructor invocation on block exit or early jump (return, break, continue, goto).
    • Reentrant Coroutine & EH state stacks: coro_state_stack (gcc_gen_be_coro_state_t) for nested/lambda coroutines and eh_state (gcc_gen_be_eh_state_t) for nested functions.
    • Computed goto state: computed_goto_dispatch_block, computed_goto_target_lval, and computed_goto_labels array for &&label and goto *expr.

3. Dynamic Hash-Map Memoization (src/gcc_gen_be_cache.[ch])

  • 8 Domain Caches (gcc_gen_be_cache_type_t):
    • GCC_GEN_BE_CACHE_TYPE: Memoizes a_type_ptr → gcc_jit_type * (essential for breaking cyclic struct/class pointer graphs).
    • GCC_GEN_BE_CACHE_VAR: Memoizes a_variable_ptr → gcc_jit_lvalue *.
    • GCC_GEN_BE_CACHE_FUNC: Memoizes a_routine_ptr → gcc_jit_function *.
    • GCC_GEN_BE_CACHE_LABEL: Memoizes a_label_ptr → gcc_jit_block *.
    • GCC_GEN_BE_CACHE_FIELD: Memoizes a_field_ptr → gcc_jit_field *.
    • GCC_GEN_BE_CACHE_SWITCH_CASE: Memoizes a_switch_case_entry_ptr → gcc_jit_block *.
    • GCC_GEN_BE_CACHE_GUARD: Memoizes local static initialization guard variables (_ZGV...).
    • GCC_GEN_BE_CACHE_STRING: Interns string literals and named runtime symbols.
  • Dynamic Rehashing & Telemetry: be_cache_map automatically doubles bucket capacity when load factor thresholds are exceeded and tracks lookup telemetry (hits, misses) queryable via cache_get_metrics().

4. Cross-Platform libgccjit Dynamic Loader (src/gcc_gen_be_lib_loader.[ch])

  • Platform Support: Uses dlopen/dlsym (RTLD_DEFAULT fallback) on POSIX (Linux, macOS, FreeBSD) and LoadLibraryA/GetProcAddress (with /DELAYLOAD:libgccjit.dll on MSVC) on Windows (load_libgccjit_posix, load_libgccjit_windows).
  • Runtime Capability Probing: Dynamically resolves optional and modern libgccjit symbols while providing graceful lowering fallbacks when running against older libgccjit releases (GCC 10–16+):
    • Constructors & Bitcasts: gcc_jit_context_new_struct_constructor, gcc_jit_context_new_array_constructor, gcc_jit_context_new_union_constructor, gcc_jit_context_new_bitcast.
    • SIMD Vectors: gcc_jit_type_get_vector, gcc_jit_context_new_rvalue_from_vector, gcc_jit_context_new_rvalue_vector_perm, gcc_jit_context_new_convert_vector.
    • Attributes & Linkage: gcc_jit_function_add_attribute, gcc_jit_function_add_string_attribute, gcc_jit_lvalue_add_string_attribute, gcc_jit_lvalue_set_link_section, gcc_jit_lvalue_set_tls_model, gcc_jit_lvalue_set_alignment, gcc_jit_lvalue_set_register_name, gcc_jit_rvalue_set_bool_require_tail_call.
    • Native GIMPLE EH & Inline Asm Extensions: gcc_jit_block_end_with_invoke, gcc_jit_block_add_try_catch, gcc_jit_block_add_cleanup, gcc_jit_block_end_with_resx, gcc_jit_function_set_personality, gcc_jit_block_add_landing_pad, gcc_jit_context_new_eh_filter, gcc_jit_block_end_with_extended_asm_goto, gcc_jit_context_add_top_level_asm.
    • Capability Probes: gcc_gen_be_probe_eh_builtins(), gcc_gen_be_probe_native_eh_support(), gcc_gen_be_resolve_eh_entrypoints(), and gcc_gen_be_probe_extended_float_types().

5. Multi-Target ABI Classification & Register Coercion (src/gcc_gen_be_abi.[ch])

  • 9 Supported Target ABIs (gcc_gen_be_target_abi_t):
    1. System V AMD64 (GCC_GEN_BE_TARGET_ABI_SYSV_AMD64): Recursive eightbyte classification (gcc_gen_be_classify_sysv_amd64) across INTEGER, SSE, SSEUP, X87, X87UP, COMPLEX_X87, NO_CLASS, and MEMORY with post-merger cleanup.
    2. ARM64 AAPCS64 (GCC_GEN_BE_TARGET_ABI_AAPCS64): Homogeneous Floating-Point Aggregate (HFA) and Homogeneous Short-Vector Aggregate (HVA) detection (gcc_gen_be_classify_aapcs64, up to 4 elements), composite ≤ 16-byte register pair coercion, and indirect x8 result location semantics.
    3. Apple Darwin ARM64 (GCC_GEN_BE_TARGET_ABI_DARWIN_ARM64): Darwin-specific variadic argument stack demotion and sub-word packing (gcc_gen_be_classify_darwin_arm64).
    4. Windows x64 (GCC_GEN_BE_TARGET_ABI_WIN64): Power-of-two size checks (1, 2, 4, 8 bytes in registers; > 8 bytes or non-power-of-two by hidden reference via gcc_gen_be_classify_win64).
    5. RISC-V LP64D (GCC_GEN_BE_TARGET_ABI_RISCV64_LP64D): Hardware FP register (fa0–fa7) flattenings (fp, fp+fp, fp+gp, gp+fp) vs GP register pairs (a0–a7, ≤ 2 × XLEN = 16 bytes) via gcc_gen_be_classify_riscv64 and gcc_gen_be_coerced_riscv64_type.
    6. System V i386 (GCC_GEN_BE_TARGET_ABI_SYSV_I386): Hidden sret stack pointer classification (gcc_gen_be_classify_i386).
    7. PowerPC64 ELFv2 (GCC_GEN_BE_TARGET_ABI_PPC64LE_ELFV2): 8-element HFA/HVA classification and > 16-byte non-HFA r3 sret buffer detection (gcc_gen_be_classify_ppc64le, gcc_gen_be_coerced_ppc64le_type).
    8. IBM z/Architecture (GCC_GEN_BE_TARGET_ABI_S390X): Single-field FP struct register classification and > 8-byte / non-power-of-two hidden reference detection (gcc_gen_be_classify_s390x).
    9. 32-bit ARM AAPCS / AAPCS-VFP (GCC_GEN_BE_TARGET_ABI_AAPCS32): ≤ 4-byte r0 return vs > 4-byte sret and 8-byte aligned even-odd register pair (r0:r1, r2:r3) tracking (gcc_gen_be_classify_aapcs32).
  • Cumulative Register Pressure & Coercion:
    • gcc_gen_be_init_abi_reg_state() and gcc_gen_be_allocate_abi_param_regs() track gp_used/gp_limit and fp_used/fp_limit across function signatures and call sites, demoting arguments to stack memory when hardware registers are exhausted.
    • gcc_gen_be_is_passed_by_invisible_reference() and gcc_gen_be_is_returned_via_sret() detect C++ non-trivially copyable classes (user copy/move ctors or non-trivial dtors).
    • Prologue/call-site/return packing and unpacking: gcc_gen_be_pack_coerced_argument(), gcc_gen_be_unpack_coerced_parameter(), gcc_gen_be_pack_coerced_return(), and gcc_gen_be_unpack_coerced_return().
    • Target-aware va_arg state machine (gcc_gen_be_classify_va_arg()): Computes GP/FP save-area register counts and stack overflow placement.

6. Exception Handling, Unwinding & Runtime Bridge (src/gcc_gen_be_eh.[ch], lib_src/gcc_be_eh_rt.c)

  • Multi-Architecture Unwind Table Synthesis:
    • DWARF .gcc_except_table (LSDA): gcc_gen_be_encode_uleb128(), gcc_gen_be_encode_sleb128(), gcc_gen_be_format_lsda_asm_directives(), gcc_gen_be_chain_cleanup_action(), and gcc_gen_be_emit_lsda_call_site_table() generate @LPStart, @TType, call-site records, and chained SLEB128 action records (filter > 0 for typed catch, filter == 0 for RAII cleanups, filter < 0 for exception specifications).
    • Windows x64 / ARM64 SEH (.pdata / .xdata): gcc_gen_be_emit_seh_unwind_tables() synthesizes UNWIND_INFO (UNW_FLAG_EHANDLER / UNW_FLAG_UHANDLER), __C_specific_handler scope records, and RUNTIME_FUNCTION descriptors.
    • ARM 32-bit EHABI (.ARM.extab / .ARM.exidx): gcc_gen_be_emit_arm_ehabi_tables() emits compact model PR0 (0x80b0b0b0, __aeabi_unwind_cpp_pr0) and generic model PR1 (0x8101b0b0, __aeabi_unwind_cpp_pr1) unwind descriptors.
  • Abnormal Unwind CFG Edges & Landing Pads:
    • gcc_gen_be_emit_invoke_call() and gcc_gen_be_emit_invoke_call_through_ptr() emit direct and indirect (vtable/function-pointer) calls with abnormal unwind edges branching to active landing pads (landing_pad_stack).
    • gcc_gen_be_emit_selector_filter_dispatch() dispatches landing pad selectors against LSDA filter indices.
    • gcc_gen_be_emit_partial_array_cleanup() synthesizes reverse-index destruction loops (i - 1 .. 0) when an element constructor throws mid-new[] or mid-aggregate initialization.
    • gcc_gen_be_emit_subobject_unwind_cleanup() destroys already-constructed base classes and member subobjects if a delegating or complete constructor throws.
    • gcc_gen_be_enforce_exception_spec() and gcc_gen_be_emit_noexcept_filter() enforce C++11 noexcept(true) (_ZSt9terminatev) and legacy dynamic throw(T1, T2) (__cxa_call_unexpected) specifications.
  • Runtime Library Bridge (lib_src/gcc_be_eh_rt.c):
    • Compiled into the EDG runtime (lib_src/CMakeLists.txt) to provide __gcc_be_eh_chain, __gcc_be_eh_register_frame, __gcc_be_eh_unregister_frame, __gcc_be_eh_check_unwind_state, and __cxa_type_match with full recursive base-class traversal and this-pointer offset adjustment across single, multiple, and virtual inheritance hierarchies.

7. C++20 Coroutines, Control Flow & Statements (src/gcc_gen_be_stmt.[ch], src/gcc_gen_be_expr.[ch])

  • C++20 Coroutine Lowering:
    • Frame Layout: gcc_gen_be_compute_coro_frame_layout() and gcc_gen_be_compute_coro_frame_size_and_align() construct the per-coroutine frame struct (__resume_fn at offset 0, __destroy_fn at offset sizeof(void *), __promise, __suspend_index, __coro_flags, copied parameters, and spilled cross-suspension local variables/temporaries).
    • Ramp Function: gcc_gen_be_lower_coroutine_ramp() lowers frame allocation (operator new or promise-specific allocator), get_return_object_on_allocation_failure() on noexcept allocation failure, parameter copying, promise construction, get_return_object(), and initial suspend execution.
    • Actor/Resume & Destroy State Machines: gcc_gen_be_lower_coroutine_dispatchers() synthesizes the state-machine switch over registered suspension points (1..N), handling normal resumption, destruction at suspended states, and frame deallocation (operator delete).
    • co_await, co_yield, and Symmetric Transfer: gcc_gen_be_lower_await_yield(), gcc_gen_be_register_coro_suspend_point(), and gcc_gen_be_emit_coro_symmetric_transfer() lower await_ready(), state saving, await_suspend() (handling void, bool, and symmetric transfer std::coroutine_handle<T> with fallback to __gcc_be_noop_coro_frame from gcc_gen_be_get_noop_coroutine_frame()), and await_resume().
    • HALO: gcc_gen_be_try_coro_halo() evaluates non-escaping coroutine descriptors for Heap Allocation Elision Optimization.
  • Statement & Control-Flow Lowering:
    • Full support for if/else, while, do-while, for, switch (including GNU case ranges case low ... high: and GCC_GEN_BE_CACHE_SWITCH_CASE deduplication), goto, computed goto *ptr (gcc_gen_be_finalize_computed_goto), GNU statement expressions ({ ... }), Microsoft SEH __try/__except/__finally (gcc_gen_be_lower_microsoft_try), and VLA stack allocation/restoration (gcc_gen_be_lower_vla_decl, gcc_gen_be_emit_stack_save, gcc_gen_be_emit_stack_restore).
    • Extended Inline Assembly: gcc_gen_be_normalize_asm_constraints() normalizes read-modify-write (+r, +m, +x, +&r) constraints into = output constraints paired with tied numeric input constraints ("0", "1", ...), and supports asm goto via p_gcc_jit_block_end_with_extended_asm_goto.

8. Itanium C++ ABI RTTI, Mangling, VTables & Clones (src/gcc_gen_be_rtti.[ch], src/gcc_gen_be_decl.[ch], src/gcc_gen_be_dtor.[ch])

  • Itanium C++ ABI Name Mangler:
    • gcc_gen_be_mangle_type_name(), gcc_gen_be_mangle_with_substitutions(), gcc_gen_be_mangle_function_name(), and gcc_gen_be_mangle_expr() implement _Z encoding for builtin types, CV-qualifiers, pointers, references, rvalue references, arrays, functions, nested scopes (N...E), template argument lists (I...E), dependent expressions (st, sz, at, nx, DT...E), special member variants (C1, C2, D0, D1, D2), overloaded operators (nw, na, dl, da, cl, ix, eq, lt, ss, etc.), and compressed substitution tables (S_, S0_, S1_, ...).
  • VTables, VTTs & Thunks:
    • gcc_gen_be_emit_vtable() synthesizes _ZTV globals containing virtual base/call offsets, offset-to-top (-offset), _ZTI RTTI pointer, and virtual function pointers (mapping pure virtuals to __cxa_pure_virtual).
    • gcc_gen_be_emit_vtt() synthesizes _ZTT Virtual Table Tables for diamond and virtual-inheritance hierarchies.
    • gcc_gen_be_emit_thunk(), gcc_gen_be_emit_vcall_thunk() (_ZTv0_n...), and gcc_gen_be_emit_covariant_return_thunk() (_ZTch... / _ZTcv...) adjust this and return pointers across multiple and virtual inheritance lattices.
  • RTTI Descriptors, dynamic_cast & typeid:
    • gcc_gen_be_emit_type_descriptor() emits _ZTS type strings and _ZTI descriptors (__fundamental_type_info, __class_type_info, __si_class_type_info, __vmi_class_type_info with __base_class_type_info flags, and __pointer_type_info).
    • gcc_gen_be_lower_dynamic_cast() lowers runtime downcasts/crosscasts to __dynamic_cast and reference casts to __cxa_bad_cast on failure.
    • gcc_gen_be_lower_typeid() lowers typeid(T) and polymorphic typeid(*ptr) (loading vptr[-1] with null check calling __cxa_bad_typeid).
  • Constructor/Destructor Clones & COMDAT Linkage:
    • gcc_gen_be_emit_ctor_dtor_clones() synthesizes complete (C1/D1), base (C2/D2), and deleting (D0, invoking D1 then _ZdlPv) clones.
    • gcc_gen_be_format_comdat_section_name() and gcc_gen_be_apply_comdat_linkage() emit platform-native vague linkage across ELF (.gnu.linkonce.{t,r,d}.* + weak), Mach-O (__TEXT,__textcoal_nt / __DATA,__const_coal + weak_definition), and COFF/PE (.text$mn / .rdata$r + selectany).
    • gcc_gen_be_emit_cxa_atexit(), gcc_gen_be_emit_cxa_thread_atexit(), and gcc_gen_be_get_dso_handle() register global and thread_local destructors against &__dso_handle.

9. Types, Extended Numerics, Bitfields & Builtins (src/gcc_gen_be_type.[ch], src/gcc_gen_be_expr.[ch], src/gcc_gen_be_builtin.[ch])

  • Type & Constant Lowering:
    • Lowers all standard C/C++ scalar types, bool, scoped/unscoped enums, pointers, pointers-to-data-members (ptrdiff_t offset), pointers-to-member-functions ({ fn_ptr_or_vtable_offset, this_adj } struct), arrays, VLAs, structs, classes, unions, bitfields, _Complex types, and SIMD vector types (__attribute__((vector_size(N)))).
    • gcc_gen_be_lower_float_constant() preserves full significand/exponent precision for _Float16, __bf16, long double, __float80, and _Float128.
    • gcc_gen_be_pack_bitfield_constants() packs adjacent bitfields sharing a storage unit into a single container word for static initializers, and expression lowering synthesizes mask-and-shift bitfield reads/writes when required.
  • IEEE 754 Decimal Floating-Point & ISO Fixed-Point:
    • gcc_gen_be_lower_decimal_float_type(), gcc_gen_be_lower_decimal_float_binary_op(), gcc_gen_be_lower_decimal_float_comparison(), gcc_gen_be_lower_decimal_float_cast(), gcc_gen_be_lower_decimal_to_binary_float(), gcc_gen_be_lower_binary_float_to_decimal(), gcc_gen_be_lower_decimal_to_int(), gcc_gen_be_lower_int_to_decimal(), and gcc_gen_be_lower_decimal_float_unary_op() lower _Decimal32, _Decimal64, and _Decimal128 operations to libgcc BID runtime helpers (__bid_addsd3, __bid_mulsd3, __bid_eqdd2, __bid_extendsddd2, etc.).
    • gcc_gen_be_lower_fixed_point_op() and gcc_gen_be_lower_fixed_point_binary_op() lower ISO/IEC TR 18037 _Fract and _Accum scaled arithmetic with optional _Sat saturation clamping.
  • Builtins, Atomics & SIMD:
    • gcc_gen_be_lower_builtin_call() lowers math, string/memory (__builtin_memcpy, __builtin_memset, __builtin_memcmp), bit-manipulation (__builtin_clz, __builtin_ctz, __builtin_popcount, __builtin_bswap*), overflow (__builtin_add_overflow, __builtin_sub_overflow, __builtin_mul_overflow), and C11 __atomic_* / __sync_* intrinsics.
    • gcc_gen_be_lower_builtin_bit_cast() lowers C++20 __builtin_bit_cast.
    • gcc_gen_be_lower_builtin_clear_padding() zeroes inter-field and tail padding bytes for atomic compare-exchange semantics.
    • gcc_gen_be_eval_builtin_object_size() evaluates __builtin_object_size / __builtin_dynamic_object_size bounds (modes 0..3).
    • gcc_gen_be_lower_vector_shuffle(), gcc_gen_be_lower_convertvector(), and gcc_gen_be_validate_simd_immediate() lower SIMD vector permutations, conversions, and immediate-operand validation.

10. DWARF Debug Metadata (src/gcc_gen_be_debug.[ch], src/gcc_gen_be_location.[ch])

  • DWARF Version & Verbosity Configuration: gcc_gen_be_set_dwarf_config(), gcc_gen_be_get_dwarf_config(), and gcc_gen_be_emit_dwarf_info() configure DWARF v2–v5 (-gdwarf-2..-gdwarf-5) and debug verbosity levels (-g0..-g3, -fdebug-macro, -fno-eliminate-unused-debug-types).
  • Debug Info Entities: Emits source locations and DWARF metadata for compile units (gcc_gen_be_emit_compile_unit_debug_info), subprograms (gcc_gen_be_emit_subprogram_debug_info), types (gcc_gen_be_emit_type_debug_info), variables (gcc_gen_be_emit_variable_debug_info), lexical scopes (gcc_gen_be_emit_lexical_block_scope), inlined subroutines (gcc_gen_be_emit_inlined_subroutine), namespaces (gcc_gen_be_emit_namespace_debug_info), class inheritance (gcc_gen_be_emit_class_inheritance_debug_info), template parameters (gcc_gen_be_emit_template_param_debug_info), and enumerations (gcc_gen_be_emit_enum_debug_info).

11. Driver, CLI, Frontend Integration & Build System (src/gcc_gen_be_main.[ch], src/cfe.c, src/cmd_line.[ch], util/eccp.sh)

  • EDG Frontend & IL Integration:
    • Enables BACK_END_IS_GCC_GEN_BE across src/defines.h, src/host_envir.h, src/targ_def.h, src/il.h, src/il_def.h, src/il_alloc.[ch], src/il_to_str.[ch], src/inline.c, src/layout.c, and src/cfe.c.
    • Preserves #pragma pack alignment in IL pragma entries and bit_field_alignment_type on bitfield descriptors when BACK_END_IS_GCC_GEN_BE is active.
  • CLI Flags & Multi-TU Pipeline:
    • Adds --gcc_gen_be (--gcc-be / --gcc_be in util/eccp.sh), -c, -S, -O0..-O3, -Os, -Ofast, -g, -fPIC, -fPIE, -fno-pie, -ffast-math, -fno-trapping-math, -fassociative-math, -shared, -static, -march=, -mcpu=, -mtune=, -mfpu=, -mcmodel=, -m64, -m32, -L, -l, -fdump-tree-all, -fdump-tree-gimple, and -fdump-rtl-all.
    • gcc_gen_be_compile_multi_tu(), gcc_gen_be_link_multi_tu_artifacts(), gcc_gen_be_link_multi_tu_objects(), gcc_gen_be_emit_artifact(), and gcc_gen_be_emit_module_initializer() (_ZGIW<module>) orchestrate per-TU context isolation, C++20 module initializer emission, and final binary linking.
  • CMake & Packaging:
    • Adds cmake/FindLibGCCJIT.cmake with compile-time feature detection (LIBGCCJIT_HAVE_*), EDG_ENABLE_GCC_BACKEND option, CPack DEB/RPM/TGZ/DragNDrop/WIX packaging rules, and 4 new presets in CMakePresets.json (macos-arm-gcc-be-debug, macos-arm-gcc-be-release, linux-gcc-be-debug, linux-gcc-be-release).

Testing & Verification (tests/gcc_be/, dev_tools/)

Test Suite Matrix

  1. End-to-End Compilation, Linking & Execution Tests (13 Suites × 3 Stages = 39 CTest Targets):
    • test_scalars.c, test_types.c, test_expr_ops.c, test_short_circuit.c, test_control_flow.c, test_functions.c, test_aggregates.c, test_inline_asm.c, test_edge_cases.c, test_cpp_classes.cpp, test_virtual.cpp, test_eh.cpp, test_dynamic_init.cpp.
    • Each suite is compiled via cpfe --gcc_gen_be -c -o <test>.o, linked into a native executable (with gcc_be_eh_rt), and executed under CTest.
  2. Isolated Subsystem Unit Test Executables (24 CTest Targets):
    • test_error, test_gcc_be_error, test_gcc_be_errors, test_gcc_be_context, test_gcc_be_lib_loader, test_gcc_be_loader, test_gcc_be_cache, test_gcc_be_type, test_gcc_be_rtti, test_gcc_be_rtti_full, test_gcc_be_builtin, test_gcc_be_simd, test_gcc_be_decl, test_gcc_be_expr, test_gcc_be_abi, test_gcc_be_abi_targets, test_gcc_be_bitfields, test_gcc_be_debug, test_gcc_be_debug_dwarf, test_gcc_be_dtor, test_gcc_be_stmt, test_gcc_be_stmt2, test_gcc_be_coroutines, test_gcc_be_eh, test_gcc_be_eh_dwarf, test_gcc_be_main, test_gcc_be_driver, test_gcc_be_location, test_gcc_be_regression.
  3. Automated Coverage Gates:
    • tests/gcc_be/check_coverage.py & dev_tools/check_gcc_be_coverage.sh: Verifies 100.00% function, line, and branch coverage across all src/gcc_gen_be_*.c and tests/gcc_be/test_*.{c,cpp} units.
    • dev_tools/check_gcc_be_doc_coverage.py: Runs Doxygen XML extraction and verifies 100.00% documentation coverage (@file, @brief, @details, @param, @return) across all backend headers, implementation files, runtime files, and test suites.

How to Build & Run Tests

# Configure and build with the GCC backend preset (macOS ARM or Linux)
cmake --preset macos-arm-gcc-be-debug
cmake --build build/gcc-be-debug --parallel

# Run all unit, end-to-end, code coverage, and Doxygen coverage tests
ctest --test-dir build/gcc-be-debug --output-on-failure

# Verify 100% Doxygen documentation and test coverage directly
python3 dev_tools/check_gcc_be_doc_coverage.py
./dev_tools/check_gcc_be_coverage.sh

Decompose monolithic gcc_gen_be.c and gcc_gen_be.h into modular,
decoupled backend subsystems to improve maintainability, testability,
and separation of concerns:
- gcc_gen_be_cache: hash map memoization for types, variables, functions,
  and fields.
- gcc_gen_be_context: context lifecycle, option configuration, and active
  basic block tracking.
- gcc_gen_be_decl: declaration lowering for globals, local variables, and
  parameters.
- gcc_gen_be_error: centralized backend error handling and diagnostics.
- gcc_gen_be_expr: expression lowering for operators, calls, and accessors.
- gcc_gen_be_lib_loader: cross-platform dynamic loader for libgccjit.
- gcc_gen_be_location: mapping frontend source locations to JIT locations.
- gcc_gen_be_main: driver entry points and compilation invocation.
- gcc_gen_be_stmt: statement and CFG control-flow lowering.
- gcc_gen_be_type: type system lowering across scalar, aggregate, pointer,
  and function types.

Additionally:
- Support GCC backend CLI optimization and debug flags in cmd_line.[ch]
  (-O0..-O3, -Os, -Ofast, -g, -fPIC, -fPIE, dump flags).
- Update src/CMakeLists.txt for the new modular sources and coverage flags.
- Expand tests/gcc_be/ suite and modernize coverage verification script
  to inspect all gcc_gen_be_*.c compilation units.
@wchilders-nvidia

Copy link
Copy Markdown
Collaborator

Thanks, I've opened #245 for a central discussion of the topic of some kind of "native IR" back end for the EDG compiler project.

…ackend

Enforce strict error handling invariants, non-discardable return codes,
and noexcept specification across all GCC backend (gcc_gen_be) subsystems:

- Error infrastructure (gcc_gen_be_error.[ch]):
  - Attach GCC_GEN_BE_NODISCARD directly to typedef enum gcc_gen_be_error_t
    to ensure compiler-enforced return value checks across all backend APIs.
  - Introduce GCC_GEN_BE_NOEXCEPT macro and add GCC_GEN_BE_ERROR_COMPILATION_FAILED.
  - Refactor gcc_gen_be_error_string() to take an out-parameter and return
    gcc_gen_be_error_t.

- Universal error code returns and pointer out-parameters:
  - Update context getters/setters (gcc_gen_be_get_state, gcc_gen_be_get_context,
    gcc_gen_be_set_context, gcc_gen_be_get_current_block, gcc_gen_be_set_current_block).
  - Update helper constructors such as gcc_gen_be_get_global_ctor_block().
  - Convert driver entry points gcc_gen_be() and back_end() to return
    gcc_gen_be_error_t.

- Strict error propagation:
  - Percolate all internal fallible operations (cache lookups/inserts/clears,
    type and expression lowering, location queries, memory allocations) via
    GCC_GEN_BE_CHECK().
  - Eliminate ignored return values, unhandled fallback paths, and silent errors.

- Universal noexcept annotation:
  - Decorate all backend function declarations and definitions across
    gcc_gen_be_cache, gcc_gen_be_context, gcc_gen_be_decl, gcc_gen_be_error,
    gcc_gen_be_expr, gcc_gen_be_lib_loader, gcc_gen_be_location,
    gcc_gen_be_main, gcc_gen_be_stmt, and gcc_gen_be_type with GCC_GEN_BE_NOEXCEPT.
@SamuelMarks
SamuelMarks marked this pull request as ready for review October 9, 2026 14:50
…n GCC backend

Expand the native libgccjit backend (gcc_gen_be) with dynamic memory management,
subsystem diagnostics, modern libgccjit symbol loading, and a modular unit test suite:

- Context and Control-Flow Stacks (gcc_gen_be_context.[ch]):
  - Replace static stack arrays with dynamically resizing stacks for break, continue,
    switch exit, nested blocks, and RAII cleanup handlers.
  - Introduce gcc_gen_be_push_block() / gcc_gen_be_pop_block() for nested scope tracking.
  - Add thread-ownership verification via gcc_gen_be_check_thread_safety().

- Cache Resizing and Metrics (gcc_gen_be_cache.[ch]):
  - Convert fixed-size hash buckets in be_cache_map to dynamically resizing tables.
  - Track cache lookup metrics (hits, misses) retrievable via cache_get_metrics().
  - Add GCC_GEN_BE_CACHE_SWITCH_CASE for jump target deduplication.

- Diagnostic Integration and Extended Errors (gcc_gen_be_error.[ch]):
  - Introduce gcc_gen_be_report_diagnostic() bridging backend errors with EDG's
    diagnostic counters and f_error.
  - Add detailed error codes for EH, unresolved symbols, vtables, RTTI, asm constraints,
    and DWARF emissions.

- Declarations and Expressions (gcc_gen_be_decl.[ch], gcc_gen_be_expr.[ch]):
  - Separate global vs local variable lowering (gcc_gen_be_lower_global_variable_decl
    and gcc_gen_be_lower_local_variable_decl).
  - Add gcc_gen_be_lower_constant_rvalue() with aggregate initializer lowering.

- Dynamic Symbol Loader (gcc_gen_be_lib_loader.[ch]):
  - Dynamically load optional modern libgccjit symbols (TLS models, vector types,
    extended asm goto, function/variable attributes, struct/array constructors).

- Namespaces and Header Structuring:
  - Standardize C++ namespaces (BEGIN_EDG_NAMESPACE / END_EDG_NAMESPACE) across
    backend headers.

- Modular Unit Test Suite (tests/gcc_be/):
  - Add standalone unit test suites for all backend subsystems: test_gcc_be_cache,
    test_gcc_be_context, test_gcc_be_decl, test_gcc_be_errors, test_gcc_be_expr,
    test_gcc_be_lib_loader, test_gcc_be_stmt, and test_gcc_be_type.
  - Update tests/gcc_be/CMakeLists.txt to build and register subsystem tests.

- Tracking and Documentation:
  - Add TODO_PLAN.md documenting architecture, test coverage mandates, and roadmap.
Expand the native libgccjit backend (gcc_gen_be) with comprehensive language
feature lowering, runtime support, lexical scoping, and subsystem test coverage:

- ABI, Calling Conventions, and Attributes (src/gcc_gen_be_abi.[ch]):
  - Implement gcc_gen_be_apply_function_attributes, gcc_gen_be_apply_struct_attributes,
    and gcc_gen_be_apply_variable_attributes for packing, alignment, TLS, and linkage.

- Builtins and Intrinsics (src/gcc_gen_be_builtin.[ch]):
  - Add gcc_gen_be_lower_builtin_call using libgccjit builtin function lookup.

- RTTI, VTables, and Thunks (src/gcc_gen_be_rtti.[ch]):
  - Add vtable and VTT emission (gcc_gen_be_emit_vtable, gcc_gen_be_emit_vtt).
  - Generate virtual method dispatch thunks (gcc_gen_be_emit_thunk).
  - Implement dynamic_cast and typeid lowering with type_info descriptor emission.

- Exception Handling and RAII Destructors (src/gcc_gen_be_eh.[ch], src/gcc_gen_be_dtor.[ch]):
  - Declare standard EH symbols (__cxa_throw, etc.) and lower throw expressions.
  - Implement __cxa_atexit and __cxa_thread_atexit registration for global and TLS destructors.

- Lexical Scopes and Control Flow (src/gcc_gen_be_context.[ch], src/gcc_gen_be_stmt.[ch], src/gcc_gen_be_cache.[ch]):
  - Introduce lexical scope push/pop stacks to support variable shadowing.
  - Add stack save/restore helpers for VLA allocation.
  - Expand cache types for local static guard variables and string constants.

- Dynamic Symbol Loader (src/gcc_gen_be_lib_loader.[ch]):
  - Dynamically load modern libgccjit symbols for union constructors, bitcasts,
    vector rvalues, builtin retrieval, and link sections.

- CLI and Driver Integration (src/cmd_line.[ch], src/gcc_gen_be_main.c):
  - Register --gcc_gen_be and -c command-line options.
  - Lower function scopes with lexical scope tracking and default terminator emission.

- Subsystem Unit Tests and Coverage (tests/gcc_be/, dev_tools/):
  - Add subsystem test suites for ABI, builtins, debug, dtor, main, RTTI, and statements.
  - Update CMake targets and end-to-end backend test fixtures.
  - Add scripts for verifying backend test and documentation coverage.
  - Remove deprecated dev-init.py.
…g in GCC backend

Expand the native libgccjit backend (gcc_gen_be) with target-specific ABI parameter
and return value classification, comprehensive CLI driver options, multi-TU support,
DWARF debug info emission, exception handling routines, and GoogleTest unit suites:

- Target ABI Classification (src/gcc_gen_be_abi.[ch]):
  - Implement System V AMD64 classification (gcc_gen_be_classify_sysv_amd64) with
    eightbyte decomposition across INTEGER, SSE, X87, and MEMORY classes.
  - Add AAPCS64 (ARM64) classification (gcc_gen_be_classify_aapcs64) for HFA/HVA.
  - Add Windows x64 parameter classification (gcc_gen_be_classify_win64).
  - Add Darwin ARM64 calling conventions and invisible reference / sret detection
    (gcc_gen_be_is_passed_by_invisible_reference, gcc_gen_be_is_returned_via_sret,
    gcc_gen_be_classify_darwin_arm64).

- CLI Driver and Multi-TU Compilation (src/cfe.c, src/cmd_line.[ch], src/gcc_gen_be_main.[ch]):
  - Register compilation stage flags (-S, -c) and backend driver switches (--gcc_gen_be).
  - Add target architecture, tuning, and floating-point flags (-march, -mcpu, -mtune,
    -mfpu, -mcmodel, -m32, -m64, -ffast-math, -fno-trapping-math, -fassociative-math,
    -fno-pie, -shared, -static, -L, -l, -fdump-rtl-all).
  - Implement gcc_gen_be_early_init, gcc_gen_be_apply_command_line_options,
    gcc_gen_be_compile_multi_tu, and gcc_gen_be_emit_artifact.
  - Propagate backend initialization and execution status in cfe.c.

- Exception Handling and Coroutines (src/gcc_gen_be_eh.[ch], src/gcc_gen_be_stmt.[ch]):
  - Implement per-function EH lifecycle management (gcc_gen_be_begin_function_eh,
    gcc_gen_be_end_function_eh).
  - Add try-catch block lowering (gcc_gen_be_lower_try_block) and function body
    lowering with exception specification enforcement (gcc_gen_be_lower_routine_body).
  - Add coroutine frame, ramp, and dispatcher lowering entry points.
  - Implement stack save and restore helpers for variable-length arrays (VLAs).

- Debug Metadata and Error Reporting (src/gcc_gen_be_debug.[ch], src/gcc_gen_be_error.[ch]):
  - Add DWARF emission for compile units, subprograms, types, variables, and lexical blocks.
  - Expand gcc_gen_be_error_t enumeration with codes for ABI classification, coroutines,
    DWARF generation, CFI unwinding, and SIMD lowering.

- Expression and Type Lowering (src/gcc_gen_be_expr.c, src/gcc_gen_be_type.c):
  - Expand lowering logic for complex expression operators, casts, initializers,
    and function calls.

- Build System and Toolchain Configuration (CMakeLists.txt):
  - Prevent default selection of lld linker when building with Clang on Darwin.

- Unit Testing and Documentation Coverage (tests/gcc_be/, dev_tools/):
  - Migrate and modernize backend unit tests using the GoogleTest framework.
  - Add test suites: test_dynamic_init.cpp, test_gcc_be_eh.cpp, test_gcc_be_error.cpp,
    test_gcc_be_location.cpp, test_gcc_be_regression.cpp, and generate_tests.py.
  - Expand Doxygen comments across headers and tests to satisfy coverage requirements.
  - Update check_gcc_be_coverage.sh and check_gcc_be_doc_coverage.py.
…ABI, and SIMD

Expand the native libgccjit backend (gcc_gen_be), EDG frontend integration,
runtime library, build presets, and test suites with full language feature
lowering, multi-target calling conventions, exception handling tables, and
100% test and documentation coverage:

- Exception Handling, Unwinding, and Runtime Bridge (src/gcc_gen_be_eh.[ch], lib_src/gcc_be_eh_rt.c):
  - Implement DWARF LSDA (.gcc_except_table) call-site, action, and type-info
    table generation with ULEB128/SLEB128 encoding and CFI directive formatting.
  - Add Windows SEH (.pdata/.xdata) and ARM EHABI (.ARM.extab/.ARM.exidx)
    unwind descriptor table synthesis.
  - Support direct and indirect invoke calls with abnormal unwind CFG edges,
    landing pad selector dispatch, noexcept/dynamic exception spec filters,
    partial array construction cleanups, and subobject unwind cleanups.
  - Add production SjLj/Itanium ABI runtime bridge (lib_src/gcc_be_eh_rt.c)
    providing frame registration and __cxa_type_match across SI/VMI hierarchies.

- C++20 Coroutines, Statements, and Inline Assembly (src/gcc_gen_be_stmt.[ch], src/gcc_gen_be_expr.[ch]):
  - Implement coroutine frame layout/size/alignment computation, ramp lowering,
    resume/destroy state-machine dispatchers, suspension point registration,
    symmetric transfer, noop_coroutine singleton, and HALO elision checks.
  - Lower co_await and co_yield expressions and <coroutine> intrinsics.
  - Add VLA stack allocation lowering (gcc_gen_be_lower_vla_decl) and normalize
    read-modify-write ('+') inline assembly constraints into tied operands.

- Multi-Target ABI Classification and Calling Conventions (src/gcc_gen_be_abi.[ch]):
  - Expand target ABI classifiers to cover System V AMD64, AAPCS64, Darwin ARM64,
    Windows x64, RISC-V LP64D, System V i386, PowerPC64 ELFv2, s390x, and AAPCS32.
  - Track cumulative GP/FP argument register pressure (gcc_gen_be_abi_reg_state_t),
    HFA/HVA packing, sret/invisible-reference lowering, and va_arg/va_list emission.

- RTTI, Itanium Mangling, VTables, and Clones (src/gcc_gen_be_rtti.[ch], src/gcc_gen_be_decl.[ch]):
  - Implement Itanium C++ ABI name mangling for types, functions, expressions,
    and substitution tables (S_, S0_, ...).
  - Emit virtual-base offset (vcall) and covariant return adjustment thunks.
  - Synthesize C1/C2 constructor and D1/D2/D0 deleting destructor clones.
  - Support cross-platform COMDAT/weak-ODR section and linkage formatting
    across ELF, Mach-O, and COFF/PE, plus __dso_handle declaration in dtor.

- Types, Decimal/Fixed-Point Arithmetic, and Builtins (src/gcc_gen_be_type.[ch], src/gcc_gen_be_builtin.[ch]):
  - Lower IEEE 754 decimal floating-point types (_Decimal32/_Decimal64/_Decimal128)
    and BID runtime arithmetic, comparisons, and conversions.
  - Implement ISO/IEC TR 18037 fixed-point (_Fract, _Accum, _Sat) scaled and
    saturating arithmetic, constant bitfield packing, and extended float constants.
  - Expand builtin and SIMD lowering for vector shuffle/permutation,
    __builtin_convertvector, atomic operations, and overflow intrinsics.

- DWARF Debug Metadata, Driver, and Frontend Integration (src/gcc_gen_be_debug.[ch], src/gcc_gen_be_main.[ch], src/*, util/eccp.sh):
  - Add DWARF metadata emission for lexical scopes, inlined subroutines,
    namespaces, class inheritance, template parameters, and enumerations.
  - Implement multi-TU object linking (gcc_gen_be_link_multi_tu_objects) and
    C++20 module initializers (_ZGIW).
  - Enable BACK_END_IS_GCC_GEN_BE across EDG IL headers/allocators/layout and
    integrate --gcc-be / --gcc_gen_be into util/eccp.sh and CMakePresets.json.

- Unit Tests and Coverage Tooling (tests/gcc_be/, dev_tools/):
  - Refactor unit and end-to-end tests to use standalone assertions (test_common.h)
    with full error percolation and Doxygen documentation.
  - Add dedicated test suites for target ABIs, bitfields, coroutines, DWARF debug,
    DWARF/SEH/ARM EH, full RTTI/mangling, SIMD, driver pipelines, and symbol loading.
@SamuelMarks SamuelMarks changed the title gcc backend (initial pass) via libgccjit gcc backend [via libgccjit] Oct 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants