diff mbox series

Add dg-require-wchars to libstdc++ testsuite

Message ID orwnx9ilza.fsf@lxoliva.fsfla.org
State New
Headers show
Series Add dg-require-wchars to libstdc++ testsuite | expand

Commit Message

Alexandre Oliva Dec. 22, 2020, 9:12 p.m. UTC
Some tests uses structures from the libstdc++ that are present only if
the target has a wchar.h header.  However, those tests do not check
that the target supports those constructs before executing the tests.

The function dg-require-wchars checks that "_GLIBCXX_USE_WCHAR_T" is
defined by the configure of the libstdc++.  If it is not the case, the
test is not executed.

Regstrapped on x86_64-linux-gnu, and tested with -x-arm-wrs-vxworks7r2.
Ok to install?


from Corentin Gay <gay@adacore.com>
for  libstdc++-v3/ChangeLog

	* testsuite/lib/dg-options.exp: Add dg-require-wchars
	function.
	* testsuite/lib/libstdc++.exp: Add check_v3_target_wchars
	function.
	* testsuite/22_locale/codecvt/codecvt_utf16/79980.cc: Add
	requirement.
	* testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc:
	Likewise.
	* testsuite/22_locale/codecvt/codecvt_utf8/79980.cc: Likewise.
	* testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc:
	Likewise.
	* testsuite/22_locale/conversions/buffer/1.cc: Likewise.
	* testsuite/22_locale/conversions/buffer/2.cc: Likewise.
	* testsuite/22_locale/conversions/buffer/3.cc: Likewise.
	* testsuite/22_locale/conversions/buffer/requirements/typedefs.cc:
	Likewise.
	* testsuite/22_locale/conversions/string/1.cc: Likewise.
	* testsuite/22_locale/conversions/string/2.cc: Likewise.
	* testsuite/22_locale/conversions/string/3.cc: Likewise.
	* testsuite/22_locale/conversions/string/66441.cc: Likewise.
	* testsuite/22_locale/conversions/string/requirements/typedefs.cc:
	Likewise.
	* testsuite/22_locale/conversions/string/requirements/typedefs-2.cc:
	Likewise.
---
 .../22_locale/codecvt/codecvt_utf16/79980.cc       |    1 
 .../22_locale/codecvt/codecvt_utf16/misaligned.cc  |    1 
 .../22_locale/codecvt/codecvt_utf8/79980.cc        |    1 
 .../22_locale/codecvt/codecvt_utf8_utf16/79511.cc  |    1 
 .../testsuite/22_locale/conversions/buffer/1.cc    |    1 
 .../testsuite/22_locale/conversions/buffer/2.cc    |    1 
 .../testsuite/22_locale/conversions/buffer/3.cc    |    1 
 .../conversions/buffer/requirements/typedefs.cc    |    1 
 .../testsuite/22_locale/conversions/string/1.cc    |    1 
 .../testsuite/22_locale/conversions/string/2.cc    |    1 
 .../testsuite/22_locale/conversions/string/3.cc    |    1 
 .../22_locale/conversions/string/66441.cc          |    1 
 .../conversions/string/requirements/typedefs-2.cc  |    1 
 .../conversions/string/requirements/typedefs.cc    |    1 
 libstdc++-v3/testsuite/lib/dg-options.exp          |    9 ++++
 libstdc++-v3/testsuite/lib/libstdc++.exp           |   47 ++++++++++++++++++++
 16 files changed, 70 insertions(+)

Comments

François Dumont Dec. 28, 2020, 6:23 p.m. UTC | #1
On 22/12/20 10:12 pm, Alexandre Oliva wrote:
> Some tests uses structures from the libstdc++ that are present only if
> the target has a wchar.h header.  However, those tests do not check
> that the target supports those constructs before executing the tests.

Looks like those tests should be in some sub-folder containing 'wchar_t' 
to be considered as UNSUP.

Maybe Jonathan will prefer them to be moved even if your approach seems 
more convenient to me.


