diff mbox series

introduce target tmpnam and require it in tests relying on it

Message ID oro8s09x58.fsf@livre.home
State New
Headers show
Series introduce target tmpnam and require it in tests relying on it | expand

Commit Message

Alexandre Oliva April 9, 2020, 9:17 p.m. UTC
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(+)

Comments

Alexandre Oliva April 17, 2020, 5:48 p.m. UTC | #1
On Apr  9, 2020, Alexandre Oliva <oliva@adacore.com> wrote:

> 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.

Ping?

https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543672.html
Martin Sebor April 17, 2020, 7:21 p.m. UTC | #2
On 4/17/20 11:48 AM, Alexandre Oliva wrote:
> On Apr  9, 2020, Alexandre Oliva <oliva@adacore.com> wrote:
> 
>> 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.
> 
> Ping?
> 
> https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543672.html

I'm okay with the changes to the tests.

The target-supports.exp changes look reasonable to me as well but
I can't approve them.  Since you said it's for targets that don't
have file I/O functions I wonder if the name would better reflect
that if it were called, say, check_effective_target_fileio?

I don't expect it's necessary to worry about handling errors in
the .exp test.

Martin
Bernhard Reutner-Fischer April 21, 2020, 9:50 a.m. UTC | #3
On 17 April 2020 21:21:41 CEST, Martin Sebor via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>On 4/17/20 11:48 AM, Alexandre Oliva wrote:
>> On Apr  9, 2020, Alexandre Oliva <oliva@adacore.com> wrote:
>> 
>>> 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.
>> 
>> Ping?
>> 
>> https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543672.html
>
>I'm okay with the changes to the tests.
>
>The target-supports.exp changes look reasonable to me as well but
>I can't approve them.  Since you said it's for targets that don't
>have file I/O functions I wonder if the name would better reflect
>that if it were called, say, check_effective_target_fileio?

Since tmpnam is obsolescent in SUSv4 and hence a libc is fine to omit it, I'd rather fix the tests to use functions that are known to stay.

If you want a fileio predicate then please do not keys it off obsolescent functions.

TIA,
>
>I don't expect it's necessary to worry about handling errors in
>the .exp test.
>
>Martin
Martin Sebor April 21, 2020, 2:59 p.m. UTC | #4
On 4/21/20 3:50 AM, Bernhard Reutner-Fischer wrote:
> On 17 April 2020 21:21:41 CEST, Martin Sebor via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>> On 4/17/20 11:48 AM, Alexandre Oliva wrote:
>>> On Apr  9, 2020, Alexandre Oliva <oliva@adacore.com> wrote:
>>>
>>>> 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.
>>>
>>> Ping?
>>>
>>> https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543672.html
>>
>> I'm okay with the changes to the tests.
>>
>> The target-supports.exp changes look reasonable to me as well but
>> I can't approve them.  Since you said it's for targets that don't
>> have file I/O functions I wonder if the name would better reflect
>> that if it were called, say, check_effective_target_fileio?
> 
> Since tmpnam is obsolescent in SUSv4 and hence a libc is fine to omit it, I'd rather fix the tests to use functions that are known to stay.

I would be okay with replacing tmpnam with something else, although
I don't think it's necessary.  tmpnam is a standard C function that
conforming C (and so POSIX) implementation are required to provide.

Martin

> 
> If you want a fileio predicate then please do not keys it off obsolescent functions.
> 
> TIA,
>>
>> I don't expect it's necessary to worry about handling errors in
>> the .exp test.
>>
>> Martin
>
Bernhard Reutner-Fischer April 22, 2020, 8:03 a.m. UTC | #5
On Tue, 21 Apr 2020 at 16:59, Martin Sebor <msebor@gmail.com> wrote:

> >>> https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543672.html
> >>
> >> I'm okay with the changes to the tests.
> >>
> >> The target-supports.exp changes look reasonable to me as well but
> >> I can't approve them.  Since you said it's for targets that don't
> >> have file I/O functions I wonder if the name would better reflect
> >> that if it were called, say, check_effective_target_fileio?
> >
> > Since tmpnam is obsolescent in SUSv4 and hence a libc is fine to omit it, I'd rather fix the tests to use functions that are known to stay.
>
> I would be okay with replacing tmpnam with something else, although
> I don't think it's necessary.  tmpnam is a standard C function that
> conforming C (and so POSIX) implementation are required to provide.

