Use __builtin_alloca. Some systems don't have alloca.h or alloca.
Co-Authored-By: Olivier Hainque <hainque@adacore.com>
for gcc/testsuite/ChangeLog
* gcc.dg/analyzer/alloca-leak.c: Drop alloca.h, use builtin.
* gcc.dg/analyzer/data-model-1.c: Likewise.
* gcc.dg/analyzer/malloc-1.c: Likewise.
* gcc.dg/analyzer/malloc-paths-8.c: Likewise.
/* { dg-require-effective-target alloca } */
-#include <alloca.h>
-
void *test (void)
{
- void *ptr = alloca (64);
+ void *ptr = __builtin_alloca (64);
return ptr;
}
/* TODO: warn about escaping alloca. */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include <alloca.h>
#include "analyzer-decls.h"
struct foo
void test_12 (void)
{
- void *p = alloca (256);
- void *q = alloca (256);
+ void *p = __builtin_alloca (256);
+ void *q = __builtin_alloca (256);
/* alloca results should be unique. */
__analyzer_eval (p == q); /* { dg-warning "FALSE" } */
/* { dg-require-effective-target alloca } */
-#include <alloca.h>
#include <stdlib.h>
extern int foo (void);
int test_24 (void)
{
- void *ptr = alloca (sizeof (int)); /* { dg-message "memory is allocated on the stack here" } */
+ void *ptr = __builtin_alloca (sizeof (int)); /* { dg-message "memory is allocated on the stack here" } */
free (ptr); /* { dg-warning "'free' of memory allocated on the stack by 'alloca' \\('ptr'\\) will corrupt the heap \\\[CWE-590\\\]" } */
}
/* { dg-require-effective-target alloca } */
#include <stddef.h>
-#include <alloca.h>
#include <stdlib.h>
extern void do_stuff (const void *);
if (sz >= LIMIT)
ptr = malloc (sz);
else
- ptr = alloca (sz);
+ ptr = __builtin_alloca (sz);
do_stuff (ptr);
{
void *ptr;
if (sz < LIMIT)
- ptr = alloca (sz);
+ ptr = __builtin_alloca (sz);
else
ptr = malloc (sz);
{
void *ptr;
if (sz <= LIMIT)
- ptr = alloca (sz); /* { dg-message "memory is allocated on the stack here" } */
+ ptr = __builtin_alloca (sz); /* { dg-message "memory is allocated on the stack here" } */
else
ptr = malloc (sz);