From patchwork Wed Feb 12 16:23:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Malcomson X-Patchwork-Id: 106388 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 483F73858410 for ; Wed, 12 Feb 2025 16:25:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 483F73858410 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=Cz1Etiz6 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062a.outbound.protection.outlook.com [IPv6:2a01:111:f403:200a::62a]) by sourceware.org (Postfix) with ESMTPS id E11993858C53 for ; Wed, 12 Feb 2025 16:24:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E11993858C53 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nvidia.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E11993858C53 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:200a::62a ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1739377484; cv=pass; b=YwJ1Jo0NAXkjteXHRuhXrNj4XVGrVGy2KX29EuP1nM5A1IIU033M+ddbRjhKactyv8b4S7sLsOXm+jJX+fCCHLxrUiqxkXMQO6IFztu0MM4LSotoyru9txvaK3dnxzUtlEjhs6oMtdqpx2EUjudwyCzYv42vydIZMnZ+Kl8wvIo= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1739377484; c=relaxed/simple; bh=I7wp6+7tVbj+7YbNA4j01zomMFFQY446kNigdCrDGvc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EH0MYq+1q6VmY+RISUE8tiPHz8Ec8QKOnUZlTQMpFqHcsOxwgYA1qlRc3iwH4Ic6w0r4OksPgH7i4bjk+c5/24ROrphRUpPZDYBTQsSHWQqWRg4Hg0s6OHt3nWlCx9IBjUJo3MyOQVW19Fj3YGirKVbkkqElVMJZV0L/VZQLp5w= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E11993858C53 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Q71o3x7FXds/1ZqPF/B0Lthh9RXjKtz9D87recCSa1c7yIAZHvitIdohqShA93VthRUsU/AyDBVnVomwu0qTWG6eiRLGnbUnYMA9lAlH09ibLcIDy1Xh1yAOmGhH2qAYKtP1jRLLpIBB+tvytud8aNTnQW0M3klOX/Fpwlok94aRmlGBNCEVN7kXmt1+Hvd53ofh+wc/7CepCMsl1OK5B+vjibKR5n+M7Cz7CS0SOa8IHr0frqlmc2BftgEIIoTKp8MsyeOn4lmUetHWu+aA4GMBZZA/i2PuPE7M57+teNSLZwnN86DjOHyR98gcPfquE/9/k9MJmOBo82lJdudMzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9ir2lNvmd6PaFg8J1Ej67Bh/zHU0SIlqi+Uv8jWGsvM=; b=AOTOkpxSL+Nqdpz3BKfNrATZPeE0rsz8duhzRhp8Dide5V5cpYAbRE+jZ4+WLB3QyaF3ImHPOX4Rdt78v0rbSslKA4Iq01QD8NSUMEVxWRH1Nxl9wGpFUb1A03eENzxaUyKvs1XGBe6tkG8c4Y/CWu3VsZ3oGaVYqTQ7UtvTvrsS/k/+JvUIPjhHCqgzRBIszUGLAXh8x3DTVnqfat19+yHo3WTOJsmSU2e6yiqLfBJiMDkjjY84gWeeTEJWvzzgBZWrItJqIOvWJ9nlQSLv31jRda24QghEgGgyasTyT6UabWI8LklfWkXmFWqweJgFe/TEucXEdMcAhIdGFSACHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9ir2lNvmd6PaFg8J1Ej67Bh/zHU0SIlqi+Uv8jWGsvM=; b=Cz1Etiz6E5eQ/PKv8mbWQeXXWjW7LnrdnUCiUMJcC2FQQseajn3DM1LHgqkQQiqmi3iipeOrx2GjZnRW1zXP821pfj18mg3LMFArG+dQ5QJ6yuB5Gj1b0KzpYDJM6s4zCj359iO7WzsAxjKfJR1Wda0oNkL6OKv7nTukLSCT6v3WzDyq8my/ChpF9wBcarB76X7UnMv1v4TtwcJRQ/WnypSWh8PQgX3r79lTR20ZEMMiXMc6I9O9mF0VlWQMbHBlvQpiriunPJvanpXDysehG/6juKeN1CvdRgUZNuCz5/MFfIBOT9vPsCxMAEXLp0FDBBID9ChoBWRHw+M9+z143A== Received: from CH2PR16CA0011.namprd16.prod.outlook.com (2603:10b6:610:50::21) by SN7PR12MB6765.namprd12.prod.outlook.com (2603:10b6:806:26b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8445.13; Wed, 12 Feb 2025 16:24:37 +0000 Received: from CH3PEPF0000000B.namprd04.prod.outlook.com (2603:10b6:610:50:cafe::1e) by CH2PR16CA0011.outlook.office365.com (2603:10b6:610:50::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8445.13 via Frontend Transport; Wed, 12 Feb 2025 16:24:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CH3PEPF0000000B.mail.protection.outlook.com (10.167.244.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8445.10 via Frontend Transport; Wed, 12 Feb 2025 16:24:36 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 12 Feb 2025 08:24:23 -0800 Received: from f2784bb-lcelt.nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Wed, 12 Feb 2025 08:24:22 -0800 From: To: CC: Jason Merrill , Mike Stump , Rainer Orth , Matthew Malcomson Subject: [PATCH] gcc: testsuite: Fix builtin-speculation-overloads[14].C testism Date: Wed, 12 Feb 2025 16:23:44 +0000 Message-ID: <20250212162344.211836-1-mmalcomson@nvidia.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PEPF0000000B:EE_|SN7PR12MB6765:EE_ X-MS-Office365-Filtering-Correlation-Id: df39683f-1abd-4d89-a474-08dd4b81bdd8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: cdVsn2FIobUzwj6DZMvgasgL7MCzPriRq9kxAp4VXnvEWydAyZPoRE+UNydrlOSNS2KhKAH4dm/5GX982+vj4aEOOXqTpzY7tK0c8U9KaoSPR1fALf6neRbJndVQCT27LOLrzxk0zy/Rckqk6WvJvVhjR9ZJrIEX++fxkvFSkNwP9UuC9EamJEOm9iAEzjN+njxvAlSYZglTdBr22CuzfTjZQGrNF+IfMMGeVAq8r4R4IcuelYSNHWbq+/cRKuCTbmFeV2r9VAW7kfvTTXG3yi5y0VsVjM2qNt03q45789jEH3WMizvUbP9MT2LAEAODxrljs6c+0Nbdy8mOCHA3CW3FR//BU61FM1V5fU1zwdprmzdzs2VGjIPqMYzgbs2GzwtQiByrnokBJicGFWE2HbhYqGfG97et5w2xOrGQc0DxQWvXtmbsDGXKgT2xsgjY+tvN6gu32X9QNpn+lgRfh6Bz10EIVpUNsvHt7AeRnsMh7Umb0Mme4OF+20UlKhdmV7tHCCP01hSuPAi8tBba7fstsrpU2Ce+r3K5Fw8sJFiY3IoxZOatIxIQcOgNfIx1eZaIIulKtkGVunW7EM5uyz0pYnhN7HBx6ZyIH5OYNjpy6Xsuf4hcEyS7QA8ZQIJezL0l/67PMy7hfyi7Z8yqXCEqAkc4irjFzqEaGLnGUGAV6X+Fckrti+TNnI1wQKwPO0IvDfO7yTdV8ZGj+DQfkP7BiAos+aVmtZlwzHvFBQ/5dStArWnM1h3RvhShJBUB/q8szuTLxMYu/I7QJ1DPHqglIgCLlxwrWdDXqRx15ToGSkV5CKJaqed/XziW2s049IYEGRT6mrWiWN4hl4rmO3YRCwa6lAi1QBOP2xpM9fhK4X5zMH/bSD2LZkKU+38/YIMmKMFY8cDNd31UwI9JS8W6NHlOi36fq0wsrDGmDa5kZRhHoxzlrBzkW+VZTpUGeridyVkoLC4TD/xTeTBeo2RBVtMBzLVXS81WrTS07Y4RR6OeLkIBllVsAV5DTHDMHGiE4hbddGm1nQfA3ZYYTDnZTpigphpj9dBliyptwMqxJnZx+jQncxI38cyS9t1cr75ql+/u5bq34TauuhVfckIIkkISEcy3LOYYS1w29zxtzxVhPEpeUlNrwUSwWq5uPZsZ6wItpsuGtqfTgjW/CbkfeFOECjD9W7KEInL+Q7My4/KtpcIUCqYBiOeAf5oTpWw5CpOKoeLgi/pijJ+P3VlDOQWJdv7yM18j0EmCkQ0jnhZtszp7hkmFmLk3UcwwhaWTTCNaCgaUg4M+ffDoQfcO234x6iVwWKZf9g0ONfw++742k9aqno73EMvfvwYW6hYVfymyveq5ih2FkbFd7JsdXL6LjnNgLG2J3yNKRj/AW81aq3AdY33y2Q/yOZM5S/Rf7vVQCoYFeZUom3xOkkbmEoPc1itpPa2qv2nSE39snpjet5VFMm5x+YkUzf7J+T3CFm0qTEZfTcrS7tTfFluRp2nczI5HFR0ugxTcS+Q= X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230040)(1800799024)(376014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2025 16:24:36.3028 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: df39683f-1abd-4d89-a474-08dd4b81bdd8 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH3PEPF0000000B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6765 X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FORGED_SPF_HELO, GIT_PATCH_0, LOCAL_AUTHENTICATION_FAIL_SPF, SPF_HELO_PASS, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org From: Matthew Malcomson I've posted the patch on the relevant Bugzilla, but also sending to mailing list. If should have only done one please do mention. ----------------- 8< ----------- >8 ---------------- When making warnings trigger a failure in template substitution I could not find any way to trigger the warning about builtin speculation not being available on the given target. Turns out I misread the code -- this warning happens when the speculation_barrier pattern is not defined. Here we add an effective target to represent "__builtin_speculation_safe_value is available on this target" and use that to adjust our test on SFINAE behaviour accordingly. N.b. this means that we get extra testing -- not just that things work on targets which support __builtin_speculation_safe_value, but also that the behaviour works on targets which don't support it. Tested with AArch64 native, AArch64 cross compiler, and RISC-V cross compiler (just running the tests that I've changed). Points of interest for any reviewer: In the new `check_known_compiler_messages_nocache` procedure I use some procedures from `prune.exp`. This works for the use I need in the g++ testsuite since g++.exp imports prune.exp and g++-dg.exp includes gcc-dg.exp which does the initialisation of prune_notes (needed for this procedure). - Would it be preferred to include a `load_lib prune.exp` statement at the top of `target-supports.exp` in order to use this procedure? - What about the handling of `initialize_prune_notes` which must have been called before calling `prune_gcc_output`? - I believe it's sensible to not use `gcc-dg-prune` which wraps `prune_gcc_output` since I don't believe the wrapping functionality useful here -- wanted to highlight that decision for review. Ok for trunk? gcc/testsuite/ChangeLog: PR/117991 * g++.dg/template/builtin-speculation-overloads.def: SUCCESS argument in SPECULATION_ASSERTS now uses a macro `true_def` instead of the literal `true` for arguments which should work with `__builtin_speculation_safe_value`. * g++.dg/template/builtin-speculation-overloads1.C: Define `true_def` macro on command line to compiler according to the effective target representing that `__builtin_speculation_safe_value` does something on this target. * g++.dg/template/builtin-speculation-overloads4.C: Likewise. * lib/target-supports.exp (check_known_compiler_messages_nocache): New. (check_effective_target_speculation_barrier_defined): New. Signed-off-by: Matthew Malcomson --- .../builtin-speculation-overloads.def | 9 ++- .../template/builtin-speculation-overloads1.C | 2 + .../template/builtin-speculation-overloads4.C | 2 + gcc/testsuite/lib/target-supports.exp | 62 +++++++++++++++++++ 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/g++.dg/template/builtin-speculation-overloads.def b/gcc/testsuite/g++.dg/template/builtin-speculation-overloads.def index 39d9b748d52..ada13e6f77c 100644 --- a/gcc/testsuite/g++.dg/template/builtin-speculation-overloads.def +++ b/gcc/testsuite/g++.dg/template/builtin-speculation-overloads.def @@ -15,14 +15,17 @@ class X{}; class Large { public: int arr[10]; }; class Incomplete; +/* Using `true_def` in order to account for the fact that if this target + * doesn't support __builtin_speculation_safe_value at all everything fails to + * substitute. */ #define SPECULATION_ASSERTS \ - MAKE_SPECULATION_ASSERT (int, true) \ + MAKE_SPECULATION_ASSERT (int, true_def) \ MAKE_SPECULATION_ASSERT (float, false) \ MAKE_SPECULATION_ASSERT (X, false) \ MAKE_SPECULATION_ASSERT (Large, false) \ MAKE_SPECULATION_ASSERT (Incomplete, false) \ - MAKE_SPECULATION_ASSERT (int *, true) \ - MAKE_SPECULATION_ASSERT (long, true) + MAKE_SPECULATION_ASSERT (int *, true_def) \ + MAKE_SPECULATION_ASSERT (long, true_def) int main() { SPECULATION_ASSERTS diff --git a/gcc/testsuite/g++.dg/template/builtin-speculation-overloads1.C b/gcc/testsuite/g++.dg/template/builtin-speculation-overloads1.C index bc8f1083a99..4c50d4aa6f5 100644 --- a/gcc/testsuite/g++.dg/template/builtin-speculation-overloads1.C +++ b/gcc/testsuite/g++.dg/template/builtin-speculation-overloads1.C @@ -1,5 +1,7 @@ /* Check that overloaded builtins can be used in templates with SFINAE. */ // { dg-do compile { target c++17 } } +// { dg-additional-options "-Dtrue_def=true" { target speculation_barrier_defined } } +// { dg-additional-options "-Dtrue_def=false" { target { ! speculation_barrier_defined } } } /* Checks performed here: Various types (some that work, some that don't). */ diff --git a/gcc/testsuite/g++.dg/template/builtin-speculation-overloads4.C b/gcc/testsuite/g++.dg/template/builtin-speculation-overloads4.C index c024a21fa18..cc0b3131af7 100644 --- a/gcc/testsuite/g++.dg/template/builtin-speculation-overloads4.C +++ b/gcc/testsuite/g++.dg/template/builtin-speculation-overloads4.C @@ -1,5 +1,7 @@ /* Check that overloaded builtins can be used in templates with SFINAE. */ // { dg-do compile { target c++17 } } +// { dg-additional-options "-Dtrue_def=true" { target speculation_barrier_defined } } +// { dg-additional-options "-Dtrue_def=false" { target { ! speculation_barrier_defined } } } /* Checks performed here: Optional parameter missing works same as with optional parameter specified. */ diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index ff95b88f3c4..b8a667d9187 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -180,8 +180,51 @@ proc clear_effective_target_cache { } { array unset et_cache } +# Like check_no_compiler_messages_nocache, but returns true if the compiler +# printed a known set of messages. `messages` is a list of messages to expect +# *after* pruning with `prune_gcc_output` and removing empty lines. Each entry +# in the list should be a regexp pattern matching each line of the output in +# turn. +proc check_known_compiler_messages_nocache { messages args } { + verbose "Arguments: $args" 3 + verbose "messages: \"$messages\"" 3 + initialize_prune_notes + set result [eval check_compile $args] + set tool_output [lindex $result 0] + set output_file [lindex $result 1] + remote_file build delete $output_file + verbose "pruning output of: \"$tool_output\"" 3 + set tool_output [prune_gcc_output $tool_output] + set lines [split $tool_output "\n"] + # Remove empty lines to make interface to this procedure nice. + verbose "Comparing \"$lines\" against \"$messages\"" 3 + set lines [lmap value $lines { + if { ! [string match "" $value] } { + string cat $value + } else { + continue + }}] + verbose "After removing empty lines \"$lines\" against \"$messages\"" 3 + if { [llength $lines] != [llength $messages] } { + verbose "message lengths different" 3 + return 0 + } + verbose "message lengths same" 3 + foreach msg $messages line $lines { + verbose "Comparing \"$msg\" against \"$line\"" 3 + if { ! [regexp $msg $line] } { + verbose "line did not compare equal" 3 + return 0 + } + } + verbose "message values same" 3 + return 1 +} + # Like check_compile, but delete the output file and return true if the # compiler printed no messages. +# Do not implement in terms of `check_known_compiler_messages_nocach` since +# that procedure includes pruning of messages. proc check_no_compiler_messages_nocache {args} { set result [eval check_compile $args] set lines [lindex $result 0] @@ -14304,3 +14347,22 @@ proc check_effective_target_alarm { } { } }] } + +# Return true if a speculation barrier is defined on the target. +proc check_effective_target_speculation_barrier_defined { } { + # N.b. not using the existing abstractions around `gcc_warning_prefix` + # since that's set depending on the tool that's getting tested while this + # effective target is used for all tools. Moreover this effective target + # is always compiling C while different tools are often testing different + # languages. Hence we always know the warning prefix that would be used + # for this test. + return [check_cached_effective_target speculation_barrier_defined { + expr ! [check_known_compiler_messages_nocache \ + [list "warning: this target does not define a speculation barrier.*"] \ + specbar assembly { + int main (int argc, char **argv) { + return __builtin_speculation_safe_value (argc); + } + }] + }] +}