]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite, c, Darwin: Fix suprious fails in mk*temp* tests.
authorIain Sandoe <iain@sandoe.co.uk>
Mon, 1 Jun 2026 23:13:07 +0000 (00:13 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Sat, 6 Jun 2026 14:22:27 +0000 (15:22 +0100)
Since there is a mixture of Posix and unspecified functions in this
group, it appears to have precipitated placement in two different
headers (stdlib and unistd).  Include both to cater for this.

Darwin also emits a deprecation warning for mktemp.

gcc/testsuite/ChangeLog:

* gcc.dg/analyzer/mkdtemp-1.c: Add unistd header.
* gcc.dg/analyzer/mkstemps-1.c: Likewise.
* gcc.dg/analyzer/mktemp-1.c: Handle deprecation warnings.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/testsuite/gcc.dg/analyzer/mkdtemp-1.c
gcc/testsuite/gcc.dg/analyzer/mkstemps-1.c
gcc/testsuite/gcc.dg/analyzer/mktemp-1.c

index da77ce78651604d9474d93b816fddf165f7400c1..2cc339b9a65e6599f03ae9956b8fa90a3b67e7cf 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <errno.h>
 #include "analyzer-decls.h"
 
index 75fcb9dbb08d0822b2f5bc86b094f5516f2592b8..6f1e7ef3e7330f38b170519db0a25b24dca64003 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 extern void populate (char *buf);
 
index 0f4b448a6aa6d1eb822e08ff3ddeef5f60ecb62d..0f1122a06ed84ee783db10560b3faf24363cf529 100644 (file)
@@ -3,7 +3,7 @@
 /* TODO: mktemp is deprecated per MSC24-C
    (https://wiki.sei.cmu.edu/confluence/x/hNYxBQ).
    Once a warning for deprecated functions exists, mktemp should
-   also warn about its use.  */
+   also warn about its use.  Later versions of Darwin do warn here.  */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -15,40 +15,47 @@ extern void populate (char *buf);
 void test_passthrough (char *s)
 {
   mktemp (s);
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
 }
 
 void test_string_literal_correct_placeholder (void)
 {
   mktemp ("/home/user/sessXXXXXX"); /* { dg-warning "'mktemp' on a string literal \\\[STR30-C\\\]" } */
-  /* { dg-message "use a writable character array" "fix suggestion" { target *-*-* } .-1 } */
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
+  /* { dg-message "use a writable character array" "fix suggestion" { target *-*-* } .-2 } */
 }
 
 void test_string_literal_missing_placeholder (void)
 {
   mktemp ("/home/user/sess"); /* { dg-warning "'mktemp' on a string literal \\\[STR30-C\\\]" } */
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
 }
 
 void test_string_literal_empty (void)
 {
   mktemp (""); /* { dg-warning "'mktemp' on a string literal \\\[STR30-C\\\]" } */
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
 }
 
 void test_correct (void)
 {
   char tmpl[] = "/var/run/sock.XXXXXX";
   mktemp (tmpl);
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
 }
 
 void test_correct_minimal (void)
 {
   char tmpl[] = "XXXXXX";
   mktemp (tmpl);
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
 }
 
 void test_correct_offset_into_buffer (void)
 {
   char buf[] = "////XXXXXX";
   mktemp (buf + 4);
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
 }
 
 void test_missing_placeholder_offset_into_buffer (void)
@@ -56,36 +63,42 @@ void test_missing_placeholder_offset_into_buffer (void)
   char buf[] = "////XXXXXX";
   /* Placeholder is incorrect from the pointer's perspective.  */
   mktemp (buf + 5); /* { dg-warning "'mktemp' template string does not end with 'XXXXXX'" } */
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
 }
 
 void test_missing_placeholder (void)
 {
   char tmpl[] = "/var/run/sock";
   mktemp (tmpl); /* { dg-warning "'mktemp' template string does not end with 'XXXXXX'" } */
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
 }
 
 void test_too_short (void)
 {
   char tmpl[] = "XY";
   mktemp (tmpl); /* { dg-warning "'mktemp' template string does not end with 'XXXXXX'" } */
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
 }
 
 void test_empty_buffer (void)
 {
   char tmpl[] = "";
   mktemp (tmpl); /* { dg-warning "'mktemp' template string does not end with 'XXXXXX'" } */
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
 }
 
 void test_partial_placeholder (void)
 {
   char tmpl[] = "/var/run/sockXXXXX-";
   mktemp (tmpl); /* { dg-warning "'mktemp' template string does not end with 'XXXXXX'" } */
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
 }
 
 void test_four_xs (void)
 {
   char tmpl[] = "/var/run/sockXXXX";
   mktemp (tmpl); /* { dg-warning "'mktemp' template string does not end with 'XXXXXX'" } */
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
 }
 
 void test_populated_buf (void)
@@ -93,11 +106,13 @@ void test_populated_buf (void)
   char tmpl[24];
   populate (tmpl);
   mktemp (tmpl);
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
 }
 
 void test_NULL (void)
 {
   mktemp (NULL); /* possibly -Wanalyzer-null-argument */
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
 }
 
 void test_errno_bad_template (void)
@@ -105,6 +120,7 @@ void test_errno_bad_template (void)
   errno = 0;
   char tmpl[] = "/tmp/foo";
   char *result = mktemp (tmpl); /* { dg-warning "'mktemp' template string does not end with 'XXXXXX'" } */
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
   __analyzer_eval (errno > 0); /* { dg-warning "TRUE" } */
 }
 
@@ -112,6 +128,7 @@ void test_failure_nul_byte (void)
 {
   char tmpl[] = "/tmp/foo";
   char *result = mktemp (tmpl); /* { dg-warning "'mktemp' template string does not end with 'XXXXXX'" } */
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
   __analyzer_eval (result[0] == '\0'); /* { dg-warning "TRUE" } */
   __analyzer_eval (result == tmpl); /* { dg-warning "TRUE" } */
 }
@@ -120,6 +137,7 @@ void test_success_path (void)
 {
   char tmpl[] = "/tmp/testXXXXXX";
   char *result = mktemp (tmpl);
+  /* { dg-warning {'mktemp' is deprecated:} "" { target *-*-darwin2* } .-1 } */
   if (result[0] != '\0')
     __analyzer_eval (result == tmpl); /* { dg-warning "TRUE" } */
 }