>
> The function dg-require-wchars checks that "_GLIBCXX_USE_WCHAR_T" is
> defined by the configure of the libstdc++.  If it is not the case, the
> test is not executed.
>
> Regstrapped on x86_64-linux-gnu, and tested with -x-arm-wrs-vxworks7r2.
> Ok to install?
>
>
> from Corentin Gay <gay@adacore.com>
> for  libstdc++-v3/ChangeLog
>
> 	* testsuite/lib/dg-options.exp: Add dg-require-wchars
> 	function.
> 	* testsuite/lib/libstdc++.exp: Add check_v3_target_wchars
> 	function.
> 	* testsuite/22_locale/codecvt/codecvt_utf16/79980.cc: Add
> 	requirement.
> 	* testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc:
> 	Likewise.
> 	* testsuite/22_locale/codecvt/codecvt_utf8/79980.cc: Likewise.
> 	* testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc:
> 	Likewise.
> 	* testsuite/22_locale/conversions/buffer/1.cc: Likewise.
> 	* testsuite/22_locale/conversions/buffer/2.cc: Likewise.
> 	* testsuite/22_locale/conversions/buffer/3.cc: Likewise.
> 	* testsuite/22_locale/conversions/buffer/requirements/typedefs.cc:
> 	Likewise.
> 	* testsuite/22_locale/conversions/string/1.cc: Likewise.
> 	* testsuite/22_locale/conversions/string/2.cc: Likewise.
> 	* testsuite/22_locale/conversions/string/3.cc: Likewise.
> 	* testsuite/22_locale/conversions/string/66441.cc: Likewise.
> 	* testsuite/22_locale/conversions/string/requirements/typedefs.cc:
> 	Likewise.
> 	* testsuite/22_locale/conversions/string/requirements/typedefs-2.cc:
> 	Likewise.
> ---
>   .../22_locale/codecvt/codecvt_utf16/79980.cc       |    1
>   .../22_locale/codecvt/codecvt_utf16/misaligned.cc  |    1
>   .../22_locale/codecvt/codecvt_utf8/79980.cc        |    1
>   .../22_locale/codecvt/codecvt_utf8_utf16/79511.cc  |    1
>   .../testsuite/22_locale/conversions/buffer/1.cc    |    1
>   .../testsuite/22_locale/conversions/buffer/2.cc    |    1
>   .../testsuite/22_locale/conversions/buffer/3.cc    |    1
>   .../conversions/buffer/requirements/typedefs.cc    |    1
>   .../testsuite/22_locale/conversions/string/1.cc    |    1
>   .../testsuite/22_locale/conversions/string/2.cc    |    1
>   .../testsuite/22_locale/conversions/string/3.cc    |    1
>   .../22_locale/conversions/string/66441.cc          |    1
>   .../conversions/string/requirements/typedefs-2.cc  |    1
>   .../conversions/string/requirements/typedefs.cc    |    1
>   libstdc++-v3/testsuite/lib/dg-options.exp          |    9 ++++
>   libstdc++-v3/testsuite/lib/libstdc++.exp           |   47 ++++++++++++++++++++
>   16 files changed, 70 insertions(+)
>
> diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
> index 8a092913a4c92..039bdd0322907 100644
> --- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
> +++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
> @@ -16,6 +16,7 @@
>   // <http://www.gnu.org/licenses/>.
>   
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   #include <locale>
>   #include <codecvt>
> diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc
> index 04cfc8d744bdd..3496e0e819e98 100644
> --- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc
> +++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc
> @@ -16,6 +16,7 @@
>   // <http://www.gnu.org/licenses/>.
>   
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   #include <locale>
>   #include <codecvt>
> diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc
> index 68ae5af234ae5..fd69dd5c04de0 100644
> --- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc
> +++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc
> @@ -16,6 +16,7 @@
>   // <http://www.gnu.org/licenses/>.
>   
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   #include <codecvt>
>   #include <locale>
> diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc
> index 1f63e7218e7d2..590a3b73bfc41 100644
> --- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc
> +++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc
> @@ -16,6 +16,7 @@
>   // <http://www.gnu.org/licenses/>.
>   
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   #include <locale>
>   #include <codecvt>
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/buffer/1.cc b/libstdc++-v3/testsuite/22_locale/conversions/buffer/1.cc
> index 2855f7432d464..91bf2bf22160d 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/buffer/1.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/buffer/1.cc
> @@ -1,4 +1,5 @@
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // Copyright (C) 2015-2020 Free Software Foundation, Inc.
>   //
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/buffer/2.cc b/libstdc++-v3/testsuite/22_locale/conversions/buffer/2.cc
> index 2cf320fc13cca..a03a16a02ed0b 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/buffer/2.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/buffer/2.cc
> @@ -16,6 +16,7 @@
>   // <http://www.gnu.org/licenses/>.
>   
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   #include <locale>
>   #include <sstream>
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/buffer/3.cc b/libstdc++-v3/testsuite/22_locale/conversions/buffer/3.cc
> index de43e0a95b2b7..84d5358f4999c 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/buffer/3.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/buffer/3.cc
> @@ -16,6 +16,7 @@
>   // <http://www.gnu.org/licenses/>.
>   
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   #include <locale>
>   #include <streambuf>
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc b/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc
> index e88799dbec750..8efe203e87398 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc
> @@ -1,4 +1,5 @@
>   // { dg-do compile { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // Copyright (C) 2015-2020 Free Software Foundation, Inc.
>   //
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc
> index 41d6594fe1320..d491e6c52709e 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc
> @@ -1,4 +1,5 @@
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // Copyright (C) 2015-2020 Free Software Foundation, Inc.
>   //
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc
> index bc26e328a6039..b4867053f3c85 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc
> @@ -1,4 +1,5 @@
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // Copyright (C) 2015-2020 Free Software Foundation, Inc.
>   //
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/3.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/3.cc
> index b7793cdca49ea..023897c9307b5 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/string/3.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/string/3.cc
> @@ -1,4 +1,5 @@
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // Copyright (C) 2015-2020 Free Software Foundation, Inc.
>   //
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/66441.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/66441.cc
> index 07136aec1179e..b78c31fbb9b1b 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/string/66441.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/string/66441.cc
> @@ -16,6 +16,7 @@
>   // <http://www.gnu.org/licenses/>.
>   
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // libstdc++/66441
>   
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc
> index 91b47c449a16a..4cd254a40da57 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc
> @@ -1,4 +1,5 @@
>   // { dg-do compile { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // Copyright (C) 2015-2020 Free Software Foundation, Inc.
>   //
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc
> index 023caa69a6e3a..30e49b2ff893b 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc
> @@ -1,4 +1,5 @@
>   // { dg-do compile { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // Copyright (C) 2015-2020 Free Software Foundation, Inc.
>   //
> diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp
> index 0102acf65a282..17306a0eb0205 100644
> --- a/libstdc++-v3/testsuite/lib/dg-options.exp
> +++ b/libstdc++-v3/testsuite/lib/dg-options.exp
> @@ -16,6 +16,15 @@
>   # along with this program; see the file COPYING3.  If not see
>   # <http://www.gnu.org/licenses/>.
>   
> +proc dg-require-wchars { args } {
> +    if { ![ check_v3_target_wchars ] } {
> +	upvar dg-do-what dg-do-what
> +	set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
> +	return
> +    }
> +    return
> +}
> +
>   proc dg-require-c-std { args } {
>       if { ![ check_v3_target_c_std ] } {
>   	upvar dg-do-what dg-do-what
> diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
> index b7d7b906de41c..2c22bcc0f0c94 100644
> --- a/libstdc++-v3/testsuite/lib/libstdc++.exp
> +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
> @@ -702,6 +702,53 @@ proc v3-build_support { } {
>       }
>   }
>   
> +proc check_v3_target_wchars { } {
> +    global et_wchars
> +    global et_wchars_target_name
> +    global tool
> +
> +    if { ![info exists et_wchars_target_name] } {
> +	set et_wchars_target_name ""
> +    }
> +
> +    # If the target has changed since we set the cached value, clear it.
> +    set current_target [current_target_name]
> +    if { $current_target != $et_wchars_target_name } {
> +	verbose "check_v3_target_wchars: `$et_wchars_target_name'" 2
> +	set et_wchars_target_name $current_target
> +	if [info exists et_wchars] {
> +	    verbose "check_v3_target_wchars: removing cached result" 2
> +	    unset et_wchars
> +	}
> +    }
> +
> +    if [info exists et_wchars] {
> +	verbose "check_v3_target_wchars: using cached result" 2
> +    } else {
> +	set et_wchars 0
> +
> +	# Set up and preprocess a C++ test program that depends
> +	# on wchars support being configured in the libstdc++.
> +	set src wchars[pid].cc
> +
> +	set f [open $src "w"]
> +	puts $f "#ifndef _GLIBCXX_USE_WCHAR_T"
> +	puts $f "#  error No wchar header."
> +	puts $f "#endif"
> +	close $f
> +
> +	set lines [v3_target_compile $src /dev/null preprocess ""]
> +	file delete $src
> +
> +	if [string match "" $lines] {
> +	    # No error message, preprocessing succeeded.
> +	    set et_wchars 1
> +	}
> +    }
> +    verbose "check_v3_target_wchars: $et_wchars" 2
> +    return $et_wchars
> +}
> +

This check_v3_target_wchars looks like a good candidate to leverage on: 
v3_check_preprocessor_condition.
François Dumont Dec. 28, 2020, 6:27 p.m. UTC | #2
On 22/12/20 10:12 pm, Alexandre Oliva wrote:
> Some tests uses structures from the libstdc++ that are present only if
> the target has a wchar.h header.  However, those tests do not check
> that the target supports those constructs before executing the tests.

Like you already spotted in another thread those tests should be in some 
sub-folder containing 'wchar_t' to be considered as UNSUP.

Maybe Jonathan will prefer them to be moved even if your approach seems 
more convenient to me.


>
> The function dg-require-wchars checks that "_GLIBCXX_USE_WCHAR_T" is
> defined by the configure of the libstdc++.  If it is not the case, the
> test is not executed.
>
> Regstrapped on x86_64-linux-gnu, and tested with -x-arm-wrs-vxworks7r2.
> Ok to install?
>
>
> from Corentin Gay <gay@adacore.com>
> for  libstdc++-v3/ChangeLog
>
> 	* testsuite/lib/dg-options.exp: Add dg-require-wchars
> 	function.
> 	* testsuite/lib/libstdc++.exp: Add check_v3_target_wchars
> 	function.
> 	* testsuite/22_locale/codecvt/codecvt_utf16/79980.cc: Add
> 	requirement.
> 	* testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc:
> 	Likewise.
> 	* testsuite/22_locale/codecvt/codecvt_utf8/79980.cc: Likewise.
> 	* testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc:
> 	Likewise.
> 	* testsuite/22_locale/conversions/buffer/1.cc: Likewise.
> 	* testsuite/22_locale/conversions/buffer/2.cc: Likewise.
> 	* testsuite/22_locale/conversions/buffer/3.cc: Likewise.
> 	* testsuite/22_locale/conversions/buffer/requirements/typedefs.cc:
> 	Likewise.
> 	* testsuite/22_locale/conversions/string/1.cc: Likewise.
> 	* testsuite/22_locale/conversions/string/2.cc: Likewise.
> 	* testsuite/22_locale/conversions/string/3.cc: Likewise.
> 	* testsuite/22_locale/conversions/string/66441.cc: Likewise.
> 	* testsuite/22_locale/conversions/string/requirements/typedefs.cc:
> 	Likewise.
> 	* testsuite/22_locale/conversions/string/requirements/typedefs-2.cc:
> 	Likewise.
> ---
>   .../22_locale/codecvt/codecvt_utf16/79980.cc       |    1
>   .../22_locale/codecvt/codecvt_utf16/misaligned.cc  |    1
>   .../22_locale/codecvt/codecvt_utf8/79980.cc        |    1
>   .../22_locale/codecvt/codecvt_utf8_utf16/79511.cc  |    1
>   .../testsuite/22_locale/conversions/buffer/1.cc    |    1
>   .../testsuite/22_locale/conversions/buffer/2.cc    |    1
>   .../testsuite/22_locale/conversions/buffer/3.cc    |    1
>   .../conversions/buffer/requirements/typedefs.cc    |    1
>   .../testsuite/22_locale/conversions/string/1.cc    |    1
>   .../testsuite/22_locale/conversions/string/2.cc    |    1
>   .../testsuite/22_locale/conversions/string/3.cc    |    1
>   .../22_locale/conversions/string/66441.cc          |    1
>   .../conversions/string/requirements/typedefs-2.cc  |    1
>   .../conversions/string/requirements/typedefs.cc    |    1
>   libstdc++-v3/testsuite/lib/dg-options.exp          |    9 ++++
>   libstdc++-v3/testsuite/lib/libstdc++.exp           |   47 ++++++++++++++++++++
>   16 files changed, 70 insertions(+)
>
> diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
> index 8a092913a4c92..039bdd0322907 100644
> --- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
> +++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
> @@ -16,6 +16,7 @@
>   // <http://www.gnu.org/licenses/>.
>   
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   #include <locale>
>   #include <codecvt>
> diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc
> index 04cfc8d744bdd..3496e0e819e98 100644
> --- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc
> +++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc
> @@ -16,6 +16,7 @@
>   // <http://www.gnu.org/licenses/>.
>   
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   #include <locale>
>   #include <codecvt>
> diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc
> index 68ae5af234ae5..fd69dd5c04de0 100644
> --- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc
> +++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc
> @@ -16,6 +16,7 @@
>   // <http://www.gnu.org/licenses/>.
>   
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   #include <codecvt>
>   #include <locale>
> diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc
> index 1f63e7218e7d2..590a3b73bfc41 100644
> --- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc
> +++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc
> @@ -16,6 +16,7 @@
>   // <http://www.gnu.org/licenses/>.
>   
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   #include <locale>
>   #include <codecvt>
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/buffer/1.cc b/libstdc++-v3/testsuite/22_locale/conversions/buffer/1.cc
> index 2855f7432d464..91bf2bf22160d 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/buffer/1.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/buffer/1.cc
> @@ -1,4 +1,5 @@
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // Copyright (C) 2015-2020 Free Software Foundation, Inc.
>   //
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/buffer/2.cc b/libstdc++-v3/testsuite/22_locale/conversions/buffer/2.cc
> index 2cf320fc13cca..a03a16a02ed0b 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/buffer/2.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/buffer/2.cc
> @@ -16,6 +16,7 @@
>   // <http://www.gnu.org/licenses/>.
>   
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   #include <locale>
>   #include <sstream>
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/buffer/3.cc b/libstdc++-v3/testsuite/22_locale/conversions/buffer/3.cc
> index de43e0a95b2b7..84d5358f4999c 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/buffer/3.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/buffer/3.cc
> @@ -16,6 +16,7 @@
>   // <http://www.gnu.org/licenses/>.
>   
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   #include <locale>
>   #include <streambuf>
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc b/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc
> index e88799dbec750..8efe203e87398 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc
> @@ -1,4 +1,5 @@
>   // { dg-do compile { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // Copyright (C) 2015-2020 Free Software Foundation, Inc.
>   //
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc
> index 41d6594fe1320..d491e6c52709e 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc
> @@ -1,4 +1,5 @@
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // Copyright (C) 2015-2020 Free Software Foundation, Inc.
>   //
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc
> index bc26e328a6039..b4867053f3c85 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc
> @@ -1,4 +1,5 @@
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // Copyright (C) 2015-2020 Free Software Foundation, Inc.
>   //
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/3.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/3.cc
> index b7793cdca49ea..023897c9307b5 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/string/3.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/string/3.cc
> @@ -1,4 +1,5 @@
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // Copyright (C) 2015-2020 Free Software Foundation, Inc.
>   //
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/66441.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/66441.cc
> index 07136aec1179e..b78c31fbb9b1b 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/string/66441.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/string/66441.cc
> @@ -16,6 +16,7 @@
>   // <http://www.gnu.org/licenses/>.
>   
>   // { dg-do run { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // libstdc++/66441
>   
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc
> index 91b47c449a16a..4cd254a40da57 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc
> @@ -1,4 +1,5 @@
>   // { dg-do compile { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // Copyright (C) 2015-2020 Free Software Foundation, Inc.
>   //
> diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc
> index 023caa69a6e3a..30e49b2ff893b 100644
> --- a/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc
> +++ b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc
> @@ -1,4 +1,5 @@
>   // { dg-do compile { target c++11 } }
> +// { dg-require-wchars "" }
>   
>   // Copyright (C) 2015-2020 Free Software Foundation, Inc.
>   //
> diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp
> index 0102acf65a282..17306a0eb0205 100644
> --- a/libstdc++-v3/testsuite/lib/dg-options.exp
> +++ b/libstdc++-v3/testsuite/lib/dg-options.exp
> @@ -16,6 +16,15 @@
>   # along with this program; see the file COPYING3.  If not see
>   # <http://www.gnu.org/licenses/>.
>   
> +proc dg-require-wchars { args } {
> +    if { ![ check_v3_target_wchars ] } {
> +	upvar dg-do-what dg-do-what
> +	set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
> +	return
> +    }
> +    return
> +}
> +
>   proc dg-require-c-std { args } {
>       if { ![ check_v3_target_c_std ] } {
>   	upvar dg-do-what dg-do-what
> diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
> index b7d7b906de41c..2c22bcc0f0c94 100644
> --- a/libstdc++-v3/testsuite/lib/libstdc++.exp
> +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
> @@ -702,6 +702,53 @@ proc v3-build_support { } {
>       }
>   }
>   
> +proc check_v3_target_wchars { } {
> +    global et_wchars
> +    global et_wchars_target_name
> +    global tool
> +
> +    if { ![info exists et_wchars_target_name] } {
> +	set et_wchars_target_name ""
> +    }
> +
> +    # If the target has changed since we set the cached value, clear it.
> +    set current_target [current_target_name]
> +    if { $current_target != $et_wchars_target_name } {
> +	verbose "check_v3_target_wchars: `$et_wchars_target_name'" 2
> +	set et_wchars_target_name $current_target
> +	if [info exists et_wchars] {
> +	    verbose "check_v3_target_wchars: removing cached result" 2
> +	    unset et_wchars
> +	}
> +    }
> +
> +    if [info exists et_wchars] {
> +	verbose "check_v3_target_wchars: using cached result" 2
> +    } else {
> +	set et_wchars 0
> +
> +	# Set up and preprocess a C++ test program that depends
> +	# on wchars support being configured in the libstdc++.
> +	set src wchars[pid].cc
> +
> +	set f [open $src "w"]
> +	puts $f "#ifndef _GLIBCXX_USE_WCHAR_T"
> +	puts $f "#  error No wchar header."
> +	puts $f "#endif"
> +	close $f
> +
> +	set lines [v3_target_compile $src /dev/null preprocess ""]
> +	file delete $src
> +
> +	if [string match "" $lines] {
> +	    # No error message, preprocessing succeeded.
> +	    set et_wchars 1
> +	}
> +    }
> +    verbose "check_v3_target_wchars: $et_wchars" 2
> +    return $et_wchars
> +}
> +

This check_v3_target_wchars looks like a good candidate to leverage on: 
v3_check_preprocessor_condition.
Alexandre Oliva Jan. 13, 2021, 5:29 p.m. UTC | #3
On Dec 28, 2020, François Dumont <frs.dumont@gmail.com> wrote:

> On 22/12/20 10:12 pm, Alexandre Oliva wrote:
>> Some tests uses structures from the libstdc++ that are present only if
>> the target has a wchar.h header.  However, those tests do not check
>> that the target supports those constructs before executing the tests.

> Looks like those tests should be in some sub-folder containing
> 'wchar_t' to be considered as UNSUP.

> Maybe Jonathan will prefer them to be moved even if your approach
> seems more convenient to me.

I'd be glad to make such changes, but I'd appreciate stronger guidance
as to the preferences and the way to go before doing so.  Jonathan,
would you please share your wisdom WRT this patch and the other
wchar_t-related libstdc++ testsuite one?

https://gcc.gnu.org/pipermail/gcc-patches/2020-December/562435.html
https://gcc.gnu.org/pipermail/gcc-patches/2020-December/562438.html

>> The function dg-require-wchars checks that "_GLIBCXX_USE_WCHAR_T" is
>> defined by the configure of the libstdc++.  If it is not the case, the
>> test is not executed.

> This check_v3_target_wchars looks like a good candidate to leverage
> on: v3_check_preprocessor_condition.

Nice!, thanks for the tip, I was not aware of this proc.
Jonathan Wakely Jan. 14, 2021, 1:08 p.m. UTC | #4
On 13/01/21 14:29 -0300, Alexandre Oliva wrote:
>On Dec 28, 2020, François Dumont <frs.dumont@gmail.com> wrote:
>
>> On 22/12/20 10:12 pm, Alexandre Oliva wrote:
>>> Some tests uses structures from the libstdc++ that are present only if
>>> the target has a wchar.h header.  However, those tests do not check
>>> that the target supports those constructs before executing the tests.
>
>> Looks like those tests should be in some sub-folder containing
>> 'wchar_t' to be considered as UNSUP.
>
>> Maybe Jonathan will prefer them to be moved even if your approach
>> seems more convenient to me.
>
>I'd be glad to make such changes, but I'd appreciate stronger guidance
>as to the preferences and the way to go before doing so.  Jonathan,
>would you please share your wisdom WRT this patch and the other
>wchar_t-related libstdc++ testsuite one?
>
>https://gcc.gnu.org/pipermail/gcc-patches/2020-December/562435.html
>https://gcc.gnu.org/pipermail/gcc-patches/2020-December/562438.html

I'll look at them today.

>>> The function dg-require-wchars checks that "_GLIBCXX_USE_WCHAR_T" is
>>> defined by the configure of the libstdc++.  If it is not the case, the
>>> test is not executed.
>
>> This check_v3_target_wchars looks like a good candidate to leverage
>> on: v3_check_preprocessor_condition.
>
>Nice!, thanks for the tip, I was not aware of this proc.

It's only been there a few weeks.
Jonathan Wakely Jan. 14, 2021, 1:41 p.m. UTC | #5
On 22/12/20 18:12 -0300, Alexandre Oliva wrote:
>--- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
>+++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
>@@ -16,6 +16,7 @@
> // <http://www.gnu.org/licenses/>.
>
> // { dg-do run { target c++11 } }
>+// { dg-require-wchars "" }

This test doesn't use wchar_t, so it shouldn't depend on
_GLIBCXX_USE_WCHAR_T being defined.

The problem is that <bits/locale_conv.h> uses wchar_t in default
template arguments:

#ifdef _GLIBCXX_USE_WCHAR_T

_GLIBCXX_BEGIN_NAMESPACE_CXX11

   /// String conversions
   template<typename _Codecvt, typename _Elem = wchar_t,

That makes it impossible to use wstring_convert and wbuffer_convert
without wchar_t, even if you don't want to convert to wchar_t.

I think we should fix the header, not disable tests that don't use
that default template argument. The attached patch should allow you to
use wstring_convert and wbuffer_convert without wchar_t support. The
tests which instantiate it with char16_t or char32_t instead of
wchar_t should work with this patch, right?

<aside>
Is it the case that the wchar_t type is defined on this target, it's
just that libc doesn't have support for wcslen etc?  Because we should
probably audit all our uses of _GLIBCXX_USE_WCHAR_T and find which
ones actually need libc support and which just need the wchar_t type
to exist. Some things really do need the libc support, but I suspect
many others don't.

It seems wrong that we can provide full support for char16_t and
char32_t but not wchar_t, just because the former two don't depend on
anything being present in libc. Why can't we just implement the same
functionality for wchar_t without using libc?

In fact, if we just define std::char_traits<wchar_t> generically
without using any libc functions (or just using them as optimisations)
we might be able to support std::basic_string<wchar_t> and iostream
classes with almost no work. But that's something to consider in the
future.
</aside>

>diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
>index b7d7b906de41c..2c22bcc0f0c94 100644
>--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
>+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
>@@ -702,6 +702,53 @@ proc v3-build_support { } {
>     }
> }
>
>+proc check_v3_target_wchars { } {
>+    global et_wchars
>+    global et_wchars_target_name
>+    global tool
>+
>+    if { ![info exists et_wchars_target_name] } {
>+	set et_wchars_target_name ""
>+    }
>+
>+    # If the target has changed since we set the cached value, clear it.
>+    set current_target [current_target_name]
>+    if { $current_target != $et_wchars_target_name } {
>+	verbose "check_v3_target_wchars: `$et_wchars_target_name'" 2
>+	set et_wchars_target_name $current_target
>+	if [info exists et_wchars] {
>+	    verbose "check_v3_target_wchars: removing cached result" 2
>+	    unset et_wchars
>+	}
>+    }
>+
>+    if [info exists et_wchars] {
>+	verbose "check_v3_target_wchars: using cached result" 2
>+    } else {
>+	set et_wchars 0
>+
>+	# Set up and preprocess a C++ test program that depends
>+	# on wchars support being configured in the libstdc++.
>+	set src wchars[pid].cc
>+
>+	set f [open $src "w"]
>+	puts $f "#ifndef _GLIBCXX_USE_WCHAR_T"
>+	puts $f "#  error No wchar header."

As François said, this could use the new proc. I'd also prefer if it
was defined as an effective-target keyword so we can use:

// { dg-require-effective-target wchars }

instead of the old fashioned { dg-require-wchars "" } form. I've
recently added effective-target keywords for several of the
dg-require-FOO directives, so we can move away from the old form. I
think new directives should be done as effective-target keywords. See
the recent changes to libstdc++-v3/testsuite/lib/libstdc++.exp for
examples, e.g. 10ee46adf44ae731fc4f9e9fdc25ad60c9d43a9c

But we might not even need this new proc if the codecvt tests can be
made to work using the attached patch.
Jonathan Wakely Jan. 14, 2021, 1:47 p.m. UTC | #6
On 14/01/21 13:41 +0000, Jonathan Wakely wrote:
><aside>
>Is it the case that the wchar_t type is defined on this target, it's
>just that libc doesn't have support for wcslen etc?  Because we should
>probably audit all our uses of _GLIBCXX_USE_WCHAR_T and find which
>ones actually need libc support and which just need the wchar_t type
>to exist. Some things really do need the libc support, but I suspect
>many others don't.
>
>It seems wrong that we can provide full support for char16_t and
>char32_t but not wchar_t, just because the former two don't depend on
>anything being present in libc. Why can't we just implement the same
>functionality for wchar_t without using libc?
>
>In fact, if we just define std::char_traits<wchar_t> generically
>without using any libc functions (or just using them as optimisations)
>we might be able to support std::basic_string<wchar_t> and iostream
>classes with almost no work. But that's something to consider in the
>future.
></aside>

Oops, I considered it already.

This untested patch should define std::char_traits<wchar_t> so it is
available if wchar_t is defined by the front end (which I assume is
always true, is that right?), only using optimized libc routines if
available.

This would be the first step to enabling std::wstring etc for targets
with no wchar_t support in libc.
Alexandre Oliva Jan. 14, 2021, 10:20 p.m. UTC | #7
On Jan 14, 2021, Jonathan Wakely <jwakely@redhat.com> wrote:

> The problem is that <bits/locale_conv.h> uses wchar_t in default
> template arguments:

> I think we should fix the header, not disable tests that don't use
> that default template argument. The attached patch should allow you to
> use wstring_convert and wbuffer_convert without wchar_t support. The
> tests which instantiate it with char16_t or char32_t instead of
> wchar_t should work with this patch, right?

Thanks, I'll give it a spin.  That said, ...

> <aside>
> Is it the case that the wchar_t type is defined on this target, it's
> just that libc doesn't have support for wcslen etc?

... it is definitely the case that the target currently defines wchar_t,
and it even offers wchar.h and a lot of (maybe all?) wcs* functions.
This was likely not the case when the patch was first written.

I'll double check whether any of the patch is still needed for current
versions.

I figured it would a waste to just discard Corentin's identification of
testcases that failed when glibc wchar_t support was not enabled.

This also means that the test results I'm going to get are likely to not
reflect the conditions for which these patches were originally written.


FWIW, I like very much the notion of offering a fallback wchar_t
implementation within libstdc++-v3, so that users get the expected C++
functionality even when libc doesn't offer it.  Even a (conditional?)
typedef to introduce wchar_t could be there.

Perhaps the test that sets or clears _GLIBCXX_USE_WCHAR_T should be used
to decide whether or not to offer a wchar.h header in libstdc++, and
then (pipe dream?) all other uses of this macro would be just gone?


> As François said, this could use the new proc. I'd also prefer if it
> was defined as an effective-target keyword so we can use:

> // { dg-require-effective-target wchars }

*nod*


> But we might not even need this new proc if the codecvt tests can be
> made to work using the attached patch.

Thanks,
Jonathan Wakely Jan. 15, 2021, 10:09 a.m. UTC | #8
On Thu, 14 Jan 2021, 22:22 Alexandre Oliva, <oliva@adacore.com> wrote:

> On Jan 14, 2021, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> > The problem is that <bits/locale_conv.h> uses wchar_t in default
> > template arguments:
>
> > I think we should fix the header, not disable tests that don't use
> > that default template argument. The attached patch should allow you to
> > use wstring_convert and wbuffer_convert without wchar_t support. The
> > tests which instantiate it with char16_t or char32_t instead of
> > wchar_t should work with this patch, right?
>
> Thanks, I'll give it a spin.  That said, ...
>
> > <aside>
> > Is it the case that the wchar_t type is defined on this target, it's
> > just that libc doesn't have support for wcslen etc?
>
> ... it is definitely the case that the target currently defines wchar_t,
> and it even offers wchar.h and a lot of (maybe all?) wcs* functions.
> This was likely not the case when the patch was first written.
>
> I'll double check whether any of the patch is still needed for current
> versions.
>
> I figured it would a waste to just discard Corentin's identification of
> testcases that failed when glibc wchar_t support was not enabled.
>

Definitely not a waste, as it's led to this discussion and plan for
improvement.



> This also means that the test results I'm going to get are likely to not
> reflect the conditions for which these patches were originally written.
>
>
> FWIW, I like very much the notion of offering a fallback wchar_t
> implementation within libstdc++-v3, so that users get the expected C++
> functionality even when libc doesn't offer it.  Even a (conditional?)
> typedef to introduce wchar_t could be there.
>
> Perhaps the test that sets or clears _GLIBCXX_USE_WCHAR_T should be used
> to decide whether or not to offer a wchar.h header in libstdc++, and
> then (pipe dream?) all other uses of this macro would be just gone?
>


That would be great. We might be able to get close even if not all the way
there. However, some small embedded systems might not want the extra
symbols for explicit instantiations of std::wstring, std::wistream in
libstdc++.so so we might want a way to suppress them (they could still
instantiate those templates implicitly by using them, we just wouldn't have
them pre-instantiated in the library).

Anyway, let's start just by making wstring_convert usable without wchar_t.
Alexandre Oliva Jan. 15, 2021, 4:18 p.m. UTC | #9
On Jan 15, 2021, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:

> On Thu, 14 Jan 2021, 22:22 Alexandre Oliva, <oliva@adacore.com> wrote:
>> ... it is definitely the case that the target currently defines wchar_t,
>> and it even offers wchar.h and a lot of (maybe all?) wcs* functions.
>> This was likely not the case when the patch was first written.
>> 
>> I'll double check whether any of the patch is still needed for current
>> versions.

With the tests I've run since yesterday, I've determined that:

- the wchar-related patches for the libstdc++ testsuite, that I had
  proposed last year, are no longer needed

- your two patchlets did not bring about any regressions to test
  results, not in mainline x86_64-linux-gnu native, not with the trivial
  backports to the gcc-10 tree for x-arm-vxw7r2 that was the focus of my
  immediate attention.

So, I withdraw my submissions of the testsuite patches, and I encourage
you to proceed with the two changes you proposed.

However, for avoidance of any doubt, I'll restate that I cannot vow for
whether they're enough to fix the issues we'd run into back when
wchar/wcs* were not supported in the target system, because now they
are, so the changes do not bring any visible improvements to our results
either.

Anyway, thanks for the feedback!
Jonathan Wakely Jan. 15, 2021, 7:47 p.m. UTC | #10
On Fri, 15 Jan 2021, 16:19 Alexandre Oliva, <oliva@adacore.com> wrote:

> On Jan 15, 2021, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>
> > On Thu, 14 Jan 2021, 22:22 Alexandre Oliva, <oliva@adacore.com> wrote:
> >> ... it is definitely the case that the target currently defines wchar_t,
> >> and it even offers wchar.h and a lot of (maybe all?) wcs* functions.
> >> This was likely not the case when the patch was first written.
> >>
> >> I'll double check whether any of the patch is still needed for current
> >> versions.
>
> With the tests I've run since yesterday, I've determined that:
>
> - the wchar-related patches for the libstdc++ testsuite, that I had
>   proposed last year, are no longer needed
>
> - your two patchlets did not bring about any regressions to test
>   results, not in mainline x86_64-linux-gnu native, not with the trivial
>   backports to the gcc-10 tree for x-arm-vxw7r2 that was the focus of my
>   immediate attention.
>
> So, I withdraw my submissions of the testsuite patches, and I encourage
> you to proceed with the two changes you proposed.
>

Great, I'll save them in a git branch to be revisited in stage 1.



> However, for avoidance of any doubt, I'll restate that I cannot vow for
> whether they're enough to fix the issues we'd run into back when
> wchar/wcs* were not supported in the target system, because now they
> are, so the changes do not bring any visible improvements to our results
> either.
>

Understood, thanks for checking them though.


>
Jonathan Wakely Oct. 9, 2021, 7:31 a.m. UTC | #11
On Fri, 15 Jan 2021, 19:47 Jonathan Wakely, <jwakely.gcc@gmail.com> wrote:

>
>
> On Fri, 15 Jan 2021, 16:19 Alexandre Oliva, <oliva@adacore.com> wrote:
>
>> On Jan 15, 2021, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>>
>> > On Thu, 14 Jan 2021, 22:22 Alexandre Oliva, <oliva@adacore.com> wrote:
>> >> ... it is definitely the case that the target currently defines
>> wchar_t,
>> >> and it even offers wchar.h and a lot of (maybe all?) wcs* functions.
>> >> This was likely not the case when the patch was first written.
>> >>
>> >> I'll double check whether any of the patch is still needed for current
>> >> versions.
>>
>> With the tests I've run since yesterday, I've determined that:
>>
>> - the wchar-related patches for the libstdc++ testsuite, that I had
>>   proposed last year, are no longer needed
>>
>> - your two patchlets did not bring about any regressions to test
>>   results, not in mainline x86_64-linux-gnu native, not with the trivial
>>   backports to the gcc-10 tree for x-arm-vxw7r2 that was the focus of my
>>   immediate attention.
>>
>> So, I withdraw my submissions of the testsuite patches, and I encourage
>> you to proceed with the two changes you proposed.
>>
>
> Great, I'll save them in a git branch to be revisited in stage 1.
>

I've committed a series of 8 patches to enable partial wchar_t support even
without a working <wchar.h> in libc. std::wstring and std::wstring_view
should work fine now (albeit slower than if libc provides optimised wcslen
etc.)

Wide character I/O and charset conversions still require libc support, so
are disabled when _GLIBCXX_USE_WCHAR_T is not defined.

I would appreciate confirmation that this hasn't caused any problems for
vxworks (understanding that vxworks does have wide character support in
libc now, as discussed back in January).




>
>
>> However, for avoidance of any doubt, I'll restate that I cannot vow for
>> whether they're enough to fix the issues we'd run into back when
>> wchar/wcs* were not supported in the target system, because now they
>> are, so the changes do not bring any visible improvements to our results
>> either.
>>
>
> Understood, thanks for checking them though.
>
>
>>
diff mbox series

Patch

diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
index 8a092913a4c92..039bdd0322907 100644
--- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
+++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
@@ -16,6 +16,7 @@ 
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do run { target c++11 } }
+// { dg-require-wchars "" }
 
 #include <locale>
 #include <codecvt>
diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc
index 04cfc8d744bdd..3496e0e819e98 100644
--- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc
+++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc
@@ -16,6 +16,7 @@ 
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do run { target c++11 } }
+// { dg-require-wchars "" }
 
 #include <locale>
 #include <codecvt>
diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc
index 68ae5af234ae5..fd69dd5c04de0 100644
--- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc
+++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8/79980.cc
@@ -16,6 +16,7 @@ 
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do run { target c++11 } }
+// { dg-require-wchars "" }
 
 #include <codecvt>
 #include <locale>
diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc
index 1f63e7218e7d2..590a3b73bfc41 100644
--- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc
+++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/79511.cc
@@ -16,6 +16,7 @@ 
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do run { target c++11 } }
+// { dg-require-wchars "" }
 
 #include <locale>
 #include <codecvt>
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/buffer/1.cc b/libstdc++-v3/testsuite/22_locale/conversions/buffer/1.cc
index 2855f7432d464..91bf2bf22160d 100644
--- a/libstdc++-v3/testsuite/22_locale/conversions/buffer/1.cc
+++ b/libstdc++-v3/testsuite/22_locale/conversions/buffer/1.cc
@@ -1,4 +1,5 @@ 
 // { dg-do run { target c++11 } }
+// { dg-require-wchars "" }
 
 // Copyright (C) 2015-2020 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/buffer/2.cc b/libstdc++-v3/testsuite/22_locale/conversions/buffer/2.cc
index 2cf320fc13cca..a03a16a02ed0b 100644
--- a/libstdc++-v3/testsuite/22_locale/conversions/buffer/2.cc
+++ b/libstdc++-v3/testsuite/22_locale/conversions/buffer/2.cc
@@ -16,6 +16,7 @@ 
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do run { target c++11 } }
+// { dg-require-wchars "" }
 
 #include <locale>
 #include <sstream>
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/buffer/3.cc b/libstdc++-v3/testsuite/22_locale/conversions/buffer/3.cc
index de43e0a95b2b7..84d5358f4999c 100644
--- a/libstdc++-v3/testsuite/22_locale/conversions/buffer/3.cc
+++ b/libstdc++-v3/testsuite/22_locale/conversions/buffer/3.cc
@@ -16,6 +16,7 @@ 
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do run { target c++11 } }
+// { dg-require-wchars "" }
 
 #include <locale>
 #include <streambuf>
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc b/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc
index e88799dbec750..8efe203e87398 100644
--- a/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc
+++ b/libstdc++-v3/testsuite/22_locale/conversions/buffer/requirements/typedefs.cc
@@ -1,4 +1,5 @@ 
 // { dg-do compile { target c++11 } }
