From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 39C3F3858416 for ; Tue, 26 Mar 2024 11:44:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 39C3F3858416 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 39C3F3858416 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711453468; cv=none; b=j8JuPFIy7VPwULCjPQwDS4weDogoKrTuaEaA+AQMNM3v/7Kx6UlBXe2/o9EnaEZGS0x0x0p0sZRqmKN9ptnTm9pKNmCGPBsBD9nbJASky9TzqokdODruRzOlWutWJBbdf/6Rp+5CligvV9mshIUxoFN+PEsI+r+oSZEsuiEtb60= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711453468; c=relaxed/simple; bh=bfZVwZzwIXi9Sf8ERIfkDVhqAXOjkugRf17TlU9M2Z8=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=SIi9qqsO3gdW07o/W5ZyIRUYD2YlMEc7ZHlcUPwMyEPOnI/NqMDEHwOoTbKyyrGL/AnpUHhT8Ry8i9o4IlxDCpOUv3mzYxeg2TGMc2jNQtOyw7J7nFeYuZtpMAZT2ReMZDc1PItS4M8F03BuTaqNwyTs8RjdfkKsFiVE7hc3+U4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711453465; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xmEGrf7aB6/S8u/YbXO0DWNTNED7zpHiWewUhRL21iM=; b=LLccFxxxuhhrZ60HNA+33tIASnx5fN7EePPbESFm1B/pWeg9tPHpjO6sy0gkzsDDR9GzLR fcR4Bn7lD6or+CWNAIyu+Sgm/HmcIheY8zuMtpFrbhfvos10ghM3ezwJZN3qKvmZLNFipF DL0KMCDZcHVuvtBLIaIVXLogvt8mCjA= Received: from mail-yb1-f198.google.com (mail-yb1-f198.google.com [209.85.219.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-255-sjdR8F_HPCiatGMr_tdIZg-1; Tue, 26 Mar 2024 07:44:24 -0400 X-MC-Unique: sjdR8F_HPCiatGMr_tdIZg-1 Received: by mail-yb1-f198.google.com with SMTP id 3f1490d57ef6-dced704f17cso8633684276.1 for ; Tue, 26 Mar 2024 04:44:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711453464; x=1712058264; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xmEGrf7aB6/S8u/YbXO0DWNTNED7zpHiWewUhRL21iM=; b=wBXRZovtSoaY106Rb7yRi2BcTfJ1TT46P8VwJc8Wb01+DKUpOrHCl4a/hnTSjWK5QW La0/aPYLy/YIPgBxHU3Umlt2D1f5JAeEh8QZvDtwDSik4fHoppFqB49Bnr5eWxd9DLmX E0qXZnpNJpr/a9C35uaIgg3s+SflWIK2P8nlXvrWto4dFM3pUMZySO53nsBu7kjJCJUb jF+Q9fJKkNZvfgJMW+WMzi9eRTv4GnJg/kvK9H8pb8O/mvcl1TrFrQXprW68bHsbKw/T jLotgmoYtNiWO0Kdl5qO8H555c5HruMQhHzdA4j8gwtFhjdvVr+vCQ30BX5kd94jX3mN R59A== X-Forwarded-Encrypted: i=1; AJvYcCUjsw/CqOfFLp9tkVyKbEjXQtH0lMdp25H8BpodEMzYpiHL2qx5VKHs+xcA8AIbgxKyzIt04OesDejcP1XZ5d8nGthqr0Q= X-Gm-Message-State: AOJu0YyYQDTg1fgQPVo2k5pH07UMjAA8gzn0Sk6zTwm0WcS65PebQB0o c7BJG/ZlJ0wjSmU3Z4jYF47goWqMUtIlYgNNzgdt6swZeetz4A7fYre7XBboJ2yj7Ed306NDe+b zAQ4kO1P+ixzmI1+gfuzaNxOFuwo4hnTXf3mNw6R2tannA4R4Q6eYDoo0Ipw1PKXZI/LvsxXJYQ QEF5hvdvuq0rsdQ/10M1rq0EhpO7o= X-Received: by 2002:a25:8e06:0:b0:dc6:ff32:aaea with SMTP id p6-20020a258e06000000b00dc6ff32aaeamr736430ybl.24.1711453463787; Tue, 26 Mar 2024 04:44:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF9ur5beJhxR9BF/j0EitdnTnvUQzAw4OUv/9gpH4L9RiiJGUJPaRYdLwnk07VaH7PH+anbR5fGIstP+mljwWc= X-Received: by 2002:a25:8e06:0:b0:dc6:ff32:aaea with SMTP id p6-20020a258e06000000b00dc6ff32aaeamr736417ybl.24.1711453463502; Tue, 26 Mar 2024 04:44:23 -0700 (PDT) MIME-Version: 1.0 References: <20240323001908.384974-1-jwakely@redhat.com> In-Reply-To: <20240323001908.384974-1-jwakely@redhat.com> From: Jonathan Wakely Date: Tue, 26 Mar 2024 11:44:07 +0000 Message-ID: Subject: Re: [PATCH 1/2] libstdc++: Add dg-require-cpp-feature-test to test feature test macros To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Pushed to trunk. On Sat, 23 Mar 2024 at 00:22, Jonathan Wakely 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 > 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 " > + 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 > #include > 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 >