On Jan 15, 2021, Olivier Hainque <hain...@adacore.com> wrote:
> On 14 Jan 2021, at 22:13, Alexandre Oliva <ol...@adacore.com> wrote:
>> Would you mind if I submitted an alternate patch to do so?
> Not at all, thanks for your feedback and for proposing
> an alternative!
Here's the modified patch. Regstrapped on x86_64-linux-gnu, also tested
on x-arm-vx7r2. David, I'm leaning towards putting it in as "obvious",
barring any objections.
gcc.dg/analyzer tests: use __builtin_alloca, not alloca.h
From: Alexandre Oliva <ol...@adacore.com>
Use __builtin_alloca. Some systems don't have alloca.h or alloca.
Co-Authored-By: Olivier Hainque <hain...@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.
---
gcc/testsuite/gcc.dg/analyzer/alloca-leak.c | 4 +---
gcc/testsuite/gcc.dg/analyzer/data-model-1.c | 5 ++---
gcc/testsuite/gcc.dg/analyzer/malloc-1.c | 3 +--
gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c | 7 +++----
4 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/analyzer/alloca-leak.c
b/gcc/testsuite/gcc.dg/analyzer/alloca-leak.c
index 93319932d44ac..073f97e1ade32 100644
--- a/gcc/testsuite/gcc.dg/analyzer/alloca-leak.c
+++ b/gcc/testsuite/gcc.dg/analyzer/alloca-leak.c
@@ -1,10 +1,8 @@
/* { 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. */
diff --git a/gcc/testsuite/gcc.dg/analyzer/data-model-1.c
b/gcc/testsuite/gcc.dg/analyzer/data-model-1.c
index 3f16a38ab14d4..f6681b678af61 100644
--- a/gcc/testsuite/gcc.dg/analyzer/data-model-1.c
+++ b/gcc/testsuite/gcc.dg/analyzer/data-model-1.c
@@ -3,7 +3,6 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include <alloca.h>
#include "analyzer-decls.h"
struct foo
@@ -140,8 +139,8 @@ void test_11 (void)
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" } */
diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c
b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c
index 26d828848a259..448b8558ffe11 100644
--- a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c
+++ b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c
@@ -1,6 +1,5 @@
/* { dg-require-effective-target alloca } */
-#include <alloca.h>
#include <stdlib.h>
extern int foo (void);
@@ -273,7 +272,7 @@ int *test_23a (int n)
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\\\]" } */
}
diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c
b/gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c
index 35c9385b20611..9a7c414920ce2 100644
--- a/gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c
+++ b/gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c
@@ -2,7 +2,6 @@
/* { dg-require-effective-target alloca } */
#include <stddef.h>
-#include <alloca.h>
#include <stdlib.h>
extern void do_stuff (const void *);
@@ -15,7 +14,7 @@ void test_1 (size_t sz)
if (sz >= LIMIT)
ptr = malloc (sz);
else
- ptr = alloca (sz);
+ ptr = __builtin_alloca (sz);
do_stuff (ptr);
@@ -27,7 +26,7 @@ void test_2 (size_t sz)
{
void *ptr;
if (sz < LIMIT)
- ptr = alloca (sz);
+ ptr = __builtin_alloca (sz);
else
ptr = malloc (sz);
@@ -41,7 +40,7 @@ void test_3 (size_t 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);
--
Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/
Free Software Activist GNU Toolchain Engineer
Vim, Vi, Voltei pro Emacs -- GNUlius Caesar