IMO it's perfectly fine to omit obsolescent functions from a
conforming implementation ¹).
But one should use the recommended replacement functions either way,
e.g. mkstemp ²)

thanks,
¹)
[OB] [Option Start] Obsolescent [Option End]
The functionality described may be removed in a future version of this
volume of POSIX.1-2017. Strictly Conforming POSIX Applications and
Strictly Conforming XSI Applications shall not use obsolescent
features.
²)
https://pubs.opengroup.org/onlinepubs/9699919799/functions/tmpnam.html
---8<---
APPLICATION USAGE
  Applications should use the tmpfile(), mkstemp(), or mkdtemp()
functions instead of the obsolescent tmpnam() function.
---8<---
Martin Sebor April 22, 2020, 2:31 p.m. UTC | #6
On 4/22/20 2:03 AM, Bernhard Reutner-Fischer wrote:
> On Tue, 21 Apr 2020 at 16:59, Martin Sebor <msebor@gmail.com> wrote:
> 
>>>>> https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543672.html
>>>>
>>>> I'm okay with the changes to the tests.
>>>>
>>>> The target-supports.exp changes look reasonable to me as well but
>>>> I can't approve them.  Since you said it's for targets that don't
>>>> have file I/O functions I wonder if the name would better reflect
>>>> that if it were called, say, check_effective_target_fileio?
>>>
>>> Since tmpnam is obsolescent in SUSv4 and hence a libc is fine to omit it, I'd rather fix the tests to use functions that are known to stay.
>>
>> I would be okay with replacing tmpnam with something else, although
>> I don't think it's necessary.  tmpnam is a standard C function that
>> conforming C (and so POSIX) implementation are required to provide.
> 
> IMO it's perfectly fine to omit obsolescent functions from a
> conforming implementation ¹).

No, it's not (the note you quoted below notwithstanding), certainly
not for C features.  In particular for tmpnam (and all other standard
C99 APIs), the POSIX description states

   The functionality described on this reference page is aligned with
   the ISO C standard. Any conflict between the requirements described
   here and the ISO C standard is unintentional. This volume of
   POSIX.1-2008 defers to the ISO C standard.

Since C99 (which is subsumed by POSXI) as well as subsequent revisions
of C require tmpnam to be provided by conforming implementation, so does
POSIX.

> But one should use the recommended replacement functions either way,
> e.g. mkstemp ²)

I wouldn't have a problem with using mkstemp in the tests but I don't
view it as important or, since it's a POSIX only API, necessarily even
the best choice for portability.

> 
> thanks,
> ¹)
> [OB] [Option Start] Obsolescent [Option End]
> The functionality described may be removed in a future version of this
> volume of POSIX.1-2017. Strictly Conforming POSIX Applications and
> Strictly Conforming XSI Applications shall not use obsolescent
> features.

Nothing here suggests that a conforming POSIX implementation need
not provide obsolescent features.  The SUSv4 guide further clarifies
the meaning of obsolescence by saying:

   OB
   Obsolescent
   Features marked as obsolescent are portable to all Single UNIX
   Specification platforms, but may be withdrawn in a future issue.
   This functionality should be avoided.

Since future SUS issues will unavoidably continue to incorporate
C, C features made obsolescent in POSIX cannot be removed until
they are also removed from C.  And since tmpnam is not obsolescent
in C17 and no proposal has been submitted to make it so in C2X,
chances are that the function will continue to be required by
POSIX for the foreseeable future as well.

Martin

> ²)
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/tmpnam.html
> ---8<---
> APPLICATION USAGE
>    Applications should use the tmpfile(), mkstemp(), or mkdtemp()
> functions instead of the obsolescent tmpnam() function.
> ---8<---
>
Li, Pan2 via Gcc-patches April 22, 2020, 6:12 p.m. UTC | #7
On Fri, 2020-04-17 at 14:48 -0300, Alexandre Oliva wrote:
> On Apr  9, 2020, Alexandre Oliva <oliva@adacore.com> wrote:
> 
> > 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.
> 
> Ping?
> 
> https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543672.html
OK.
jeff
Alexandre Oliva April 23, 2020, 8:21 a.m. UTC | #8
On Apr 21, 2020, Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote:

