[committed] analyzer: testsuite fixes for alloca, getpass, and setjmp (PR 93316)

Message ID 20200122193513.20973-1-dmalcolm@redhat.com
State New
Headers show
Series
  • [committed] analyzer: testsuite fixes for alloca, getpass, and setjmp (PR 93316)
Related show

Commit Message

David Malcolm Jan. 22, 2020, 7:35 p.m.
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.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu;
tested on stage 1 on sparc-sun-solaris2.11.

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 <alloca.h>.
	* 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 <alloca.h>.
	* gcc.dg/analyzer/sensitive-1.c: Define __EXTENSIONS__ before
	including unistd.h.
	* gcc.dg/analyzer/setjmp-2.c: Replace include of <setjmp.h>
	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/analyzer.cc                         |  3 ++-
 gcc/testsuite/gcc.dg/analyzer/data-model-1.c     |  1 +
 gcc/testsuite/gcc.dg/analyzer/malloc-1.c         |  1 +
 gcc/testsuite/gcc.dg/analyzer/malloc-callbacks.c |  4 +++-
 gcc/testsuite/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 ++++++++++++++++
 16 files changed, 62 insertions(+), 36 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/test-setjmp.h

-- 
2.21.0

Comments

Jakub Jelinek Jan. 22, 2020, 7:40 p.m. | #1
On Wed, Jan 22, 2020 at 02:35:13PM -0500, David Malcolm wrote:
> 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.

> 

> Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu;

> tested on stage 1 on sparc-sun-solaris2.11.

> 

> gcc/analyzer/ChangeLog:

> 	PR analyzer/93316

> 	* analyzer.cc (is_setjmp_call_p): Check for "setjmp" as well as

> 	"_setjmp".


Please see calls.c (special_function_p), you should treat certainly
also sigsetjmp as a setjmp call, and similarly to special_function_p,
skip over _ or __ prefixes before the setjmp or sigsetjmp name.
Similarly for longjmp/siglongjmp.

	Jakub

Patch

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 <const gcall *> (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/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 <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include <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 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 <alloca.h>
 #include <stdlib.h>
 #include <string.h>
 
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 <stddef.h>
+#include <alloca.h>
 #include <stdlib.h>
 
 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 <stdio.h>
+
+/* Solaris needs this for <unistd.h> to declare getpass.  */
+#define __EXTENSIONS__
 #include <unistd.h>
+
 #include <string.h>
 
 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 <setjmp.h>
+#include "test-setjmp.h"
 #include <stddef.h>
 #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 <setjmp.h>
 #include <stddef.h>
+#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 <setjmp.h>
+#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 <setjmp.h>
+#include "test-setjmp.h"
 #include <stddef.h>
 #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 <setjmp.h>
+#include "test-setjmp.h"
 #include <stddef.h>
 #include <stdlib.h>
 
@@ -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 <setjmp.h>
+#include "test-setjmp.h"
 #include <stddef.h>
 #include <stdlib.h>
 
@@ -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 <setjmp.h>
+#include "test-setjmp.h"
 #include <stdlib.h>
 
 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 <setjmp.h>
+#include "test-setjmp.h"
 #include <stddef.h>
 #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 <setjmp.h>
+#include "test-setjmp.h"
 #include <stddef.h>
 #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 <setjmp.h>
+
+#pragma GCC system_header
+
+#define SETJMP(E) setjmp(E)