You copied the Doc URL to your clipboard.

Arm Compiler armclang Reference Guide : __attribute__((value_in_regs)) function attribute

__attribute__((value_in_regs)) function attribute

The value_in_regs function attribute is compatible with functions whose return type is a structure. It alters the calling convention of a function so that the returned structure is stored in the argument registers rather than being written to memory using an implicit pointer argument.

Note

When using __attribute__((value_in_regs)), the calling convention only uses integer registers.

Syntax

__attribute__((value_in_regs)) return-type function-name([argument-list]);

Where:

return-type

is the type of the returned structure that conforms to certain restrictions as described in Restrictions.

Usage

Declaring a function __attribute__((value_in_regs)) can be useful when calling functions that return more than one result.

Restrictions

When targeting AArch32, the returned structure can be up to 16 bytes to fit in four 32-bit argument registers. When targeting AArch64, the returned structure can be up to 64 bytes to fit in eight 64-bit argument registers. If the structure returned by a function qualified by __attribute__((value_in_regs)) is too big, the compiler generates an error.

Each field of the returned structure must occupy exactly one or two integer registers, and must not require implicit padding of the structure. Anything else, including bitfields, is incompatible.

Nested structures are allowed with the same restriction that the nested structure as a whole and its individual members must occupy exactly one or two integer registers.

Unions are allowed if they have at least one maximal-size member that occupies exactly one or two integer registers. The other fields within the union can have any field type.

The allowed field types are:

  • signed int (AArch32 only).
  • unsigned int (AArch32 only).
  • signed long.
  • unsigned long.
  • signed long long.
  • unsigned long long.
  • pointer.
  • structure containing any of the types in this list.
  • union whose maximal-size member is any of the types in this list.

If the structure type returned by a function qualified by __attribute__((value_in_regs)) violates any of the above rules, then the compiler generates the corresponding error.

If a virtual function declared as __attribute__((value_in_regs)) is to be overridden, the overriding function must also be declared as __attribute__((value_in_regs)). If the functions do not match, the compiler generates an error.

A function declared as __attribute__((value_in_regs)) is not function-pointer-compatible with a normal function of the same type signature. If a pointer to a function that is declared as __attribute__((value_in_regs)) is initialized with a pointer to a function that is not declared as __attribute__((value_in_regs)), then the compiler generates a warning.

The return type of a function declared as__attribute__((value_in_regs)) must be known at the point of the function declaration. The compiler generates a corresponding error if the return type is an incomplete type.

Example

struct ReturnType
{
    long a;
    void *ptr;
    union U
    {
       char c;
       short s;
       int i;
       float f;
       double d;
       struct S1 {long long ll;} s1;
    } u;
};

extern __attribute__((value_in_regs)) struct retType g(long y);
Was this page helpful? Yes No