> On 17 April 2020 21:21:41 CEST, Martin Sebor via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
>> On 4/17/20 11:48 AM, Alexandre Oliva wrote:
>>> On Apr  9, 2020, Alexandre Oliva <oliva@adacore.com> wrote:
>>> 
>>>> 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.

>>>> 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.
>>> 
>>> Ping?
>>> 
>>> https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543672.html
>> 
>> I'm okay with the changes to the tests.
>> 
>> The target-supports.exp changes look reasonable to me as well but
>> I can't approve them.  Since you said it's for targets that don't
>> have file I/O functions I wonder if the name would better reflect
>> that if it were called, say, check_effective_target_fileio?

> If you want a fileio predicate then please do not keys it off obsolescent functions.

I'd actually considered adding two expect/dejagnu procs, one for fileio,
one for tmpnam, possibly with the latter depending on the former, but
decided to take the simpler path on the grounds that all tests that
would have depended on fileio would also depend on tmpnam.

Plus, it did seem to make sense to test for tmpnam, since it probably
won't be found on freestanding environments (the affected tests require
non-freestanding effective target, but that translate to requiring I/O
support), and tmpnam might be removed from standards in the future.  We
might want to catch that, rather than silently skip the test, though.

I'd be glad to add an intermediate fileio effective target, or rename
the proposed one and drop tmpnam from it, if there's agreement such a
separate effective target would be more useful.


So, should I rename _tmpnam to _fileio and drop tmpnam() from the code
snippet in the effective target test?  Or should I keep _tmpnam and
introduce _fileio?  With or without a dependency of _tmpnam on _fileio?

Since Jeff Law approved the patch as is, would you guys mind if I make
any further changes as separate, followup patches?

Thanks,
Martin Sebor April 23, 2020, 5:19 p.m. UTC | #9
On 4/23/20 2:21 AM, Alexandre Oliva wrote:
> On Apr 21, 2020, Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote:
> 
>> On 17 April 2020 21:21:41 CEST, Martin Sebor via Gcc-patches
>> <gcc-patches@gcc.gnu.org> wrote:
>>> On 4/17/20 11:48 AM, Alexandre Oliva wrote:
>>>> On Apr  9, 2020, Alexandre Oliva <oliva@adacore.com> wrote:
>>>>
>>>>> 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.
> 
>>>>> 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.
>>>>
>>>> Ping?
>>>>
>>>> https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543672.html
>>>
>>> I'm okay with the changes to the tests.
>>>
>>> The target-supports.exp changes look reasonable to me as well but
>>> I can't approve them.  Since you said it's for targets that don't
>>> have file I/O functions I wonder if the name would better reflect
>>> that if it were called, say, check_effective_target_fileio?
> 
>> If you want a fileio predicate then please do not keys it off obsolescent functions.
> 
> I'd actually considered adding two expect/dejagnu procs, one for fileio,
> one for tmpnam, possibly with the latter depending on the former, but
> decided to take the simpler path on the grounds that all tests that
> would have depended on fileio would also depend on tmpnam.
> 
> Plus, it did seem to make sense to test for tmpnam, since it probably
> won't be found on freestanding environments (the affected tests require
> non-freestanding effective target, but that translate to requiring I/O
> support), and tmpnam might be removed from standards in the future.  We
> might want to catch that, rather than silently skip the test, though.
> 
> I'd be glad to add an intermediate fileio effective target, or rename
> the proposed one and drop tmpnam from it, if there's agreement such a
> separate effective target would be more useful.
> 
> 
> So, should I rename _tmpnam to _fileio and drop tmpnam() from the code
> snippet in the effective target test?  Or should I keep _tmpnam and
> introduce _fileio?  With or without a dependency of _tmpnam on _fileio?
> 
> Since Jeff Law approved the patch as is, would you guys mind if I make
> any further changes as separate, followup patches?

Sure.  I'd go with _fileio but that's just a suggestion.  I don't
think there are enough uses of tmpnam in the test suite or risk
that it will disappear anytime soon to justify its own target test
or removing its uses, but I'm not opposed to it either.

Martin
Alexandre Oliva April 24, 2020, 9:59 a.m. UTC | #10
On Apr 23, 2020, Martin Sebor <msebor@gmail.com> wrote:

> Sure.  I'd go with _fileio but that's just a suggestion.

