public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] libstdc++: Add dg-require-cpp-feature-test to test feature test macros
@ 2024-03-22 23:51 Jonathan Wakely
  2024-03-22 23:51 ` [PATCH 2/2] libstdc++: Replace stacktrace effective target with feature test Jonathan Wakely
  2024-03-26 11:44 ` [PATCH 1/2] libstdc++: Add dg-require-cpp-feature-test to test feature test macros Jonathan Wakely
  0 siblings, 2 replies; 4+ messages in thread
From: Jonathan Wakely @ 2024-03-22 23:51 UTC (permalink / raw)
  To: gcc-patches, libstdc++

Thoughts? There are only a few uses for this presently, but I can see it
being useful often in future. The library exposes which features it
supports in a standardized way, so we can use those in tests to skip
tests for features that aren't available on all targets.

The obvious downside is that it becomes harder to notice if a particular
feature is missing on all targets, because we don't get FAILs we just
skip all tests as UNSUPPORTED. And the checks for whether <version>
correctly defines the macro become redundant, because the test won't
even get run if it doesn't. But we won't use this dg-require for many
tests, only the ones where support is target-dependent because it relies
on something non-standard or not available on all targets (like
nl_langinfo_l or libbacktrace).

-- >8 -

This adds a new dejagnu directive which can be used to make a test
depend on a feature test macro such as __cpp_lib_text_encoding. This is
mroe flexible than writing a new dg-require-xxx for each feature.

libstdc++-v3/ChangeLog:

	* testsuite/lib/dg-options.exp (dg-require-cpp-feature-test):
	New proc.
	* testsuite/lib/libstdc++.exp (check_v3_target_cpp_feature_test):
	New proc.
	* testsuite/std/text_encoding/cons.cc: Use new directive to skip
	the test if the __cpp_lib_text_encoding feature test macro is
	not defined.
	* testsuite/std/text_encoding/requirements.cc: Likewise.
---
 libstdc++-v3/testsuite/lib/dg-options.exp         |  9 +++++++++
 libstdc++-v3/testsuite/lib/libstdc++.exp          | 15 +++++++++++++++
 libstdc++-v3/testsuite/std/text_encoding/cons.cc  |  1 +
 .../testsuite/std/text_encoding/requirements.cc   |  3 ++-
 4 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp
index 00ca678a53a..802bfc0b492 100644
--- a/libstdc++-v3/testsuite/lib/dg-options.exp
+++ b/libstdc++-v3/testsuite/lib/dg-options.exp
@@ -277,6 +277,15 @@ proc dg-require-target-fs-lwt { args } {
     return
 }
 
