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 CD98D3858C33 for ; Sat, 23 Mar 2024 00:19:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD98D3858C33 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 CD98D3858C33 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=1711153163; cv=none; b=HTYW2hHNvMiGTh4cm3hVJP15AHeoKN6dOHhbVl2Wt9RGd0zo+Hp/EaOm19g4jxUg3FdLiQKHbCXxn1Ac2TGk5tjBTrU9IuvT/VrrgF55EmuiFM0AZvrdr/BWvOxkiH1lkqYdicuHFRHhplcssODfRyPCPoPthjdnBwW8HReHzEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711153163; c=relaxed/simple; bh=A7C+Urdx6mYv8Q6ZlolfEC9rJJOJdab0kJq+JFQ3bb8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DPucOfYz4xYAkBce1coZnZS4B13HeWTcl4OeUCgtOmDw9BJoyl4ztzOA7UI011sBYRsXAwcV3ohMjUBhHfcRgSTVDeT/A9AWeYL3aGksFrM24EBYOAQb+Uz0KbEj/vvANSFoaa0b0+aPhw1bnKoEBi/6rAB91/kcdKFWA8TJZCQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711153155; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sY0XYaeNq8QUf8U1rcxkJTwMjD+s5iLbBK/Ptp/I5Vk=; b=FIcbtwAy5IRpVV1W/PBqGEKDQiMvowfGxAR+xI+WB6Tt2pUK03kppPZ/di/JbAzPrMP+7c uagQPFrQlt5zdToYY9BEUiCBVE9Uk+7b+dHPLIIbazgv242HzKPTViXZhoC85sRjQRMxYQ KqAZk1wzu2hN+cBDtsYU3J2IhcggFTQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-JI3mq_raMWq2PxZmb_3OuA-1; Fri, 22 Mar 2024 20:19:13 -0400 X-MC-Unique: JI3mq_raMWq2PxZmb_3OuA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 820053804A0E; Sat, 23 Mar 2024 00:19:13 +0000 (UTC) Received: from localhost (unknown [10.42.28.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FC872166B4F; Sat, 23 Mar 2024 00:19:13 +0000 (UTC) From: Jonathan Wakely To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: [PATCH 1/2] libstdc++: Add dg-require-cpp-feature-test to test feature test macros Date: Fri, 22 Mar 2024 23:51:26 +0000 Message-ID: <20240323001908.384974-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.2 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: 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