From patchwork Thu Aug 22 21:05:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1975769 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=XFpuB8vh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WqbNJ4M5Qz1ybW for ; Fri, 23 Aug 2024 07:06:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 64A113871039 for ; Thu, 22 Aug 2024 21:06:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id E97AF3858430 for ; Thu, 22 Aug 2024 21:05:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E97AF3858430 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E97AF3858430 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724360760; cv=none; b=oetjmBTLuf+sgJ9T5fHPFZx8H3AH4LUKq3u1apwbMEHaAa5F12X2ezvl8U9vRmfKbMKrhRc8PeAHyKUTf2QxC8wLd7q3lNK/xSlOnobHVZ3FRKselKoKTV35STPtPmrWGArImVI8bOKx2KD+HbghfAW2U9012PbkJ1jN6hHv0Wo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724360760; c=relaxed/simple; bh=sRyVfBYrRuob9hACQTcQQXj3SeS4C38uTE/cZPNYDy4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=K5/MlOFNGt1QUHW5Laj/45/u5uD2E8tRT4gIu5h9qn2bAGbVjdQV0EizgdD65hLA0TNvOye3/srlbX35Po5u8GTUGajAVVzdg6uQ3ABVWUmjvQMBuN08plpXXHeVEzehjoG7fh1e8ReYwWTB5WlGLNiTYJo85UOr6Vyr6P/NXV8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-20223b5c1c0so11890725ad.2 for ; Thu, 22 Aug 2024 14:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724360757; x=1724965557; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=sRiY6pGU1LU90jpGe43BCjwdUUAqV+JsfOFNSGLduG0=; b=XFpuB8vhRL75jeQh4HQRQR5PGg1yQBu4yYVgZeYD5DQe1kZ3F2in+Wpaj6vK9nVqt5 lw9zu+v4vGdv+48T/9Pr7ygVum8YyXLxHbLRJgu9J+UH07EfIVVevl0sWX/Veowj4IL0 MzAZIO+7tpPy90ani5diT3AlETHG+qcGhd5fGD+p6rJrphsBZW2RqeQnGqzuccH7z7qp FosBqKEjOKi18xhMdYMpoeXhR0P+mAjwa4BvVEu1BpH8bX2/7GTSqcfqQwKEShZjX+iK 5FMnveaApnO6u6kYspYeWsoTtA3gGw2sCBcXTttah7oQykUdcNMA2VWwX1086N6zKSoy rFJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724360757; x=1724965557; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sRiY6pGU1LU90jpGe43BCjwdUUAqV+JsfOFNSGLduG0=; b=wBUJJcYP7H8Bbu+D0CDmAUdJUf/Qc4cOub+9HBDGieGsrfSGEHm6kSUKzHY/viLNKL oNWDQM4YTJ1Zd2suGlulX79oLZbJTp0HX+9vwqJLnhgD3uR5hn1yV+Y1a/MKRn0WZ5HP D6gerKZVj76+z2sx9WvwA9c0OZ/j1xh34jCGXfLbMS86/Pg/P0LiR7CX4ywoI9T8/i2x 0zfTLQOL8kq/jEucNygnvfiUKyd6Vp0A4M6tyl6HQ13J34xiG9qcIuhebe4ma5kxuJ6a YY3qYa0uwWnxc1nqQVN1GiR6hBjySBy5cypPIKWeDT/pO5+lwNENL2zBweZLzMTcXnav FLPA== X-Gm-Message-State: AOJu0Yx5mnR7RXK4BTyW1xRiPmTB9A7g4SfWnO3bTGFtYU700U2bZKDI ERy7H9gRetS4AXpEp82RfRTeK5rfWIbXiomPxZFaRWvqVLuvbkhY X-Google-Smtp-Source: AGHT+IH8XaVP+EzhqIccqA8o2ufA2GPOKGGAcoglxAVe2Gg7XYpPA+FKAq0T8Nf1zG5FtnLctHCpLg== X-Received: by 2002:a17:902:ea0d:b0:1fb:8f72:d5ea with SMTP id d9443c01a7336-2039e57036cmr204975ad.50.1724360756469; Thu, 22 Aug 2024 14:05:56 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.59.129.158]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855808a7sm16759945ad.72.2024.08.22.14.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 14:05:56 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id D4DD27400A2; Thu, 22 Aug 2024 14:05:54 -0700 (PDT) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: richard.sandiford@arm.com, hongtao.liu@intel.com Subject: [PATCH v2] Extend check-function-bodies to allow label and directives Date: Thu, 22 Aug 2024 14:05:54 -0700 Message-ID: <20240822210554.1172978-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3019.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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~incoming=patchwork.ozlabs.org@gcc.gnu.org As PR target/116174 shown, we may need to verify labels and the directive order. Extend check-function-bodies to support matched output lines to allow label and directives. gcc/ * doc/sourcebuild.texi (check-function-bodies): Add an optional argument for matched output lines. gcc/testsuite/ * gcc.target/i386/pr116174.c: Use check-function-bodies. * lib/scanasm.exp (parse_function_bodies): Append the line if $up_config(matched) matches the line. (check-function-bodies): Add an argument for matched. Set up_config(matched) to $matched. Append the expected line without $config(line_prefix) to function_regexp if it starts with ".L". Signed-off-by: H.J. Lu --- gcc/doc/sourcebuild.texi | 6 +++++- gcc/testsuite/gcc.target/i386/pr116174.c | 18 +++++++++++++++--- gcc/testsuite/lib/scanasm.exp | 14 ++++++++++++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi index 1a31f00fb65..f7128f445cf 100644 --- a/gcc/doc/sourcebuild.texi +++ b/gcc/doc/sourcebuild.texi @@ -3530,7 +3530,7 @@ assembly output. Passes if @var{symbol} is not defined as a hidden symbol in the test's assembly output. -@item check-function-bodies @var{prefix} @var{terminator} [@var{options} [@{ target/xfail @var{selector} @}]] +@item check-function-bodies @var{prefix} @var{terminator} [@var{options} [@{ target/xfail @var{selector} @} [@var{matched}]]] Looks through the source file for comments that give the expected assembly output for selected functions. Each line of expected output starts with the prefix string @var{prefix} and the expected output for a function as a whole @@ -3544,6 +3544,10 @@ command line. This can help if a source file is compiled both with and without optimization, since it is rarely useful to check the full function body for unoptimized code. +@var{matched}, if specified, is a regular expression which matches a +line of the function body. If @var{matched} isn't specified, lines +beginning with labels, directives and comments are ignored. + The first line of the expected output for a function @var{fn} has the form: @smallexample diff --git a/gcc/testsuite/gcc.target/i386/pr116174.c b/gcc/testsuite/gcc.target/i386/pr116174.c index 8877d0b51af..91ec3288786 100644 --- a/gcc/testsuite/gcc.target/i386/pr116174.c +++ b/gcc/testsuite/gcc.target/i386/pr116174.c @@ -1,6 +1,20 @@ /* { dg-do compile { target *-*-linux* } } */ -/* { dg-options "-O2 -fcf-protection=branch" } */ +/* { dg-options "-O2 -g0 -fcf-protection=branch" } */ +/* Keep labels and directives ('.p2align', '.cfi_startproc'). +/* { dg-final { check-function-bodies "**" "" "" { target "*-*-*" } {.*} } } */ +/* +**foo: +**.LFB0: +** .cfi_startproc +** ( +** endbr64 +** .p2align 5 +** | +** endbr32 +** ) +**... +*/ char * foo (char *dest, const char *src) { @@ -8,5 +22,3 @@ foo (char *dest, const char *src) /* nothing */; return --dest; } - -/* { dg-final { scan-assembler "\t\.cfi_startproc\n\tendbr(32|64)\n" } } */ diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp index 42c719c512c..9dc99836762 100644 --- a/gcc/testsuite/lib/scanasm.exp +++ b/gcc/testsuite/lib/scanasm.exp @@ -952,6 +952,8 @@ proc parse_function_bodies { config filename result } { verbose "parse_function_bodies: $function_name:\n$function_body" set up_result($function_name) $function_body set in_function 0 + } elseif { $up_config(matched) ne "" && [regexp $up_config(matched) $line] } { + append function_body $line "\n" } elseif { [regexp $up_config(fluff) $line] } { verbose "parse_function_bodies: $function_name: ignoring fluff line: $line" } else { @@ -982,7 +984,7 @@ proc check_function_body { functions name body_regexp } { # Check the implementations of functions against expected output. Used as: # -# { dg-do { check-function-bodies PREFIX TERMINATOR[ OPTION[ SELECTOR]] } } +# { dg-do { check-function-bodies PREFIX TERMINATOR[ OPTION[ SELECTOR [MATCHED]]] } } # # See sourcebuild.texi for details. @@ -990,7 +992,7 @@ proc check-function-bodies { args } { if { [llength $args] < 2 } { error "too few arguments to check-function-bodies" } - if { [llength $args] > 4 } { + if { [llength $args] > 5 } { error "too many arguments to check-function-bodies" } @@ -1029,6 +1031,11 @@ proc check-function-bodies { args } { } } + set matched "" + if { [llength $args] >= 5 } { + set matched [lindex $args 4] + } + set testcase [testname-for-summary] # The name might include a list of options; extract the file name. set filename [lindex $testcase 0] @@ -1048,6 +1055,7 @@ proc check-function-bodies { args } { # (name in \1). This may be different from '$config(start)'. set start_expected {^(\S+):$} + set config(matched) $matched configure_check-function-bodies config set have_bodies 0 if { [is_remote host] } { @@ -1090,6 +1098,8 @@ proc check-function-bodies { args } { append function_regexp ")" } elseif { [string equal $line "..."] } { append function_regexp ".*" + } elseif { [regexp "^.L.*" $line] } { + append function_regexp $line "\n" } else { append function_regexp $config(line_prefix) $line "\n" }