+// { dg-require-wchars "" }
 
 // Copyright (C) 2015-2020 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc
index 41d6594fe1320..d491e6c52709e 100644
--- a/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc
+++ b/libstdc++-v3/testsuite/22_locale/conversions/string/1.cc
@@ -1,4 +1,5 @@ 
 // { dg-do run { target c++11 } }
+// { dg-require-wchars "" }
 
 // Copyright (C) 2015-2020 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc
index bc26e328a6039..b4867053f3c85 100644
--- a/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc
+++ b/libstdc++-v3/testsuite/22_locale/conversions/string/2.cc
@@ -1,4 +1,5 @@ 
 // { dg-do run { target c++11 } }
+// { dg-require-wchars "" }
 
 // Copyright (C) 2015-2020 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/3.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/3.cc
index b7793cdca49ea..023897c9307b5 100644
--- a/libstdc++-v3/testsuite/22_locale/conversions/string/3.cc
+++ b/libstdc++-v3/testsuite/22_locale/conversions/string/3.cc
@@ -1,4 +1,5 @@ 
 // { dg-do run { target c++11 } }
+// { dg-require-wchars "" }
 
 // Copyright (C) 2015-2020 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/66441.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/66441.cc
index 07136aec1179e..b78c31fbb9b1b 100644
--- a/libstdc++-v3/testsuite/22_locale/conversions/string/66441.cc
+++ b/libstdc++-v3/testsuite/22_locale/conversions/string/66441.cc
@@ -16,6 +16,7 @@ 
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do run { target c++11 } }
+// { dg-require-wchars "" }
 
 // libstdc++/66441
 
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc
index 91b47c449a16a..4cd254a40da57 100644
--- a/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc
+++ b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs-2.cc
@@ -1,4 +1,5 @@ 
 // { dg-do compile { target c++11 } }
