public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Testsuite: fix analyzer tests on Darwin
@ 2023-08-19 21:28 FX Coudert
  2023-08-19 22:10 ` Iain Sandoe
  0 siblings, 1 reply; 2+ messages in thread
From: FX Coudert @ 2023-08-19 21:28 UTC (permalink / raw)
  To: gcc-patches; +Cc: dmalcolm, Iain Sandoe

[-- Attachment #1: Type: text/plain, Size: 747 bytes --]

Hi,

gcc.dg/analyzer/ currently has 80 failures on Darwin (both x86_64-apple-darwin and aarch64-apple-darwin). All those come from two issues:

1. Many tests use memset() without including the <string.h> header. We can fix that easily.

2. Other tests fail because of the use of macOS headers, which redefine functions like memcpy and others to “checked”/fortified versions https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104042 Instead of correcting this on a case-by-case basis, add the -D_FORTIFY_SOURCE=0 flag systematically on Darwin.

With that, all 80 failures are silenced and that part of the testsuite is now clean:

# of expected passes 5238
# of expected failures 194
# of unsupported tests 12



OK to commit?
FX


[-- Attachment #2: 0001-Testsuite-fix-analyzer-tests-on-Darwin.patch --]
[-- Type: application/octet-stream, Size: 6166 bytes --]

From 6c40e2153d986e4ac3d40c74c7f839408170f8bf Mon Sep 17 00:00:00 2001
From: Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Date: Sat, 19 Aug 2023 23:22:06 +0200
Subject: [PATCH] Testsuite: fix analyzer tests on Darwin

On macOS, system headers redefine by default some macros (memcpy,
memmove, etc) to checked versions, which defeats the analyzer. We
want to turn this off.
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104042

gcc/testsuite/ChangeLog:

	PR analyzer/104042
	* analyzer.exp: Pass -D_FORTIFY_SOURCE=0 on Darwin.
	* fd-bind.c: Add missing <string.h> header.
	* fd-datagram-socket.c: Likewise.
	* fd-listen.c: Likewise.
	* fd-socket-misuse.c: Likewise.
	* fd-stream-socket-active-open.c: Likewise.
	* fd-stream-socket-passive-open.c: Likewise.
	* fd-stream-socket.c: Likewise.
	* fd-symbolic-socket.c: Likewise.
---
 gcc/testsuite/gcc.dg/analyzer/analyzer.exp                | 8 ++++++++
 gcc/testsuite/gcc.dg/analyzer/fd-bind.c                   | 1 +
 gcc/testsuite/gcc.dg/analyzer/fd-datagram-socket.c        | 1 +
 gcc/testsuite/gcc.dg/analyzer/fd-listen.c                 | 1 +
 gcc/testsuite/gcc.dg/analyzer/fd-socket-misuse.c          | 1 +
 .../gcc.dg/analyzer/fd-stream-socket-active-open.c        | 1 +
 .../gcc.dg/analyzer/fd-stream-socket-passive-open.c       | 1 +
 gcc/testsuite/gcc.dg/analyzer/fd-stream-socket.c          | 1 +
 gcc/testsuite/gcc.dg/analyzer/fd-symbolic-socket.c        | 1 +
 9 files changed, 16 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer.exp b/gcc/testsuite/gcc.dg/analyzer/analyzer.exp
index 76569267af0..af05c98fa16 100644
--- a/gcc/testsuite/gcc.dg/analyzer/analyzer.exp
+++ b/gcc/testsuite/gcc.dg/analyzer/analyzer.exp
@@ -32,6 +32,14 @@ if [info exists DEFAULT_CFLAGS] then {
 # If a testcase doesn't have special options, use these.
 set DEFAULT_CFLAGS "-fanalyzer -Wanalyzer-too-complex -fanalyzer-call-summaries"
 
+if { [istarget "*-*-darwin*" ] } {
+  # On macOS, system headers redefine by default some macros (memcpy,
+  # memmove, etc) to checked versions, which defeats the analyzer. We
+  # want to turn this off.
+  # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104042
+  set DEFAULT_CFLAGS "$DEFAULT_CFLAGS -D_FORTIFY_SOURCE=0"
+}
+
 # Initialize `dg'.
 dg-init
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-bind.c b/gcc/testsuite/gcc.dg/analyzer/fd-bind.c
index 184a471f0b2..2a5cee58230 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-bind.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-bind.c
@@ -1,6 +1,7 @@
 /* { dg-require-effective-target sockets } */
 /* { dg-skip-if "" { powerpc*-*-aix* } } */
 
