3.20 __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 structure that conforms to certain 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 structure can be up to 16 bytes in order to fit in four 32-bit argument registers. When targeting AArch64, the structure can be up to 64 bytes in order 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 structure has to fit exactly in one integer register. Therefore, the fields can only be pointers or pointer-sized integers. Anything else, including bitfields, is incompatible. Nested structures are allowed if they contain a single field whose type is pointer or pointer-sized integer. Unions can have more that one field. If the type of the return structure 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.

Example

typedef struct ReturnType
{
    long a;
    char *b;
    union U
    {
       int *c;
       struct S1 {short *d;} s1;
    } u;
    struct S2 {double *e;} s2;
} my_struct;

extern __attribute__((value_in_regs)) my_struct foo(long x);
Non-ConfidentialPDF file icon PDF versionDUI0774J
Copyright © 2014–2017, 2019 Arm Limited or its affiliates. All rights reserved.