Hello, Some of the tests in gcc.dg/analyzer exercize alloca and #include <alloca.h>.
Some systems, e.g. VxWorks, don't feature alloca.h and the aforementioned tests fail. Other tests in the suite have been in this situation and the usual way around consists in resorting to __builtin_alloca directly. This patch is a proposal in this direction for gcc.dg/analyzer. It introduces a common "analyzer-alloca.h" where we can stick a common comment and a macro to redirect "alloca" directly to "__builtin_alloca". The intermediate macro in a non system header unfortunately diverts some of the warning expectations, as the allocation point for "x = alloca(128);" is shown on the macro definition and not at the macro invocation point. The patch circumvents this by calling __builtin_alloca directly from the points where the tests perform a warning check. I have verified that all the tests adjusted by the change now pass in a run for a powerpc-vxworks configuration. I'll gladly perform an extra regression test on a native system if the patch is considered ok. Would this be ok to commit ? Thanks in advance, With Kind Regards, Olivier 2020-10-29 Olivier Hainque <hain...@adacore.com> gcc/testsuite/ * gcc.dg/analyzer/analyzer-alloca.h: New file. * gcc.dg/analyzer/alloca-leak.c: Use it. * gcc.dg/analyzer/data-model-1.c: Use it. * gcc.dg/analyzer/malloc-1.c: Use it and replace call to be tracked by a direct call to __builtin_alloca. * gcc.dg/analyzer/malloc-paths-8.c: Likewise.
diff --git a/gcc/testsuite/gcc.dg/analyzer/alloca-leak.c b/gcc/testsuite/gcc.dg/analyzer/alloca-leak.c index 93319932d44a..e990cbc642b9 100644 --- a/gcc/testsuite/gcc.dg/analyzer/alloca-leak.c +++ b/gcc/testsuite/gcc.dg/analyzer/alloca-leak.c @@ -1,6 +1,6 @@ /* { dg-require-effective-target alloca } */ -#include <alloca.h> +#include "analyzer-alloca.h" void *test (void) { diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer-alloca.h b/gcc/testsuite/gcc.dg/analyzer/analyzer-alloca.h new file mode 100644 index 000000000000..edb20b118db3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/analyzer-alloca.h @@ -0,0 +1,8 @@ + +/* This header is provided to circumvent the absence of alloca.h on + some systems. Spots that rely on the ability to designate + allocation points within tests can use __builtin_alloca directly + to prevent the diagnostic redirection to the local macro definition + here, as this is not a system header. */ + +#define alloca(n) __builtin_alloca(n) diff --git a/gcc/testsuite/gcc.dg/analyzer/data-model-1.c b/gcc/testsuite/gcc.dg/analyzer/data-model-1.c index 3f16a38ab14d..f4ba96b1e997 100644 --- a/gcc/testsuite/gcc.dg/analyzer/data-model-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/data-model-1.c @@ -3,7 +3,7 @@ #include <stdlib.h> #include <string.h> #include <stdio.h> -#include <alloca.h> +#include "analyzer-alloca.h" #include "analyzer-decls.h" struct foo diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c index 38ce1a52987b..b0039597c5fb 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c @@ -1,6 +1,6 @@ /* { dg-require-effective-target alloca } */ -#include <alloca.h> +#include "analyzer-alloca.h" #include <stdlib.h> extern int foo (void); @@ -273,7 +273,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 35c9385b2061..417459edf8cc 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c @@ -2,7 +2,7 @@ /* { dg-require-effective-target alloca } */ #include <stddef.h> -#include <alloca.h> +#include "analyzer-alloca.h" #include <stdlib.h> extern void do_stuff (const void *); @@ -41,7 +41,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); -- 2.17.1