infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
102_by_reference.c File Reference

Tests passing and returning aggregates that are handled by reference. More...

#include "common/double_tap.h"
#include "types.h"
#include <infix/infix.h>
Include dependency graph for 102_by_reference.c:

Macros

#define DBLTAP_IMPLEMENTATION
 

Functions

int process_large_struct (LargeStruct s)
 Processes a large struct, returning a value derived from its members.
 
LargeStruct return_large_struct (int base_val)
 Returns a large struct by value, which the ABI turns into a hidden pointer return.
 
int process_npot_struct (NonPowerOfTwoStruct s)
 
 subtest ("Large struct (>16 bytes) passed and returned by reference/stack")
 
 subtest ("Non-power-of-two sized struct")
 

Variables

 TEST
 

Detailed Description

Tests passing and returning aggregates that are handled by reference.

Copyright (c) 2025 Sanko Robinson

This source code is dual-licensed under the Artistic License 2.0 or the MIT License. You may choose to use this code under the terms of either license.

SPDX-License-Identifier: (Artistic-2.0 OR MIT)

The documentation blocks within this file are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).

SPDX-License-Identifier: CC-BY-4.0

This test suite focuses on aggregates that are too large to be passed entirely in registers. According to most ABIs, such structs are either passed as a pointer to a copy on the stack (by reference) or directly on the stack. When returned, a hidden pointer to a caller-allocated buffer is often used. This suite verifies these mechanisms.

It covers two main scenarios:

  1. Large Structs (All Platforms): A struct larger than 16 bytes is used to test the common case for stack-based passing and returning via a hidden pointer. This is expected behavior on SysV x64, Windows x64, and AArch64.
  2. Windows x64 Specific Rule: The Windows x64 ABI mandates that any aggregate whose size is not a power of two (1, 2, 4, or 8 bytes) must be passed by reference, regardless of its total size. This test verifies this specific edge case using a 12-byte struct.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ process_large_struct()

int process_large_struct ( LargeStruct  s)

Processes a large struct, returning a value derived from its members.

◆ process_npot_struct()

int process_npot_struct ( NonPowerOfTwoStruct  s)

◆ return_large_struct()

LargeStruct return_large_struct ( int  base_val)

Returns a large struct by value, which the ABI turns into a hidden pointer return.

◆ subtest() [1/2]

subtest ( "Large struct (>16 bytes) passed and returned by reference/stack"  )

◆ subtest() [2/2]

subtest ( "Non-power-of-two sized struct"  )

Variable Documentation

◆ TEST

TEST
Initial value:
{
plan(2)
#define plan(count)
Definition double_tap.h:132