The OpenD Programming Language

allocSize

Specifies that the function returns null or a pointer to at least a certain number of allocated bytes. sizeArgIdx and numArgIdx specify the 0-based index of the function arguments that should be used to calculate the number of bytes returned:

bytes = argsizeArgIdx * (numArgIdx < 0) ? argnumArgIdx : 1

The optimizer may assume that an @allocSize function has no other side effects and that it is valid to eliminate calls to the function if the allocated memory is not used. The optimizer will eliminate all code from foo in this example: @allocSize(0) void* myAlloc(size_t size); void foo() { auto p = myAlloc(100); p[0] = 1; }

See LLVM LangRef for more details: http://llvm.org/docs/LangRef.html#function-attributes

This attribute has no effect for LLVM < 3.9.

struct allocSize {
int sizeArgIdx;
}

Members

Variables

numArgIdx
int numArgIdx;

If numArgIdx < 0, there is no argument specifying the element count

Examples

import ldc.attributes;

@allocSize(0) extern(C) void* malloc(size_t size);
@allocSize(2,1) extern(C) void* reallocarray(void *ptr, size_t nmemb,
                                             size_t size);
@allocSize(0,1) void* my_calloc(size_t element_size, size_t count,
                                bool irrelevant);

Meta