Repository navigation
gcc backend [via libgccjit] - #239
Open
SamuelMarks wants to merge 7 commits into
Open
SamuelMarks wants to merge 7 commits into
SamuelMarks wants to merge 7 commits into
Conversation
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.
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
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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (.sassembly,.orelocatable 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:src/gcc_gen_be_*.[ch]): Decoupled subsystems for error handling, context/scope state machines, dynamic hash-map memoization, cross-platformlibgccjitdynamic 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.noexceptInvariants: Universal[[nodiscard]]/__attribute__((warn_unused_result))enforcement attached directly toenum gcc_gen_be_error(gcc_gen_be_error_t, 82 distinct error codes),GCC_GEN_BE_CHECK/GCC_GEN_BE_CHECK_CLEANUPpercolation macros, out-parameter idioms,-Werror=unused-result, andGCC_GEN_BE_NOEXCEPTacross every backend API.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_ZTIhierarchy 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.get_return_object_on_allocation_failure), resume/destroy state-machine dispatchers,co_await/co_yield/co_return, symmetric transfer,std::noop_coroutinesingleton, and Heap Allocation Elision Optimization (HALO)..gcc_except_tableLSDA generation (ULEB128/SLEB128 call-site, action, and@TTypetables), Windows x64/ARM64.pdata/.xdataSEH (__try/__except/__finally), ARM EHABI (.ARM.extab/.ARM.exidxcompact PR0 & generic PR1), partial array construction cleanups, constructor base/member subobject cleanups,noexcepttermination filters, and dynamic exception specifications._Z...) with substitution tables (S_,S0_, ...), vtable (_ZTV) and VTT (_ZTT) synthesis, virtual-base offset (vcall) and covariant return adjustment thunks,C1/C2constructor andD1/D2/D0deleting destructor clones, and cross-platform COMDAT/weak-ODR sections (ELF, Mach-O, COFF/PE).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-awareva_arg/va_liststate machines._Decimal32/_Decimal64/_Decimal128vialibgccBID 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).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)
cc0d088356[libgccjit]backend (initial pass) — Introducescmake/FindLibGCCJIT.cmake,EDG_ENABLE_GCC_BACKEND,BACK_END_IS_GCC_GEN_BEinsrc/host_envir.h, initial monolithicsrc/gcc_gen_be.[ch], and initialtests/gcc_be/harness.533a5b95acsrc/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-*).516331dafanoexceptacross GCC backend — AttachesGCC_GEN_BE_NODISCARDdirectly toenum gcc_gen_be_error, introducesGCC_GEN_BE_NOEXCEPT, converts all backend functions (includinggcc_gen_be()andback_end()) to returngcc_gen_be_error_twith out-parameters, and percolates all fallible operations viaGCC_GEN_BE_CHECK().8904394694gcc_gen_be_context, convertsbe_cache_mapto dynamically resizing hash tables with hit/miss metrics, bridges backend errors to EDG'sf_errordiagnostics, loads optional modernlibgccjitsymbols, and adds standalone subsystem unit test binaries.5f9218bc60gcc_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 addsdev_tools/check_gcc_be_doc_coverage.py&dev_tools/check_gcc_be_coverage.sh(removing legacydev-init.py).cf7106287b-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.4a57745410lib_src/gcc_be_eh_rt.cruntime 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/D2clones, COMDAT sections, IEEE 754 decimal floats, ISO fixed-point arithmetic, SIMD shuffle/convertvector,util/eccp.sh--gcc-beintegration,CMakePresets.json, and 100% test/doc coverage.Subsystem Architecture & Technical Deep-Dive
1. Error Handling & Diagnostic Infrastructure (
src/gcc_gen_be_error.[ch])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-resultin CMake.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.GCC_GEN_BE_CHECK(expr)andGCC_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])gcc_gen_be_context_t): Encapsulates the activegcc_jit_context *, active basic block (gcc_jit_block *), thread ownership ID (gcc_gen_be_check_thread_safety()), and dynamically resizing stacks:break_stack,continue_stack,switch_exit_stack,block_stack.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), andactive_seh_finally_stack(gcc_gen_be_seh_finally_entry_t).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).coro_state_stack(gcc_gen_be_coro_state_t) for nested/lambda coroutines andeh_state(gcc_gen_be_eh_state_t) for nested functions.computed_goto_dispatch_block,computed_goto_target_lval, andcomputed_goto_labelsarray for&&labelandgoto *expr.3. Dynamic Hash-Map Memoization (
src/gcc_gen_be_cache.[ch])gcc_gen_be_cache_type_t):GCC_GEN_BE_CACHE_TYPE: Memoizesa_type_ptr→gcc_jit_type *(essential for breaking cyclic struct/class pointer graphs).GCC_GEN_BE_CACHE_VAR: Memoizesa_variable_ptr→gcc_jit_lvalue *.GCC_GEN_BE_CACHE_FUNC: Memoizesa_routine_ptr→gcc_jit_function *.GCC_GEN_BE_CACHE_LABEL: Memoizesa_label_ptr→gcc_jit_block *.GCC_GEN_BE_CACHE_FIELD: Memoizesa_field_ptr→gcc_jit_field *.GCC_GEN_BE_CACHE_SWITCH_CASE: Memoizesa_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.be_cache_mapautomatically doubles bucket capacity when load factor thresholds are exceeded and tracks lookup telemetry (hits,misses) queryable viacache_get_metrics().4. Cross-Platform
libgccjitDynamic Loader (src/gcc_gen_be_lib_loader.[ch])dlopen/dlsym(RTLD_DEFAULTfallback) on POSIX (Linux, macOS, FreeBSD) andLoadLibraryA/GetProcAddress(with/DELAYLOAD:libgccjit.dllon MSVC) on Windows (load_libgccjit_posix,load_libgccjit_windows).libgccjitsymbols while providing graceful lowering fallbacks when running against olderlibgccjitreleases (GCC 10–16+):gcc_jit_context_new_struct_constructor,gcc_jit_context_new_array_constructor,gcc_jit_context_new_union_constructor,gcc_jit_context_new_bitcast.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.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.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.gcc_gen_be_probe_eh_builtins(),gcc_gen_be_probe_native_eh_support(),gcc_gen_be_resolve_eh_entrypoints(), andgcc_gen_be_probe_extended_float_types().5. Multi-Target ABI Classification & Register Coercion (
src/gcc_gen_be_abi.[ch])gcc_gen_be_target_abi_t):GCC_GEN_BE_TARGET_ABI_SYSV_AMD64): Recursive eightbyte classification (gcc_gen_be_classify_sysv_amd64) acrossINTEGER,SSE,SSEUP,X87,X87UP,COMPLEX_X87,NO_CLASS, andMEMORYwith post-merger cleanup.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 indirectx8result location semantics.GCC_GEN_BE_TARGET_ABI_DARWIN_ARM64): Darwin-specific variadic argument stack demotion and sub-word packing (gcc_gen_be_classify_darwin_arm64).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 viagcc_gen_be_classify_win64).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) viagcc_gen_be_classify_riscv64andgcc_gen_be_coerced_riscv64_type.GCC_GEN_BE_TARGET_ABI_SYSV_I386): Hiddensretstack pointer classification (gcc_gen_be_classify_i386).GCC_GEN_BE_TARGET_ABI_PPC64LE_ELFV2): 8-element HFA/HVA classification and > 16-byte non-HFAr3sretbuffer detection (gcc_gen_be_classify_ppc64le,gcc_gen_be_coerced_ppc64le_type).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).GCC_GEN_BE_TARGET_ABI_AAPCS32): ≤ 4-byter0return vs > 4-bytesretand 8-byte aligned even-odd register pair (r0:r1,r2:r3) tracking (gcc_gen_be_classify_aapcs32).gcc_gen_be_init_abi_reg_state()andgcc_gen_be_allocate_abi_param_regs()trackgp_used/gp_limitandfp_used/fp_limitacross function signatures and call sites, demoting arguments to stack memory when hardware registers are exhausted.gcc_gen_be_is_passed_by_invisible_reference()andgcc_gen_be_is_returned_via_sret()detect C++ non-trivially copyable classes (user copy/move ctors or non-trivial dtors).gcc_gen_be_pack_coerced_argument(),gcc_gen_be_unpack_coerced_parameter(),gcc_gen_be_pack_coerced_return(), andgcc_gen_be_unpack_coerced_return().va_argstate 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).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(), andgcc_gen_be_emit_lsda_call_site_table()generate@LPStart,@TType, call-site records, and chained SLEB128 action records (filter > 0for typedcatch,filter == 0for RAII cleanups,filter < 0for exception specifications)..pdata/.xdata):gcc_gen_be_emit_seh_unwind_tables()synthesizesUNWIND_INFO(UNW_FLAG_EHANDLER/UNW_FLAG_UHANDLER),__C_specific_handlerscope records, andRUNTIME_FUNCTIONdescriptors..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.gcc_gen_be_emit_invoke_call()andgcc_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()andgcc_gen_be_emit_noexcept_filter()enforce C++11noexcept(true)(_ZSt9terminatev) and legacy dynamicthrow(T1, T2)(__cxa_call_unexpected) specifications.lib_src/gcc_be_eh_rt.c):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_matchwith full recursive base-class traversal andthis-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])gcc_gen_be_compute_coro_frame_layout()andgcc_gen_be_compute_coro_frame_size_and_align()construct the per-coroutine frame struct (__resume_fnat offset0,__destroy_fnat offsetsizeof(void *),__promise,__suspend_index,__coro_flags, copied parameters, and spilled cross-suspension local variables/temporaries).gcc_gen_be_lower_coroutine_ramp()lowers frame allocation (operator newor promise-specific allocator),get_return_object_on_allocation_failure()onnoexceptallocation failure, parameter copying, promise construction,get_return_object(), and initial suspend execution.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(), andgcc_gen_be_emit_coro_symmetric_transfer()lowerawait_ready(), state saving,await_suspend()(handlingvoid,bool, and symmetric transferstd::coroutine_handle<T>with fallback to__gcc_be_noop_coro_framefromgcc_gen_be_get_noop_coroutine_frame()), andawait_resume().gcc_gen_be_try_coro_halo()evaluates non-escaping coroutine descriptors for Heap Allocation Elision Optimization.if/else,while,do-while,for,switch(including GNU case rangescase low ... high:andGCC_GEN_BE_CACHE_SWITCH_CASEdeduplication),goto, computedgoto *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).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 supportsasm gotoviap_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])gcc_gen_be_mangle_type_name(),gcc_gen_be_mangle_with_substitutions(),gcc_gen_be_mangle_function_name(), andgcc_gen_be_mangle_expr()implement_Zencoding 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_, ...).gcc_gen_be_emit_vtable()synthesizes_ZTVglobals containing virtual base/call offsets, offset-to-top (-offset),_ZTIRTTI pointer, and virtual function pointers (mapping pure virtuals to__cxa_pure_virtual).gcc_gen_be_emit_vtt()synthesizes_ZTTVirtual Table Tables for diamond and virtual-inheritance hierarchies.gcc_gen_be_emit_thunk(),gcc_gen_be_emit_vcall_thunk()(_ZTv0_n...), andgcc_gen_be_emit_covariant_return_thunk()(_ZTch.../_ZTcv...) adjustthisand return pointers across multiple and virtual inheritance lattices.dynamic_cast&typeid:gcc_gen_be_emit_type_descriptor()emits_ZTStype strings and_ZTIdescriptors (__fundamental_type_info,__class_type_info,__si_class_type_info,__vmi_class_type_infowith__base_class_type_infoflags, and__pointer_type_info).gcc_gen_be_lower_dynamic_cast()lowers runtime downcasts/crosscasts to__dynamic_castand reference casts to__cxa_bad_caston failure.gcc_gen_be_lower_typeid()lowerstypeid(T)and polymorphictypeid(*ptr)(loadingvptr[-1]with null check calling__cxa_bad_typeid).gcc_gen_be_emit_ctor_dtor_clones()synthesizes complete (C1/D1), base (C2/D2), and deleting (D0, invokingD1then_ZdlPv) clones.gcc_gen_be_format_comdat_section_name()andgcc_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(), andgcc_gen_be_get_dso_handle()register global andthread_localdestructors 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])bool, scoped/unscoped enums, pointers, pointers-to-data-members (ptrdiff_toffset), pointers-to-member-functions ({ fn_ptr_or_vtable_offset, this_adj }struct), arrays, VLAs, structs, classes, unions, bitfields,_Complextypes, 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.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(), andgcc_gen_be_lower_decimal_float_unary_op()lower_Decimal32,_Decimal64, and_Decimal128operations tolibgccBID runtime helpers (__bid_addsd3,__bid_mulsd3,__bid_eqdd2,__bid_extendsddd2, etc.).gcc_gen_be_lower_fixed_point_op()andgcc_gen_be_lower_fixed_point_binary_op()lower ISO/IEC TR 18037_Fractand_Accumscaled arithmetic with optional_Satsaturation clamping.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_sizebounds (modes 0..3).gcc_gen_be_lower_vector_shuffle(),gcc_gen_be_lower_convertvector(), andgcc_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])gcc_gen_be_set_dwarf_config(),gcc_gen_be_get_dwarf_config(), andgcc_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).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)BACK_END_IS_GCC_GEN_BEacrosssrc/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, andsrc/cfe.c.#pragma packalignment in IL pragma entries andbit_field_alignment_typeon bitfield descriptors whenBACK_END_IS_GCC_GEN_BEis active.--gcc_gen_be(--gcc-be/--gcc_beinutil/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(), andgcc_gen_be_emit_module_initializer()(_ZGIW<module>) orchestrate per-TU context isolation, C++20 module initializer emission, and final binary linking.cmake/FindLibGCCJIT.cmakewith compile-time feature detection (LIBGCCJIT_HAVE_*),EDG_ENABLE_GCC_BACKENDoption, CPack DEB/RPM/TGZ/DragNDrop/WIX packaging rules, and 4 new presets inCMakePresets.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
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.cpfe --gcc_gen_be -c -o <test>.o, linked into a native executable (withgcc_be_eh_rt), and executed under CTest.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.tests/gcc_be/check_coverage.py&dev_tools/check_gcc_be_coverage.sh: Verifies 100.00% function, line, and branch coverage across allsrc/gcc_gen_be_*.candtests/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