Okiedokie, here's the patch using fileio instead of tmpnam for the
effective target name.  I'm going to check it in shortly.


introduce target fileio and require it in tests that use tmpnam

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 fileio effective target to the testsuite, and
requires it in the tests that call tmpnam.


for  gcc/testsuite/ChangeLog

	* lib/target-supports.exp (check_effective_target_fileio): 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             |   13 +++++++++++++
 4 files changed, 16 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..d8e19e7 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 fileio }
    { 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..4e7d8f7 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 fileio }
    { 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..42a3b17 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 fileio }
    { 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..476d795 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -751,6 +751,19 @@ proc check_effective_target_freestanding { } {
     return 0
 }
 
+# Check to see that file I/O functions are available.
+proc check_effective_target_fileio { } {
+    return [check_no_compiler_messages fileio_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
Bernhard Reutner-Fischer April 28, 2020, 9:52 a.m. UTC | #11
On 24 April 2020 11:59:50 CEST, Alexandre Oliva <oliva@adacore.com> wrote:
>On Apr 23, 2020, Martin Sebor <msebor@gmail.com> wrote:
>
>> Sure.  I'd go with _fileio but that's just a suggestion.
>
>Okiedokie, here's the patch using fileio instead of tmpnam for the
>effective target name.  I'm going to check it in shortly.
>
>
>introduce target fileio and require it in tests that use tmpnam

ISTM the corresponding documentation hunk for sourcebuild.texi  is missing.
TIA,
>
>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 fileio effective target to the testsuite, and
>requires it in the tests that call tmpnam.
>
>
>for  gcc/testsuite/ChangeLog
>
>	* lib/target-supports.exp (check_effective_target_fileio): 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             |   13 +++++++++++++
> 4 files changed, 16 insertions(+)
Alexandre Oliva April 28, 2020, 11:43 p.m. UTC | #12
On Apr 28, 2020, Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote:

> ISTM the corresponding documentation hunk for sourcebuild.texi  is missing.

Thanks, I wasn't aware that testsuite effective targets were documented
there.

Here's the missing documentation.  Tested with 'make info' on
x86_64-linux-gnu.  Ok to install?


document effective target fileio

From: Alexandre Oliva <oliva@adacore.com>

check_effective_target_fileio was added to
gcc/testsuite/lib/target-supports.exp the other day, without
documentation.

This patch adds the corresponding documentation.


for  gcc/ChangeLog

	* doc/sourcebuild.texi (Effective-Target Keywords): Document
	the newly-introduced fileio effective target.
---
 gcc/doc/sourcebuild.texi |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index b696120..46b486d 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2233,6 +2233,12 @@ Target provides @file{fenv.h} include file.
 Target supports @file{fenv.h} with all the standard IEEE exceptions
 and floating-point exceptions are raised by arithmetic operations.
 
+@item fileio
+Target offers such file I/O library functions as @code{fopen},
+@code{fclose}, @code{tmpnam}, and @code{remove}.  This is a link-time
+requirement for the presence of the functions in the library; even if
+they fail at runtime, the requirement is still regarded as satisfied.
+
 @item freestanding
 Target is @samp{freestanding} as defined in section 4 of the C99 standard.
 Effectively, it is a target which supports no extra headers or libraries
Li, Pan2 via Gcc-patches April 29, 2020, 5:18 p.m. UTC | #13
On Tue, 2020-04-28 at 20:43 -0300, Alexandre Oliva wrote:
> On Apr 28, 2020, Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote:
> 
> > ISTM the corresponding documentation hunk for sourcebuild.texi  is missing.
> 
> Thanks, I wasn't aware that testsuite effective targets were documented
> there.
> 
> Here's the missing documentation.  Tested with 'make info' on
> x86_64-linux-gnu.  Ok to install?
> 
> 
> document effective target fileio
> 
> From: Alexandre Oliva <oliva@adacore.com>
> 
> check_effective_target_fileio was added to
> gcc/testsuite/lib/target-supports.exp the other day, without
> documentation.
> 
> This patch adds the corresponding documentation.
> 
> 
> for  gcc/ChangeLog
> 
> 	* doc/sourcebuild.texi (Effective-Target Keywords): Document
> 	the newly-introduced fileio effective target.
OK
jeff
>
diff mbox series

Patch

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