From da7cf663b75513e4d2baf5a579ffcb4f8a61193b Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Wed, 22 Jan 2020 02:45:48 +0100 Subject: [PATCH] analyzer: testsuite fixes for alloca, getpass, and setjmp (PR 93316) PR analyzer/93316 reports various testsuite failures where I accidentally relied on properties of x86_64-pc-linux-gnu. The following patch fixes them on sparc-sun-solaris2.11 (gcc211 in the GCC compile farm), and, I hope, the other configurations showing failures. There may still be other failures for pattern-test-2.c, which I'm tracking separately as PR analyzer/93291. gcc/analyzer/ChangeLog: PR analyzer/93316 * analyzer.cc (is_setjmp_call_p): Check for "setjmp" as well as "_setjmp". gcc/testsuite/ChangeLog: PR analyzer/93316 * gcc.dg/analyzer/data-model-1.c: Include . * gcc.dg/analyzer/malloc-1.c: Likewise. * gcc.dg/analyzer/malloc-callbacks.c (get_alloca): Return __builtin_alloca rather than alloca. * gcc.dg/analyzer/malloc-paths-8.c: Include . * gcc.dg/analyzer/sensitive-1.c: Define __EXTENSIONS__ before including unistd.h. * gcc.dg/analyzer/setjmp-2.c: Replace include of with "test-setjmp.h" and usage of setjmp with new SETJMP macro. * gcc.dg/analyzer/setjmp-3.c: Likewise. * gcc.dg/analyzer/setjmp-4.c: Likewise. * gcc.dg/analyzer/setjmp-5.c: Likewise. * gcc.dg/analyzer/setjmp-6.c: Likewise. * gcc.dg/analyzer/setjmp-7.c: Likewise. * gcc.dg/analyzer/setjmp-7a.c: Likewise. * gcc.dg/analyzer/setjmp-8.c: Likewise. * gcc.dg/analyzer/setjmp-9.c: Likewise. * gcc.dg/analyzer/test-setjmp.h: New header. --- gcc/analyzer/ChangeLog | 6 +++++ gcc/analyzer/analyzer.cc | 3 ++- gcc/testsuite/ChangeLog | 22 +++++++++++++++++++ gcc/testsuite/gcc.dg/analyzer/data-model-1.c | 1 + gcc/testsuite/gcc.dg/analyzer/malloc-1.c | 1 + .../gcc.dg/analyzer/malloc-callbacks.c | 4 +++- .../gcc.dg/analyzer/malloc-paths-8.c | 1 + gcc/testsuite/gcc.dg/analyzer/sensitive-1.c | 4 ++++ gcc/testsuite/gcc.dg/analyzer/setjmp-2.c | 10 ++++----- gcc/testsuite/gcc.dg/analyzer/setjmp-3.c | 8 +++---- gcc/testsuite/gcc.dg/analyzer/setjmp-4.c | 12 +++++----- gcc/testsuite/gcc.dg/analyzer/setjmp-5.c | 6 ++--- gcc/testsuite/gcc.dg/analyzer/setjmp-6.c | 4 ++-- gcc/testsuite/gcc.dg/analyzer/setjmp-7.c | 4 ++-- gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c | 8 +++---- gcc/testsuite/gcc.dg/analyzer/setjmp-8.c | 8 +++---- gcc/testsuite/gcc.dg/analyzer/setjmp-9.c | 8 +++---- gcc/testsuite/gcc.dg/analyzer/test-setjmp.h | 16 ++++++++++++++ 18 files changed, 90 insertions(+), 36 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/analyzer/test-setjmp.h diff --git a/gcc/analyzer/ChangeLog b/gcc/analyzer/ChangeLog index 07876a0b4af..d0a652b4a57 100644 --- a/gcc/analyzer/ChangeLog +++ b/gcc/analyzer/ChangeLog @@ -1,3 +1,9 @@ +2020-01-22 David Malcolm + + PR analyzer/93316 + * analyzer.cc (is_setjmp_call_p): Check for "setjmp" as well as + "_setjmp". + 2020-01-22 David Malcolm PR analyzer/93307 diff --git a/gcc/analyzer/analyzer.cc b/gcc/analyzer/analyzer.cc index 2a3ffaee852..3884788ee9e 100644 --- a/gcc/analyzer/analyzer.cc +++ b/gcc/analyzer/analyzer.cc @@ -91,7 +91,8 @@ is_setjmp_call_p (const gimple *stmt) { /* TODO: is there a less hacky way to check for "setjmp"? */ if (const gcall *call = dyn_cast (stmt)) - if (is_special_named_call_p (call, "_setjmp", 1)) + if (is_special_named_call_p (call, "setjmp", 1) + || is_special_named_call_p (call, "_setjmp", 1)) return true; return false; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6c5fe273c64..5f07ffec0f9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,25 @@ +2020-01-22 David Malcolm + + PR analyzer/93316 + * gcc.dg/analyzer/data-model-1.c: Include . + * gcc.dg/analyzer/malloc-1.c: Likewise. + * gcc.dg/analyzer/malloc-callbacks.c (get_alloca): Return + __builtin_alloca rather than alloca. + * gcc.dg/analyzer/malloc-paths-8.c: Include . + * gcc.dg/analyzer/sensitive-1.c: Define __EXTENSIONS__ before + including unistd.h. + * gcc.dg/analyzer/setjmp-2.c: Replace include of + with "test-setjmp.h" and usage of setjmp with new SETJMP macro. + * gcc.dg/analyzer/setjmp-3.c: Likewise. + * gcc.dg/analyzer/setjmp-4.c: Likewise. + * gcc.dg/analyzer/setjmp-5.c: Likewise. + * gcc.dg/analyzer/setjmp-6.c: Likewise. + * gcc.dg/analyzer/setjmp-7.c: Likewise. + * gcc.dg/analyzer/setjmp-7a.c: Likewise. + * gcc.dg/analyzer/setjmp-8.c: Likewise. + * gcc.dg/analyzer/setjmp-9.c: Likewise. + * gcc.dg/analyzer/test-setjmp.h: New header. + 2020-01-22 Marek Polacek PR c++/92907 - noexcept does not consider "const" in member functions. diff --git a/gcc/testsuite/gcc.dg/analyzer/data-model-1.c b/gcc/testsuite/gcc.dg/analyzer/data-model-1.c index 3a0108d0b8c..91685f578a4 100644 --- a/gcc/testsuite/gcc.dg/analyzer/data-model-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/data-model-1.c @@ -1,6 +1,7 @@ #include #include #include +#include #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 6e9a014272e..e2e279bd7fd 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c @@ -1,3 +1,4 @@ +#include #include #include diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-callbacks.c b/gcc/testsuite/gcc.dg/analyzer/malloc-callbacks.c index eb5545e5da0..901ca5c46fd 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-callbacks.c +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-callbacks.c @@ -12,7 +12,9 @@ get_malloc (void) static allocator_t __attribute__((noinline)) get_alloca (void) { - return alloca; + /* On e.g. Solaris, alloca is a macro so we can't take its address; + use __builtin_alloca instead. */ + return __builtin_alloca; } static deallocator_t __attribute__((noinline)) diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c b/gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c index bf858e04840..10b97a05402 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-paths-8.c @@ -1,6 +1,7 @@ /* { dg-additional-options "-fanalyzer-transitivity" } */ #include +#include #include extern void do_stuff (const void *); diff --git a/gcc/testsuite/gcc.dg/analyzer/sensitive-1.c b/gcc/testsuite/gcc.dg/analyzer/sensitive-1.c index 8c6b6074784..81144af620e 100644 --- a/gcc/testsuite/gcc.dg/analyzer/sensitive-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/sensitive-1.c @@ -1,5 +1,9 @@ #include + +/* Solaris needs this for to declare getpass. */ +#define __EXTENSIONS__ #include + #include char test_1 (FILE *logfile) diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-2.c b/gcc/testsuite/gcc.dg/analyzer/setjmp-2.c index f0fd23cf264..beaf43684e0 100644 --- a/gcc/testsuite/gcc.dg/analyzer/setjmp-2.c +++ b/gcc/testsuite/gcc.dg/analyzer/setjmp-2.c @@ -1,7 +1,7 @@ /* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */ /* { dg-enable-nn-line-numbers "" } */ -#include +#include "test-setjmp.h" #include #include "analyzer-decls.h" @@ -9,7 +9,7 @@ extern void foo (int); void test_1 (void) { - setjmp (NULL); + SETJMP (NULL); } void test_2 (void) @@ -19,7 +19,7 @@ void test_2 (void) foo (0); - i = setjmp(env); + i = SETJMP(env); foo (1); @@ -39,7 +39,7 @@ void test_2 (void) | ^~~~~~~~~~~~~~~~~~~~~~~ 'test_2': event 1 | - | NN | i = setjmp(env); + | NN | i = SETJMP(env); | | ^~~~~~ | | | | | (1) 'setjmp' called here @@ -59,7 +59,7 @@ void test_2 (void) | 'test_2': event 5 | - | NN | i = setjmp(env); + | NN | i = SETJMP(env); | | ^~~~~~ | | | | | (5) ...to 'setjmp' (saved at (1)) diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-3.c b/gcc/testsuite/gcc.dg/analyzer/setjmp-3.c index 0c082b82a70..5c1d4060c3b 100644 --- a/gcc/testsuite/gcc.dg/analyzer/setjmp-3.c +++ b/gcc/testsuite/gcc.dg/analyzer/setjmp-3.c @@ -1,8 +1,8 @@ /* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */ /* { dg-enable-nn-line-numbers "" } */ -#include #include +#include "test-setjmp.h" #include "analyzer-decls.h" extern int foo (int) __attribute__ ((__pure__)); @@ -20,7 +20,7 @@ void outer (void) foo (0); - i = setjmp(env); + i = SETJMP(env); if (i != 0) { @@ -47,7 +47,7 @@ void outer (void) | 'outer': event 2 | - | NN | i = setjmp(env); + | NN | i = SETJMP(env); | | ^~~~~~ | | | | | (2) 'setjmp' called here @@ -84,7 +84,7 @@ void outer (void) | 'outer': event 8 | - | NN | i = setjmp(env); + | NN | i = SETJMP(env); | | ^~~~~~ | | | | | (8) ...to 'setjmp' in 'outer' (saved at (2)) diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-4.c b/gcc/testsuite/gcc.dg/analyzer/setjmp-4.c index bfac6170d91..f216a456b59 100644 --- a/gcc/testsuite/gcc.dg/analyzer/setjmp-4.c +++ b/gcc/testsuite/gcc.dg/analyzer/setjmp-4.c @@ -1,7 +1,7 @@ /* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */ /* { dg-enable-nn-line-numbers "" } */ -#include +#include "test-setjmp.h" #include "analyzer-decls.h" extern int foo (int) __attribute__ ((__pure__)); @@ -23,7 +23,7 @@ void outer (int y) int main (void) { - if (!setjmp(buf)) + if (!SETJMP(buf)) outer (42); else __analyzer_dump_path (); /* { dg-message "path" } */ @@ -42,14 +42,14 @@ int main (void) | 'main': event 2 | - | NN | if (!setjmp(buf)) + | NN | if (!SETJMP(buf)) | | ^~~~~~ | | | | | (2) 'setjmp' called here | 'main': events 3-5 | - | NN | if (!setjmp(buf)) + | NN | if (!SETJMP(buf)) | | ^ | | | | | (3) following 'true' branch... @@ -87,14 +87,14 @@ int main (void) | 'main': event 10 | - | NN | if (!setjmp(buf)) + | NN | if (!SETJMP(buf)) | | ^~~~~~ | | | | | (10) ...to 'setjmp' in 'main' (saved at (2)) | 'main': events 11-13 | - | NN | if (!setjmp(buf)) + | NN | if (!SETJMP(buf)) | | ^ | | | | | (11) following 'false' branch... diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-5.c b/gcc/testsuite/gcc.dg/analyzer/setjmp-5.c index 2c41e6dff77..3ee02980e57 100644 --- a/gcc/testsuite/gcc.dg/analyzer/setjmp-5.c +++ b/gcc/testsuite/gcc.dg/analyzer/setjmp-5.c @@ -1,7 +1,7 @@ /* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */ /* { dg-enable-nn-line-numbers "" } */ -#include +#include "test-setjmp.h" #include #include "analyzer-decls.h" @@ -9,7 +9,7 @@ static jmp_buf env; static void inner (void) { - setjmp (env); + SETJMP (env); } void outer (void) @@ -45,7 +45,7 @@ void outer (void) | 'inner': event 4 | - | NN | setjmp (env); + | NN | SETJMP (env); | | ^~~~~~ | | | | | (4) 'setjmp' called here diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-6.c b/gcc/testsuite/gcc.dg/analyzer/setjmp-6.c index d7319129070..0e0f12f919c 100644 --- a/gcc/testsuite/gcc.dg/analyzer/setjmp-6.c +++ b/gcc/testsuite/gcc.dg/analyzer/setjmp-6.c @@ -1,4 +1,4 @@ -#include +#include "test-setjmp.h" #include #include @@ -19,7 +19,7 @@ void outer (void) foo (0); - i = setjmp(env); + i = SETJMP(env); if (i == 0) { diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-7.c b/gcc/testsuite/gcc.dg/analyzer/setjmp-7.c index 3a14534434d..6cf98247bb6 100644 --- a/gcc/testsuite/gcc.dg/analyzer/setjmp-7.c +++ b/gcc/testsuite/gcc.dg/analyzer/setjmp-7.c @@ -1,4 +1,4 @@ -#include +#include "test-setjmp.h" #include #include @@ -24,7 +24,7 @@ void outer (void) foo (0); - i = setjmp(env); + i = SETJMP(env); if (i == 0) { diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c b/gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c index 1e2c348af3e..87d35bc88f3 100644 --- a/gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c +++ b/gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c @@ -1,7 +1,7 @@ /* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */ /* { dg-enable-nn-line-numbers "" } */ -#include +#include "test-setjmp.h" #include extern int foo (int) __attribute__ ((__pure__)); @@ -26,7 +26,7 @@ void outer (void) foo (0); - i = setjmp(env); + i = SETJMP(env); if (i == 0) { @@ -49,7 +49,7 @@ void outer (void) | 'outer': event 2 | - | NN | i = setjmp(env); + | NN | i = SETJMP(env); | | ^~~~~~ | | | | | (2) 'setjmp' called here @@ -103,7 +103,7 @@ void outer (void) | 'outer': event 12 | - | NN | i = setjmp(env); + | NN | i = SETJMP(env); | | ^~~~~~ | | | | | (12) ...to 'setjmp' in 'outer' (saved at (2)) diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-8.c b/gcc/testsuite/gcc.dg/analyzer/setjmp-8.c index fb931653803..abbee2d9108 100644 --- a/gcc/testsuite/gcc.dg/analyzer/setjmp-8.c +++ b/gcc/testsuite/gcc.dg/analyzer/setjmp-8.c @@ -1,7 +1,7 @@ /* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */ /* { dg-enable-nn-line-numbers "" } */ -#include +#include "test-setjmp.h" #include #include "analyzer-decls.h" @@ -21,7 +21,7 @@ void outer (void) foo (0); - i = setjmp(env); + i = SETJMP(env); if (i != 0) { @@ -48,7 +48,7 @@ void outer (void) | 'outer': event 2 | - | NN | i = setjmp(env); + | NN | i = SETJMP(env); | | ^~~~~~ | | | | | (2) 'setjmp' called here @@ -85,7 +85,7 @@ void outer (void) | 'outer': event 8 | - | NN | i = setjmp(env); + | NN | i = SETJMP(env); | | ^~~~~~ | | | | | (8) ...to 'setjmp' in 'outer' (saved at (2)) diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-9.c b/gcc/testsuite/gcc.dg/analyzer/setjmp-9.c index fa2d3152c27..cf75d3ad896 100644 --- a/gcc/testsuite/gcc.dg/analyzer/setjmp-9.c +++ b/gcc/testsuite/gcc.dg/analyzer/setjmp-9.c @@ -1,7 +1,7 @@ /* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */ /* { dg-enable-nn-line-numbers "" } */ -#include +#include "test-setjmp.h" #include #include "analyzer-decls.h" @@ -23,7 +23,7 @@ void outer (void) foo (0); - i = setjmp(env); + i = SETJMP(env); if (i != 0) { @@ -50,7 +50,7 @@ void outer (void) | 'outer': event 2 | - | NN | i = setjmp(env); + | NN | i = SETJMP(env); | | ^~~~~~ | | | | | (2) 'setjmp' called here @@ -87,7 +87,7 @@ void outer (void) | 'outer': event 8 | - | NN | i = setjmp(env); + | NN | i = SETJMP(env); | | ^~~~~~ | | | | | (8) ...to 'setjmp' in 'outer' (saved at (2)) diff --git a/gcc/testsuite/gcc.dg/analyzer/test-setjmp.h b/gcc/testsuite/gcc.dg/analyzer/test-setjmp.h new file mode 100644 index 00000000000..ee0e1ec7d75 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/test-setjmp.h @@ -0,0 +1,16 @@ +/* Various integration tests for setjmp-handling expect a precise + multiline output. + + The outputs from -fdiagnostics-path-format=inline-events for such + setjmp tests are dependent on whether setjmp is a macro or a function + (and whether that macro is defined in a system header). + + setjmp is a function on some systems and a macro on others. + This header provides a SETJMP macro in a (fake) system header, + for consistency of output across such systems. */ + +#include + +#pragma GCC system_header + +#define SETJMP(E) setjmp(E) -- 2.30.2