From: Jonathan Wakely <jwakely@redhat.com>
To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH 1/2] libstdc++: Add dg-require-cpp-feature-test to test feature test macros
Date: Tue, 26 Mar 2024 11:44:07 +0000 [thread overview]
Message-ID: <CACb0b4m+QJ7Mo8Zp8fdd8uoFgyjFf5xMb8nTrJ8AiRf7L9rwNg@mail.gmail.com> (raw)
In-Reply-To: <20240323001908.384974-1-jwakely@redhat.com>
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>
>
prev parent reply other threads:[~2024-03-26 11:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Jonathan Wakely
2024-03-26 11:44 ` Jonathan Wakely [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CACb0b4m+QJ7Mo8Zp8fdd8uoFgyjFf5xMb8nTrJ8AiRf7L9rwNg@mail.gmail.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).