Some target C libraries that aren't recognized as freestanding don't
have filesystem support, so calling tmpnam, fopen/open and
remove/unlink fails to link.

This patch introduces a tmpnam effective target to the testsuite, and
requires it in the tests that call tmpnam.

Tested on x86_64-linux-gnu, and with a cross to arm-eabi.
Ok to install?


for  gcc/testsuite/ChangeLog

        * lib/target-supports.exp (check_effective_target_tmpnam): New.
        * gcc.c-torture/execute/fprintf-2.c: Require it.
        * gcc.c-torture/execute/printf-2.c: Likewise.
        * gcc.c-torture/execute/user-printf.c: Likewise.
---
 gcc/testsuite/gcc.c-torture/execute/fprintf-2.c   |    1 +
 gcc/testsuite/gcc.c-torture/execute/printf-2.c    |    1 +
 gcc/testsuite/gcc.c-torture/execute/user-printf.c |    1 +
 gcc/testsuite/lib/target-supports.exp             |   14 ++++++++++++++
 4 files changed, 17 insertions(+)

diff --git a/gcc/testsuite/gcc.c-torture/execute/fprintf-2.c 
b/gcc/testsuite/gcc.c-torture/execute/fprintf-2.c
index c723867..815109b 100644
--- a/gcc/testsuite/gcc.c-torture/execute/fprintf-2.c
+++ b/gcc/testsuite/gcc.c-torture/execute/fprintf-2.c
@@ -1,6 +1,7 @@
 /* Verify that calls to fprintf don't get eliminated even if their
    result on success can be computed at compile time (they can fail).
    The calls can still be transformed into those of other functions.
+   { dg-require-effective-target tmpnam }
    { dg-prune-output "warning: warning: \[^\n\r\]* possibly used unsafely" }
    { dg-skip-if "requires io" { avr-*-* } }
    { dg-skip-if "requires io" { freestanding } } */
diff --git a/gcc/testsuite/gcc.c-torture/execute/printf-2.c 
b/gcc/testsuite/gcc.c-torture/execute/printf-2.c
index 57f467e..02787ec1 100644
--- a/gcc/testsuite/gcc.c-torture/execute/printf-2.c
+++ b/gcc/testsuite/gcc.c-torture/execute/printf-2.c
@@ -2,6 +2,7 @@
    result on success can be computed at compile time (they can fail).
    The calls can still be transformed into those of other functions.
    { dg-require-effective-target unwrapped }
+   { dg-require-effective-target tmpnam }
    { dg-prune-output "warning: warning: \[^\n\r\]* possibly used unsafely" }
    { dg-skip-if "requires io" { avr-*-* } }
    { dg-skip-if "requires io" { freestanding } } */
diff --git a/gcc/testsuite/gcc.c-torture/execute/user-printf.c 
b/gcc/testsuite/gcc.c-torture/execute/user-printf.c
index 006d99e..5f40f98 100644
--- a/gcc/testsuite/gcc.c-torture/execute/user-printf.c
+++ b/gcc/testsuite/gcc.c-torture/execute/user-printf.c
@@ -2,6 +2,7 @@
    don't get eliminated even if their result on success can be computed at
    compile time (they can fail).
    { dg-require-effective-target unwrapped }
+   { dg-require-effective-target tmpnam }
    { dg-prune-output "warning: warning: \[^\n\r\]* possibly used unsafely" }
    { dg-skip-if "requires io" { avr-*-* } }
    { dg-skip-if "requires io" { freestanding } } */
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index e42d0ea..8bde03a 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -751,6 +751,20 @@ proc check_effective_target_freestanding { } {
     return 0
 }
 
+# Check to see that tmpnam() and other I/O functions normally used
+# with it are available.
+proc check_effective_target_tmpnam { } {
+    return [check_no_compiler_messages tmpnam_available executable {
+#include <stdio.h>
+int main() {
+    char *n = tmpnam (NULL);
+    FILE *f = fopen (n, "w");
+    fclose (f);
+    remove (n);
+    return 0;
+} } ""]
+}
+
 # Return 1 if target has packed layout of structure members by
 # default, 0 otherwise.  Note that this is slightly different than
 # whether the target has "natural alignment": both attributes may be

-- 
Alexandre Oliva, freedom fighter    he/him    https://FSFLA.org/blogs/lxo/
Free Software Evangelist              Stallman was right, but he's left :(
GNU Toolchain Engineer           Live long and free, and prosper ethically

Reply via email to