+proc dg-require-cpp-feature-test { n args } {
+    if { ![ check_v3_target_cpp_feature_test $args ] } {
+	upvar dg-do-what dg-do-what
+	set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+	return
+    }
+    return
+}
+
 proc add_options_for_no_pch { flags } {
     # Remove any inclusion of bits/stdc++.h from the options.
     regsub -all -- "-include bits/stdc...h" $flags "" flags
diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
index 7466fb51c58..2b31c950826 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -1134,6 +1134,21 @@ proc v3_check_preprocessor_condition { name cond { inc "" } } {
     return [v3_try_preprocess name $code $flags]
 }
 
+# Return 1 if libstdc++ defines macro for the current target, 0 otherwise.
+proc check_v3_target_cpp_feature_test { cond } {
+    global cxxflags
+    set cxxflags_saved $cxxflags
+    # Use the latest standard, so that all feature test macros are defined.
+    # We need to do it here, because this check happens before v3-dg-runtest
+    # runs its loop to test multiple times with different -std options.
+    # This should be updated when a new -std is added.
+    set cxxflags "$cxxflags -std=gnu++26"
+    set inc "#include <version>"
+    set result [v3_check_preprocessor_condition cpp_feature_test "$cond" $inc]
+    set cxxflags $cxxflags_saved
+    return $result
+}
+
 # Return 1 if Debug Mode is active, 0 otherwise.
 proc check_v3_target_debug_mode { } {
     global cxxflags
diff --git a/libstdc++-v3/testsuite/std/text_encoding/cons.cc b/libstdc++-v3/testsuite/std/text_encoding/cons.cc
index 8fcc2ec8c3b..4196e32ea8b 100644
--- a/libstdc++-v3/testsuite/std/text_encoding/cons.cc
+++ b/libstdc++-v3/testsuite/std/text_encoding/cons.cc
@@ -1,4 +1,5 @@
 // { dg-do run { target c++26 } }
+// { dg-require-cpp-feature-test "__cpp_lib_text_encoding" }
 
 #include <text_encoding>
 #include <string_view>
diff --git a/libstdc++-v3/testsuite/std/text_encoding/requirements.cc b/libstdc++-v3/testsuite/std/text_encoding/requirements.cc
index a1d5d6baee1..3889b250688 100644
--- a/libstdc++-v3/testsuite/std/text_encoding/requirements.cc
+++ b/libstdc++-v3/testsuite/std/text_encoding/requirements.cc
@@ -1,4 +1,5 @@
 // { dg-do compile { target c++26 } }
+// { dg-require-cpp-feature-test __cpp_lib_text_encoding }
 // { dg-add-options no_pch }
 
 #include <text_encoding>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] libstdc++: Replace stacktrace effective target with feature test
  2024-03-22 23:51 [PATCH 1/2] libstdc++: Add dg-require-cpp-feature-test to test feature test macros Jonathan Wakely
@ 2024-03-22 23:51 ` Jonathan Wakely
  2024-03-26 11:44   ` Jonathan Wakely
  2024-03-26 11:44 ` [PATCH 1/2] libstdc++: Add dg-require-cpp-feature-test to test feature test macros Jonathan Wakely
  1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2024-03-22 23:51 UTC (permalink / raw)
  To: gcc-patches, libstdc++

And this replaces an existing custom dg-require- directive with a use of
the new one that checks for a standard feature test macro. I didn't see
any other existing dg-require-xxx directives that can be replaced like
this.

-- >8 --

Remove the dejagnu code for checking whether std::stacktrace is supported
and just use the new dg-require-cpp-feature-test directive to check for
__cpp_lib_stacktrace instead.

libstdc++-v3/ChangeLog:

	* testsuite/19_diagnostics/stacktrace/current.cc: Check for
	__cpp_lib_stacktrace instead of check for stacktrace ET.
	* testsuite/19_diagnostics/stacktrace/entry.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/hash.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/output.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/stacktrace.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/synopsis.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/version.cc: Likewise.
	* testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc:
	Likewise.
	* testsuite/lib/libstdc++.exp (check_effective_target_stacktrace):
	Remove.
---
 .../testsuite/19_diagnostics/stacktrace/current.cc        | 2 +-
 libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc | 2 +-
 libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc  | 2 +-
 .../testsuite/19_diagnostics/stacktrace/output.cc         | 2 +-
 .../testsuite/19_diagnostics/stacktrace/stacktrace.cc     | 2 +-
 .../testsuite/19_diagnostics/stacktrace/synopsis.cc       | 2 +-
 .../testsuite/19_diagnostics/stacktrace/version.cc        | 2 +-
 .../23_containers/vector/debug/assign4_backtrace_neg.cc   | 2 +-
 libstdc++-v3/testsuite/lib/libstdc++.exp                  | 8 --------
 9 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/current.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/current.cc
index a27836d27af..b1af5f74fb2 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/current.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/current.cc
@@ -1,6 +1,6 @@
 // { dg-options "-lstdc++exp" }
 // { dg-do run { target c++23 } }
-// { dg-require-effective-target stacktrace }
+// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
 
 #include <stacktrace>
 #include <memory>
diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc
index ab016d56400..bb348ebef8f 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc
@@ -1,6 +1,6 @@
 // { dg-options "-lstdc++exp" }
 // { dg-do run { target c++23 } }
-// { dg-require-effective-target stacktrace }
+// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
 
 #include <stacktrace>
 #include "testsuite_hooks.h"
diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc
index 21705098ff0..2176596ae5c 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc
@@ -1,6 +1,6 @@
 // { dg-options "-lstdc++exp" }
 // { dg-do run { target c++23 } }
-// { dg-require-effective-target stacktrace }
+// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
 
 #include <stacktrace>
 #include <testsuite_allocator.h>
diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/output.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/output.cc
index 67f1e0cebaf..e27aea1f508 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/output.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/output.cc
@@ -1,6 +1,6 @@
 // { dg-options "-lstdc++exp" }
 // { dg-do run { target c++23 } }
-// { dg-require-effective-target stacktrace }
+// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
 // { dg-add-options no_pch }
 
 #include <stacktrace>
diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
index 5dfa76951df..070c4157471 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
@@ -1,6 +1,6 @@
 // { dg-options "-lstdc++exp" }
 // { dg-do run { target c++23 } }
-// { dg-require-effective-target stacktrace }
+// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
 
 #include <stacktrace>
 #include "testsuite_allocator.h"
diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/synopsis.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/synopsis.cc
index 9e775b86ac9..b99d382ec26 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/synopsis.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/synopsis.cc
@@ -1,5 +1,5 @@
 // { dg-do compile { target c++23 } }
-// { dg-require-effective-target stacktrace }
+// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
 // { dg-require-normal-namespace "" }
 // { dg-add-options no_pch }
 
diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/version.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/version.cc
index 21c2d48b7b5..1fc7722a6f4 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/version.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/version.cc
@@ -1,5 +1,5 @@
 // { dg-do preprocess { target c++23 } }
-// { dg-require-effective-target stacktrace }
+// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
 // { dg-add-options no_pch }
 
 #include <version>
diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc
index 43a82fb1201..2f7238c590c 100644
--- a/libstdc++-v3/testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc
+++ b/libstdc++-v3/testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc
@@ -1,6 +1,6 @@
 // { dg-do run { xfail *-*-* } }
 // { dg-options "-D_GLIBCXX_DEBUG_BACKTRACE -lstdc++exp" }
-// { dg-require-effective-target stacktrace }
+// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
 
 #include <debug/vector>
 #include <debug/checks.h>
diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
index 2b31c950826..67a63f5b5f3 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -1570,14 +1570,6 @@ proc check_effective_target_std_allocator_new { } {
     }]
 }
 
-# Return 1 if libstdc++ was built as --enable-libstdcxx-backtrace
-proc check_effective_target_stacktrace { } {
-    return [check_v3_target_prop_cached et_stacktrace {
-	set cond "_GLIBCXX_HAVE_STACKTRACE && _GLIBCXX_HOSTED"
-	return [v3_check_preprocessor_condition stacktrace $cond]
-    }]
-}
-
 # Return 1 if RTTI is enabled by the current test flags.
 proc check_effective_target_rtti { } {
     return [check_v3_target_prop_cached et_rtti {
-- 
2.44.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] libstdc++: Replace stacktrace effective target with feature test
  2024-03-22 23:51 ` [PATCH 2/2] libstdc++: Replace stacktrace effective target with feature test Jonathan Wakely
@ 2024-03-26 11:44   ` Jonathan Wakely
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2024-03-26 11:44 UTC (permalink / raw)
  To: gcc-patches, libstdc++

Pushed to trunk.

On Sat, 23 Mar 2024 at 00:22, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> And this replaces an existing custom dg-require- directive with a use of
> the new one that checks for a standard feature test macro. I didn't see
> any other existing dg-require-xxx directives that can be replaced like
> this.
>
> -- >8 --
>
> Remove the dejagnu code for checking whether std::stacktrace is supported
> and just use the new dg-require-cpp-feature-test directive to check for
> __cpp_lib_stacktrace instead.
>
> libstdc++-v3/ChangeLog:
>
>         * testsuite/19_diagnostics/stacktrace/current.cc: Check for
>         __cpp_lib_stacktrace instead of check for stacktrace ET.
>         * testsuite/19_diagnostics/stacktrace/entry.cc: Likewise.
>         * testsuite/19_diagnostics/stacktrace/hash.cc: Likewise.
>         * testsuite/19_diagnostics/stacktrace/output.cc: Likewise.
>         * testsuite/19_diagnostics/stacktrace/stacktrace.cc: Likewise.
>         * testsuite/19_diagnostics/stacktrace/synopsis.cc: Likewise.
>         * testsuite/19_diagnostics/stacktrace/version.cc: Likewise.
>         * testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc:
>         Likewise.
>         * testsuite/lib/libstdc++.exp (check_effective_target_stacktrace):
>         Remove.
> ---
>  .../testsuite/19_diagnostics/stacktrace/current.cc        | 2 +-
>  libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc | 2 +-
>  libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc  | 2 +-
>  .../testsuite/19_diagnostics/stacktrace/output.cc         | 2 +-
>  .../testsuite/19_diagnostics/stacktrace/stacktrace.cc     | 2 +-
>  .../testsuite/19_diagnostics/stacktrace/synopsis.cc       | 2 +-
>  .../testsuite/19_diagnostics/stacktrace/version.cc        | 2 +-
>  .../23_containers/vector/debug/assign4_backtrace_neg.cc   | 2 +-
>  libstdc++-v3/testsuite/lib/libstdc++.exp                  | 8 --------
>  9 files changed, 8 insertions(+), 16 deletions(-)
>
> diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/current.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/current.cc
> index a27836d27af..b1af5f74fb2 100644
> --- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/current.cc
> +++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/current.cc
> @@ -1,6 +1,6 @@
>  // { dg-options "-lstdc++exp" }
>  // { dg-do run { target c++23 } }
> -// { dg-require-effective-target stacktrace }
> +// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
>
>  #include <stacktrace>
>  #include <memory>
> diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc
> index ab016d56400..bb348ebef8f 100644
> --- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc
> +++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/entry.cc
> @@ -1,6 +1,6 @@
>  // { dg-options "-lstdc++exp" }
>  // { dg-do run { target c++23 } }
> -// { dg-require-effective-target stacktrace }
> +// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
>
>  #include <stacktrace>
>  #include "testsuite_hooks.h"
> diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc
> index 21705098ff0..2176596ae5c 100644
> --- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc
> +++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/hash.cc
> @@ -1,6 +1,6 @@
>  // { dg-options "-lstdc++exp" }
>  // { dg-do run { target c++23 } }
> -// { dg-require-effective-target stacktrace }
> +// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
>
>  #include <stacktrace>
>  #include <testsuite_allocator.h>
> diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/output.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/output.cc
> index 67f1e0cebaf..e27aea1f508 100644
> --- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/output.cc
> +++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/output.cc
> @@ -1,6 +1,6 @@
>  // { dg-options "-lstdc++exp" }
>  // { dg-do run { target c++23 } }
> -// { dg-require-effective-target stacktrace }
> +// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
>  // { dg-add-options no_pch }
>
>  #include <stacktrace>
> diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
> index 5dfa76951df..070c4157471 100644
> --- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
> +++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
> @@ -1,6 +1,6 @@
>  // { dg-options "-lstdc++exp" }
>  // { dg-do run { target c++23 } }
> -// { dg-require-effective-target stacktrace }
> +// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
>
>  #include <stacktrace>
>  #include "testsuite_allocator.h"
> diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/synopsis.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/synopsis.cc
> index 9e775b86ac9..b99d382ec26 100644
> --- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/synopsis.cc
> +++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/synopsis.cc
> @@ -1,5 +1,5 @@
>  // { dg-do compile { target c++23 } }
> -// { dg-require-effective-target stacktrace }
> +// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
>  // { dg-require-normal-namespace "" }
>  // { dg-add-options no_pch }
>
> diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/version.cc b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/version.cc
> index 21c2d48b7b5..1fc7722a6f4 100644
> --- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/version.cc
> +++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/version.cc
> @@ -1,5 +1,5 @@
>  // { dg-do preprocess { target c++23 } }
> -// { dg-require-effective-target stacktrace }
> +// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
>  // { dg-add-options no_pch }
>
>  #include <version>
> diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc
> index 43a82fb1201..2f7238c590c 100644
> --- a/libstdc++-v3/testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc
> +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc
> @@ -1,6 +1,6 @@
>  // { dg-do run { xfail *-*-* } }
>  // { dg-options "-D_GLIBCXX_DEBUG_BACKTRACE -lstdc++exp" }
> -// { dg-require-effective-target stacktrace }
> +// { dg-require-cpp-feature-test __cpp_lib_stacktrace }
>
>  #include <debug/vector>
>  #include <debug/checks.h>
> diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
> index 2b31c950826..67a63f5b5f3 100644
> --- a/libstdc++-v3/testsuite/lib/libstdc++.exp
> +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
> @@ -1570,14 +1570,6 @@ proc check_effective_target_std_allocator_new { } {
>      }]
>  }
>
> -# Return 1 if libstdc++ was built as --enable-libstdcxx-backtrace
> -proc check_effective_target_stacktrace { } {
> -    return [check_v3_target_prop_cached et_stacktrace {
> -       set cond "_GLIBCXX_HAVE_STACKTRACE && _GLIBCXX_HOSTED"
> -       return [v3_check_preprocessor_condition stacktrace $cond]
> -    }]
> -}
> -
>  # Return 1 if RTTI is enabled by the current test flags.
>  proc check_effective_target_rtti { } {
>      return [check_v3_target_prop_cached et_rtti {
> --
> 2.44.0
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] libstdc++: Add dg-require-cpp-feature-test to test feature test macros
  2024-03-22 23:51 [PATCH 1/2] libstdc++: Add dg-require-cpp-feature-test to test feature test macros Jonathan Wakely
  2024-03-22 23:51 ` [PATCH 2/2] libstdc++: Replace stacktrace effective target with feature test Jonathan Wakely
@ 2024-03-26 11:44 ` Jonathan Wakely
  1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2024-03-26 11:44 UTC (permalink / raw)
  To: gcc-patches, libstdc++

Pushed to trunk.

On Sat, 23 Mar 2024 at 00:22, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> Thoughts? There are only a few uses for this presently, but I can see it
> being useful often in future. The library exposes which features it
> supports in a standardized way, so we can use those in tests to skip
> tests for features that aren't available on all targets.
>
> The obvious downside is that it becomes harder to notice if a particular
> feature is missing on all targets, because we don't get FAILs we just
> skip all tests as UNSUPPORTED. And the checks for whether <version>
> correctly defines the macro become redundant, because the test won't
> even get run if it doesn't. But we won't use this dg-require for many
> tests, only the ones where support is target-dependent because it relies
> on something non-standard or not available on all targets (like
> nl_langinfo_l or libbacktrace).
>
> -- >8 -
>
> This adds a new dejagnu directive which can be used to make a test
> depend on a feature test macro such as __cpp_lib_text_encoding. This is
> mroe flexible than writing a new dg-require-xxx for each feature.
>
> libstdc++-v3/ChangeLog:
>
>         * testsuite/lib/dg-options.exp (dg-require-cpp-feature-test):
>         New proc.
>         * testsuite/lib/libstdc++.exp (check_v3_target_cpp_feature_test):
>         New proc.
>         * testsuite/std/text_encoding/cons.cc: Use new directive to skip
>         the test if the __cpp_lib_text_encoding feature test macro is
>         not defined.
>         * testsuite/std/text_encoding/requirements.cc: Likewise.
> ---
>  libstdc++-v3/testsuite/lib/dg-options.exp         |  9 +++++++++
>  libstdc++-v3/testsuite/lib/libstdc++.exp          | 15 +++++++++++++++
>  libstdc++-v3/testsuite/std/text_encoding/cons.cc  |  1 +
>  .../testsuite/std/text_encoding/requirements.cc   |  3 ++-
>  4 files changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp
> index 00ca678a53a..802bfc0b492 100644
> --- a/libstdc++-v3/testsuite/lib/dg-options.exp
> +++ b/libstdc++-v3/testsuite/lib/dg-options.exp
> @@ -277,6 +277,15 @@ proc dg-require-target-fs-lwt { args } {
>      return
>  }
>
> +proc dg-require-cpp-feature-test { n args } {
> +    if { ![ check_v3_target_cpp_feature_test $args ] } {
> +       upvar dg-do-what dg-do-what
> +       set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
> +       return
> +    }
> +    return
> +}
> +
>  proc add_options_for_no_pch { flags } {
>      # Remove any inclusion of bits/stdc++.h from the options.
>      regsub -all -- "-include bits/stdc...h" $flags "" flags
> diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
> index 7466fb51c58..2b31c950826 100644
> --- a/libstdc++-v3/testsuite/lib/libstdc++.exp
> +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
> @@ -1134,6 +1134,21 @@ proc v3_check_preprocessor_condition { name cond { inc "" } } {
>      return [v3_try_preprocess name $code $flags]
>  }
>
> +# Return 1 if libstdc++ defines macro for the current target, 0 otherwise.
> +proc check_v3_target_cpp_feature_test { cond } {
> +    global cxxflags
> +    set cxxflags_saved $cxxflags
> +    # Use the latest standard, so that all feature test macros are defined.
> +    # We need to do it here, because this check happens before v3-dg-runtest
> +    # runs its loop to test multiple times with different -std options.
> +    # This should be updated when a new -std is added.
> +    set cxxflags "$cxxflags -std=gnu++26"
> +    set inc "#include <version>"
> +    set result [v3_check_preprocessor_condition cpp_feature_test "$cond" $inc]
> +    set cxxflags $cxxflags_saved
> +    return $result
> +}
> +
>  # Return 1 if Debug Mode is active, 0 otherwise.
>  proc check_v3_target_debug_mode { } {
>      global cxxflags
> diff --git a/libstdc++-v3/testsuite/std/text_encoding/cons.cc b/libstdc++-v3/testsuite/std/text_encoding/cons.cc
> index 8fcc2ec8c3b..4196e32ea8b 100644
> --- a/libstdc++-v3/testsuite/std/text_encoding/cons.cc
> +++ b/libstdc++-v3/testsuite/std/text_encoding/cons.cc
> @@ -1,4 +1,5 @@
>  // { dg-do run { target c++26 } }
> +// { dg-require-cpp-feature-test "__cpp_lib_text_encoding" }
>
>  #include <text_encoding>
>  #include <string_view>
> diff --git a/libstdc++-v3/testsuite/std/text_encoding/requirements.cc b/libstdc++-v3/testsuite/std/text_encoding/requirements.cc
> index a1d5d6baee1..3889b250688 100644
> --- a/libstdc++-v3/testsuite/std/text_encoding/requirements.cc
> +++ b/libstdc++-v3/testsuite/std/text_encoding/requirements.cc
> @@ -1,4 +1,5 @@
>  // { dg-do compile { target c++26 } }
> +// { dg-require-cpp-feature-test __cpp_lib_text_encoding }
>  // { dg-add-options no_pch }
>
>  #include <text_encoding>
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-26 11:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-22 23:51 [PATCH 1/2] libstdc++: Add dg-require-cpp-feature-test to test feature test macros Jonathan Wakely
2024-03-22 23:51 ` [PATCH 2/2] libstdc++: Replace stacktrace effective target with feature test Jonathan Wakely
2024-03-26 11:44   ` Jonathan Wakely
2024-03-26 11:44 ` [PATCH 1/2] libstdc++: Add dg-require-cpp-feature-test to test feature test macros Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).