You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The __builtin_alloca_with_align function must be called at block scope. The function allocates an object size bytes large on the stack of the calling function. The allocated object is aligned on the boundary specified by the argument alignment whose unit is given in bits (not bytes). The size argument must be positive and not exceed the stack size limit. The alignment argument must be a constant integer expression that evaluates to a power of 2 greater than or equal to CHAR_BIT and less than some unspecified maximum. Invocations with other values are rejected with an error indicating the valid bounds. The function returns a pointer to the first byte of the allocated object. The lifetime of the allocated object ends at the end of the block in which the function was called. The allocated storage is released no later than just before the calling function returns to its caller, but may be released at the end of the block in which the function was called.
For example, in the following function the call to g is unsafe because when overalign is non-zero, the space allocated by __builtin_alloca_with_align may have been released at the end of the if statement in which it was called.
void f (unsigned n, bool overalign)
{
void *p;
if (overalign)
p = __builtin_alloca_with_align (n, 64 /* bits */);
else
p = __builtin_alloc (n);
g (p, n); // unsafe
}
Since the __builtin_alloca_with_align function doesn’t validate its size argument it is the responsibility of its caller to make sure the argument doesn’t cause it to exceed the stack size limit. The __builtin_alloca_with_align function is provided to make it possible to allocate on the stack overaligned arrays of bytes with an upper bound that may be computed at run time. Since C99 Variable Length Arrays offer the same functionality under a portable, more convenient, and safer interface they are recommended instead, in both C99 and C++ programs where GCC provides them as an extension. See Variable Length, for details.
No description provided.
The text was updated successfully, but these errors were encountered: