nvptx: Disable effective-target 'freestanding' (was: [PATCH 3/9] nvptx: Re-enable test cases by removing effective target 'freestanding')

2024-10-07 Thread Thomas Schwinge
Hi!

On 2022-12-02T13:03:09+0100, I wrote:
> --- a/gcc/testsuite/lib/target-supports.exp
> +++ b/gcc/testsuite/lib/target-supports.exp

> -# Check to see if a target is "freestanding". This is as per the definition
> -# in Section 4 of C99 standard. Effectively, it is a target which supports no
> -# extra headers or libraries other than what is considered essential.
> -proc check_effective_target_freestanding { } {
> -if { [istarget nvptx-*-*] } {
> -   return 1
> -}
> -return 0
> -}

I have, for now, pushed a simpler variant of this to trunk branch in
commit 65c7616c251a6697134b2a3ac7fe6460d308d2ed
"nvptx: Disable effective-target 'freestanding'", see attached.


Grüße
 Thomas


>From 65c7616c251a6697134b2a3ac7fe6460d308d2ed Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
Date: Mon, 28 Nov 2022 13:49:06 +0100
Subject: [PATCH] nvptx: Disable effective-target 'freestanding'

After 2014's commit 157e859ffe3b5d43db1e19475711c1a3d21ab57a "remove picochip",
the effective-target 'freestanding' (later) was only ever used for nvptx.
However, the relevant I/O library functions have long been implemented in nvptx
newlib.

These test cases generally PASS, just a few need to get XFAILed; see
,
and then supposedly
 for
description of the non-standard PTX 'vprintf' return value:

> Unlike the C-standard 'printf()', which returns the number of characters
> printed, CUDA's 'printf()' returns the number of arguments parsed. If no
> arguments follow the format string, 0 is returned. If the format string is
> NULL, -1 is returned. If an internal error occurs, -2 is returned.

(I've tried a few variants to confirm that PTX 'vprintf' -- which supposedly is
underlying the CUDA 'printf' -- is what's implementing this behavior.)
Probably, we ought to fix that up in nvptx newlib.

	gcc/testsuite/
	* gcc.c-torture/execute/printf-1.c: XFAIL for nvptx.
	* gcc.c-torture/execute/printf-chk-1.c: Likewise.
	* gcc.c-torture/execute/vprintf-1.c: Likewise.
	* gcc.c-torture/execute/vprintf-chk-1.c: Likewise.
	* lib/target-supports.exp (check_effective_target_freestanding):
	Disable for nvptx.
---
 gcc/testsuite/gcc.c-torture/execute/printf-1.c  | 1 +
 gcc/testsuite/gcc.c-torture/execute/printf-chk-1.c  | 1 +
 gcc/testsuite/gcc.c-torture/execute/vprintf-1.c | 1 +
 gcc/testsuite/gcc.c-torture/execute/vprintf-chk-1.c | 1 +
 gcc/testsuite/lib/target-supports.exp   | 3 ---
 5 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.c-torture/execute/printf-1.c b/gcc/testsuite/gcc.c-torture/execute/printf-1.c
index 654e62766a8..e1201365c1f 100644
--- a/gcc/testsuite/gcc.c-torture/execute/printf-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/printf-1.c
@@ -1,4 +1,5 @@
 /* { dg-skip-if "requires io" { freestanding } }  */
+/* { dg-xfail-run-if {unexpected PTX 'vprintf' return value} { nvptx-*-* } } */
 
 #include 
 #include 
diff --git a/gcc/testsuite/gcc.c-torture/execute/printf-chk-1.c b/gcc/testsuite/gcc.c-torture/execute/printf-chk-1.c
index aab43062bae..6418957edae 100644
--- a/gcc/testsuite/gcc.c-torture/execute/printf-chk-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/printf-chk-1.c
@@ -1,4 +1,5 @@
 /* { dg-skip-if "requires io" { freestanding } }  */
+/* { dg-xfail-run-if {unexpected PTX 'vprintf' return value} { nvptx-*-* } } */
 
 #include 
 #include 
diff --git a/gcc/testsuite/gcc.c-torture/execute/vprintf-1.c b/gcc/testsuite/gcc.c-torture/execute/vprintf-1.c
index 259397ebda3..0fb1ade94e0 100644
--- a/gcc/testsuite/gcc.c-torture/execute/vprintf-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/vprintf-1.c
@@ -1,4 +1,5 @@
 /* { dg-skip-if "requires io" { freestanding } }  */
+/* { dg-xfail-run-if {unexpected PTX 'vprintf' return value} { nvptx-*-* } } */
 
 #ifndef test
 #include 
diff --git a/gcc/testsuite/gcc.c-torture/execute/vprintf-chk-1.c b/gcc/testsuite/gcc.c-torture/execute/vprintf-chk-1.c
index 04ecc4df4d9..7ea3617e184 100644
--- a/gcc/testsuite/gcc.c-torture/execute/vprintf-chk-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/vprintf-chk-1.c
@@ -1,4 +1,5 @@
 /* { dg-skip-if "requires io" { freestanding } }  */
+/* { dg-xfail-run-if {unexpected PTX 'vprintf' return value} { nvptx-*-* } } */
 
 #ifndef test
 #include 
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 459af8e58c6..1c9bbf64817 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -859,9 +859,6 @@ proc check_profiling_available { test_what } {
 # in Section 4 of C99 standard. Effectively, it is a target which supports no
 # extra headers or libraries other than what is considered essential.
 proc check_effective_target_freestanding { } {
-if { [istarget nvptx-*-*] } {
-	return 1
-}
 return 0
 }
 
-- 
2.34.1



[PATCH 3/9] nvptx: Re-enable test cases by removing effective target 'freestanding'

2022-12-02 Thread Thomas Schwinge
After 2014's commit 157e859ffe3b5d43db1e19475711c1a3d21ab57a "remove picochip",
the effective target 'freestanding' (later) was only ever used for nvptx.
However, the relevant I/O library functions have long been implemented in nvptx
newlib, and otherwise, the more specific effective target 'fileio' (as added in
commit r10-7943-g3685c5adf5c0b30268cb8f95c89e4c4a3240ae6f
"introduce target fileio and require it in tests that use tmpnam") may be used,
and already is used in the relevant test cases.  Therefore, I suggest
"removing effective target 'freestanding'" instead of letting it linger unused,
and thus unmaintained.

These test cases generally PASS, just a few need to get XFAILed; see
,
and then supposedly
 for
description of the non-standard PTX 'vprintf' return value:

> Unlike the C-standard 'printf()', which returns the number of characters
> printed, CUDA's 'printf()' returns the number of arguments parsed. If no
> arguments follow the format string, 0 is returned. If the format string is
> NULL, -1 is returned. If an internal error occurs, -2 is returned.

(I've tried a few variants to confirm that PTX 'vprintf' -- which supposedly is
underlying the CUDA 'printf' -- is what's implementing this behavior.)
Probably, we ought to fix that up in nvptx newlib.

gcc/doc/
* sourcebuild.texi (Effective-Target Keywords): Remove
'freestanding'.
gcc/testsuite/
* gcc.c-torture/execute/builtins/fprintf.x: Remove.
* gcc.c-torture/execute/builtins/fputs.x: Likewise.
* gcc.c-torture/execute/complex-6.c: Don't gate on 'freestanding'.
* gcc.c-torture/execute/fprintf-1.c: Likewise.
* gcc.c-torture/execute/fprintf-2.c: Likewise.
* gcc.c-torture/execute/fprintf-chk-1.c: Likewise.
* gcc.c-torture/execute/gofast.c: Likewise.
* gcc.c-torture/execute/pr34456.c: Likewise.
* gcc.c-torture/execute/printf-1.c: Likewise.
* gcc.c-torture/execute/printf-2.c: Likewise.
* gcc.c-torture/execute/printf-chk-1.c: Likewise.
* gcc.c-torture/execute/user-printf.c: Likewise.
* gcc.c-torture/execute/vfprintf-1.c: Likewise.
* gcc.c-torture/execute/vfprintf-chk-1.c: Likewise.
* gcc.c-torture/execute/vprintf-1.c: Likewise.
* gcc.c-torture/execute/vprintf-chk-1.c: Likewise.
* gcc.dg/pr27531-1.c: Likewise.
* gcc.dg/pr44606.c: Likewise.
* lib/target-supports.exp (check_effective_target_freestanding):
Remove.
---
 gcc/doc/sourcebuild.texi   |  5 -
 gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.x |  7 ---
 gcc/testsuite/gcc.c-torture/execute/builtins/fputs.x   |  7 ---
 gcc/testsuite/gcc.c-torture/execute/complex-6.c|  2 --
 gcc/testsuite/gcc.c-torture/execute/fprintf-1.c|  2 --
 gcc/testsuite/gcc.c-torture/execute/fprintf-2.c|  3 +--
 gcc/testsuite/gcc.c-torture/execute/fprintf-chk-1.c|  2 --
 gcc/testsuite/gcc.c-torture/execute/gofast.c   |  2 --
 gcc/testsuite/gcc.c-torture/execute/pr34456.c  |  2 --
 gcc/testsuite/gcc.c-torture/execute/printf-1.c |  2 +-
 gcc/testsuite/gcc.c-torture/execute/printf-2.c |  3 +--
 gcc/testsuite/gcc.c-torture/execute/printf-chk-1.c |  2 +-
 gcc/testsuite/gcc.c-torture/execute/user-printf.c  |  3 +--
 gcc/testsuite/gcc.c-torture/execute/vfprintf-1.c   |  2 --
 gcc/testsuite/gcc.c-torture/execute/vfprintf-chk-1.c   |  2 --
 gcc/testsuite/gcc.c-torture/execute/vprintf-1.c|  2 +-
 gcc/testsuite/gcc.c-torture/execute/vprintf-chk-1.c|  2 +-
 gcc/testsuite/gcc.dg/pr27531-1.c   |  1 -
 gcc/testsuite/gcc.dg/pr44606.c |  1 -
 gcc/testsuite/lib/target-supports.exp  | 10 --
 20 files changed, 7 insertions(+), 55 deletions(-)
 delete mode 100644 gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.x
 delete mode 100644 gcc/testsuite/gcc.c-torture/execute/builtins/fputs.x

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index fc488964480f..cfdd5cfe1a6f 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2623,11 +2623,6 @@ Target offers such file I/O library functions as 
@code{fopen},
 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
-other than what is considered essential.
-
 @item gettimeofday
 Target supports @code{gettimeofday}.

diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.x 
b/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.x
deleted file mode 100644
index c8fdaf5b254