+// { dg-require-wchars "" }
 
 // Copyright (C) 2015-2020 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc
index 023caa69a6e3a..30e49b2ff893b 100644
--- a/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc
+++ b/libstdc++-v3/testsuite/22_locale/conversions/string/requirements/typedefs.cc
@@ -1,4 +1,5 @@ 
 // { dg-do compile { target c++11 } }
+// { dg-require-wchars "" }
 
 // Copyright (C) 2015-2020 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp
index 0102acf65a282..17306a0eb0205 100644
--- a/libstdc++-v3/testsuite/lib/dg-options.exp
+++ b/libstdc++-v3/testsuite/lib/dg-options.exp
@@ -16,6 +16,15 @@ 
 # along with this program; see the file COPYING3.  If not see
 # <http://www.gnu.org/licenses/>.
 
+proc dg-require-wchars { args } {
+    if { ![ check_v3_target_wchars ] } {
+	upvar dg-do-what dg-do-what
+	set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+	return
+    }
+    return
+}
+
 proc dg-require-c-std { args } {
     if { ![ check_v3_target_c_std ] } {
 	upvar dg-do-what dg-do-what
diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
index b7d7b906de41c..2c22bcc0f0c94 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -702,6 +702,53 @@  proc v3-build_support { } {
     }
 }
 
+proc check_v3_target_wchars { } {
+    global et_wchars
+    global et_wchars_target_name
+    global tool
+
+    if { ![info exists et_wchars_target_name] } {
+	set et_wchars_target_name ""
+    }
+
+    # If the target has changed since we set the cached value, clear it.
+    set current_target [current_target_name]
+    if { $current_target != $et_wchars_target_name } {
+	verbose "check_v3_target_wchars: `$et_wchars_target_name'" 2
+	set et_wchars_target_name $current_target
+	if [info exists et_wchars] {
+	    verbose "check_v3_target_wchars: removing cached result" 2
+	    unset et_wchars
+	}
+    }
+
+    if [info exists et_wchars] {
+	verbose "check_v3_target_wchars: using cached result" 2
+    } else {
+	set et_wchars 0
+
+	# Set up and preprocess a C++ test program that depends
+	# on wchars support being configured in the libstdc++.
+	set src wchars[pid].cc
+
+	set f [open $src "w"]
+	puts $f "#ifndef _GLIBCXX_USE_WCHAR_T"
+	puts $f "#  error No wchar header."
+	puts $f "#endif"
+	close $f
+
+	set lines [v3_target_compile $src /dev/null preprocess ""]
+	file delete $src
+
+	if [string match "" $lines] {
+	    # No error message, preprocessing succeeded.
+	    set et_wchars 1
+	}
+    }
+    verbose "check_v3_target_wchars: $et_wchars" 2
+    return $et_wchars
+}
+
 # Implement an target check for property PROP by invoking
 # the Tcl command ARGS and seeing if it returns true.