+#include <string.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-datagram-socket.c b/gcc/testsuite/gcc.dg/analyzer/fd-datagram-socket.c
index 6546df1962c..59e80c831e3 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-datagram-socket.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-datagram-socket.c
@@ -1,6 +1,7 @@
 /* { dg-require-effective-target sockets } */
 /* { dg-skip-if "" { powerpc*-*-aix* } } */
 
+#include <string.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-listen.c b/gcc/testsuite/gcc.dg/analyzer/fd-listen.c
index e47c3f628d1..3ac7a990042 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-listen.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-listen.c
@@ -1,6 +1,7 @@
 /* { dg-require-effective-target sockets } */
 /* { dg-skip-if "" { powerpc*-*-aix* } } */
 
+#include <string.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-socket-misuse.c b/gcc/testsuite/gcc.dg/analyzer/fd-socket-misuse.c
index 4b427d69a78..87e8967ff21 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-socket-misuse.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-socket-misuse.c
@@ -3,6 +3,7 @@
 /* { dg-require-effective-target sockets } */
 /* { dg-skip-if "" { powerpc*-*-aix* } } */
 
+#include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-stream-socket-active-open.c b/gcc/testsuite/gcc.dg/analyzer/fd-stream-socket-active-open.c
index 4ec58217360..b39dbf85c3d 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-stream-socket-active-open.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-stream-socket-active-open.c
@@ -1,6 +1,7 @@
 /* { dg-require-effective-target sockets } */
 /* { dg-skip-if "" { powerpc*-*-aix* } } */
 
+#include <string.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-stream-socket-passive-open.c b/gcc/testsuite/gcc.dg/analyzer/fd-stream-socket-passive-open.c
index 102e4350f45..e161098b96b 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-stream-socket-passive-open.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-stream-socket-passive-open.c
@@ -5,6 +5,7 @@
 /* { dg-require-effective-target sockets } */
 /* { dg-skip-if "" { powerpc*-*-aix* } } */
 
+#include <string.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-stream-socket.c b/gcc/testsuite/gcc.dg/analyzer/fd-stream-socket.c
index d458708aea0..7e0e26ab40b 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-stream-socket.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-stream-socket.c
@@ -1,6 +1,7 @@
 /* { dg-require-effective-target sockets } */
 /* { dg-skip-if "" { powerpc*-*-aix* } } */
 
+#include <string.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-symbolic-socket.c b/gcc/testsuite/gcc.dg/analyzer/fd-symbolic-socket.c
index 4479cc965ab..d7dc46a2d47 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-symbolic-socket.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-symbolic-socket.c
@@ -1,6 +1,7 @@
 /* { dg-require-effective-target sockets } */
 /* { dg-skip-if "" { powerpc*-*-aix* } } */
 
+#include <string.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
-- 
2.39.2 (Apple Git-143)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Testsuite: fix analyzer tests on Darwin
  2023-08-19 21:28 [PATCH] Testsuite: fix analyzer tests on Darwin FX Coudert
@ 2023-08-19 22:10 ` Iain Sandoe
  0 siblings, 0 replies; 2+ messages in thread
From: Iain Sandoe @ 2023-08-19 22:10 UTC (permalink / raw)
  To: FX Coudert; +Cc: GCC Patches, dmalcolm

Hi FX,

thanks for chasing these fails down,

> On 19 Aug 2023, at 22:28, FX Coudert <fxcoudert@gmail.com> wrote:
> 

> gcc.dg/analyzer/ currently has 80 failures on Darwin (both x86_64-apple-darwin and aarch64-apple-darwin). All those come from two issues:
> 
> 1. Many tests use memset() without including the <string.h> header. We can fix that easily.
> 
> 2. Other tests fail because of the use of macOS headers, which redefine functions like memcpy and others to “checked”/fortified versions https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104042 Instead of correcting this on a case-by-case basis, add the -D_FORTIFY_SOURCE=0 flag systematically on Darwin.
> 
> With that, all 80 failures are silenced and that part of the testsuite is now clean:
> 
> # of expected passes 5238
> # of expected failures 194
> # of unsupported tests 12

> OK to commit?

LGTM,

Iain

> FX
> 
> <0001-Testsuite-fix-analyzer-tests-on-Darwin.patch>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-19 22:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-19 21:28 [PATCH] Testsuite: fix analyzer tests on Darwin FX Coudert
2023-08-19 22:10 ` Iain Sandoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).