From patchwork Wed Jan 8 22:07:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1220010 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-516953-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="joT7bZOW"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="ghPYQh9o"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47tNf029nDz9sPn for ; Thu, 9 Jan 2020 09:07:34 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=oGY7ehSBN0ko85HGS64jfLIT5+b+lX8xrMW0AZ9DjO72vmTM2nYYn ZNwaGPH4TxVSUUg8Y4lMQiQYXh3EhZl6a2QxHeqfepRMPwIWVMGP7EKUHGvstFDT MAWwcULJValKodcYCw1+6R81JxbAXRrnDpmcULxmOtFssJIF/V4l0g= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=default; bh=8od9TXQRdESikK625qiGwp04s4s=; b=joT7bZOWy0AJRpwN7eqhf3+cywrI B6u3/aq3bk+TEu2aCbcBqo/pJiSXQDxgMjQD/09cutb9sqIHcFkCB7aOBHJLs0ZE xdJMNtrJspaJ2nk5FeH2/69yNZjhAuQdW75ZYrqkaH4u89Vr2oPGyQR05R2DiiEd h8bb8AaePbpXrrU= Received: (qmail 82350 invoked by alias); 8 Jan 2020 22:07:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 82257 invoked by uid 89); 8 Jan 2020 22:07:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=9676 X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 08 Jan 2020 22:07:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578521242; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=llHlqImGUCXMusD9HM7oGk1kK+sEU90efiwsfeY/keE=; b=ghPYQh9ob8RT7r0qzESRGoF3oP4RA7NNEyMwSItypJxAONiJO94edGAB3V+Rdou6vLaIzk rC650r9PKWtkTCU3rN13AcA0jnRC+lhb1B8WKeR6YiTFMDxyVTOg4SBcy53+nHJceWpO/M 40t+kN1tyE/Ndd3p3WKrdz67NjnsvBQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-389-6qKmCFByPZOWjXwFMprHJw-1; Wed, 08 Jan 2020 17:07:19 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 226A9477; Wed, 8 Jan 2020 22:07:18 +0000 (UTC) Received: from t470.redhat.com (ovpn-117-41.phx2.redhat.com [10.3.117.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B035100194E; Wed, 8 Jan 2020 22:07:17 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org, Rainer Orth , Mike Stump Cc: msebor@redhat.com, law@redhat.com, David Malcolm Subject: [PATCH] testsuite: add lib/nn-line-numbers.exp Date: Wed, 8 Jan 2020 17:07:14 -0500 Message-Id: <20200108220714.15701-1-dmalcolm@redhat.com> In-Reply-To: <20200108090302.2425-6-dmalcolm@redhat.com> References: <20200108090302.2425-6-dmalcolm@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes (replying to my own "[PATCH 05/41] Add -fdiagnostics-nn-line-numbers" with a followup that does it at the DejaGnu level rather than as a test-only option) On Wed, 2020-01-08 at 04:02 -0500, David Malcolm wrote: > I may be able to self-approve this. It's used by the diagnostic_path > patch, and by the analyzer test suite. Perhaps better to make > undocumeted, or do it via a DejaGnu pruning directive, but I wanted > to get v5 of the kit posted. > > This patch implements -fdiagnostics-nn-line-numbers, a new option > which makes diagnostic_show_locus print "NN" rather than specific > line numbers when printing the left margin. > > This is intended purely to make it easier to write certain kinds of > DejaGnu test; various integration tests for diagnostic paths later > in the patch kit make use of it. > > gcc/ChangeLog: > * common.opt (fdiagnostics-nn-line-numbers): New option. > * diagnostic-show-locus.c > (layout::m_use_nn_for_line_numbers_p): > New field. > (layout::layout): Initialize it. > (layout::calculate_linenum_width): Use it when computing > m_linenum_width. > (layout::print_source_line): Implement printing "NN" rather > than > the line number. > (selftest::test_line_numbers_multiline_range): Add a test of > "NN" > printing. > * diagnostic.c (diagnostic_initialize): Initialize > use_nn_for_line_numbers_p. > (num_digits): Add "use_nn_p" param. > (selftest::test_num_digits): Add a test for use_nn_p==true. > * diagnostic.h (diagnostic_context::use_nn_for_line_numbers_p): > New field. > (num_digits): Add optional "use_nn_p" param. > * doc/invoke.texi (-fdiagnostics-nn-line-numbers): New option. > * dwarf2out.c (gen_producer_string): Ignore > OPT_fdiagnostics_nn_line_numbers. > * lto-wrapper.c (merge_and_complain): Handle > OPT_fdiagnostics_nn_line_numbers. > (append_compiler_options): Likewise. > (append_diag_options): Likewise. > * opts.c (common_handle_option): Likewise. > * toplev.c (general_init): Initialize > global_dc->use_nn_for_line_numbers_p. Here's an alterative patch to the above that replaces the "-fdiagnostics-nn-line-numbers" option in earlier versions of the analyzer patch kit, by doing it at the DejaGnu level instead. This patch adds support for obscuring the line numbers printed in the left-hand margin when printing the source code, converting them to NN, e.g from: 7111 | if (!(flags & 0x0001)) { | ^ | | | (1) following 'true' branch... 7112 | to: NN | if (!(flags & 0x0001)) { | ^ | | | (1) following 'true' branch... NN | This is useful in followup patches e.g. when testing how interprocedural paths are printed using multiline.exp, to avoid depending on precise line numbers. I'm testing this now (but it seems to be a working, drop-in replacement for the option in the parts of the patch kit I've tested with it). Examples of use can be seen in the analyzer test suite: https://gcc.gnu.org/ml/gcc-patches/2020-01/msg00320.html (search for -fdiagnostics-nn-line-numbers and dg-begin-multiline-output there to get the idea) OK for trunk assuming the other testing looks good? gcc/testsuite/ChangeLog: * lib/gcc-dg.exp (cleanup-after-saved-dg-test): Reset global nn_line_numbers_enabled. * lib/nn-line-numbers.exp: New file. * lib/prune.exp: Load nn-line-numbers.exp. (prune_gcc_output): Call maybe-handle-nn-line-numbers. --- gcc/testsuite/lib/gcc-dg.exp | 2 + gcc/testsuite/lib/nn-line-numbers.exp | 103 ++++++++++++++++++++++++++ gcc/testsuite/lib/prune.exp | 5 ++ 3 files changed, 110 insertions(+) create mode 100644 gcc/testsuite/lib/nn-line-numbers.exp diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp index e6875de23831..cccd3ce4742c 100644 --- a/gcc/testsuite/lib/gcc-dg.exp +++ b/gcc/testsuite/lib/gcc-dg.exp @@ -940,6 +940,7 @@ if { [info procs saved-dg-test] == [list] } { global set_compiler_env_var global saved_compiler_env_var global keep_saved_temps_suffixes + global nn_line_numbers_enabled global multiline_expected_outputs global freeform_regexps global save_linenr_varnames @@ -967,6 +968,7 @@ if { [info procs saved-dg-test] == [list] } { if [info exists testname_with_flags] { unset testname_with_flags } + set nn_line_numbers_enabled 0 set multiline_expected_outputs [] set freeform_regexps [] diff --git a/gcc/testsuite/lib/nn-line-numbers.exp b/gcc/testsuite/lib/nn-line-numbers.exp new file mode 100644 index 000000000000..fed1004eb8e7 --- /dev/null +++ b/gcc/testsuite/lib/nn-line-numbers.exp @@ -0,0 +1,103 @@ +# Copyright (C) 2020 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +# Support for obsuring the line numbers printed in the left-hand margin +# when printing the source code, converting them to NN, e.g from: +# +# 7111 | if (!(flags & 0x0001)) { +# | ^ +# | | +# | (1) following 'true' branch... +# 7112 | +# +# to: +# +# NN | if (!(flags & 0x0001)) { +# | ^ +# | | +# | (1) following 'true' branch... +# NN | +# +# This is useful e.g. when testing how interprocedural paths are printed +# using multiline.exp (to avoid depending on precise line numbers). + +############################################################################ +# Global variables. +############################################################################ + +# Was dg-enable-nn-line-numbers called? +set nn_line_numbers_enabled 0 + +############################################################################ +# Exported functions. +############################################################################ + +# Directive for enabling obscuring source-margin line numbers in "NN" form. + +proc dg-enable-nn-line-numbers { args } { + verbose "dg-nn-line-numbers: args: $args" 2 + global nn_line_numbers_enabled + set nn_line_numbers_enabled 1 +} + +# Hook to be called by prune.exp's prune_gcc_output to convert such line +# numbers to "NN" form. +# +# Match lines that start like: +# " 25 |" +# and convert them to: +# " NN |" +# +# It returns a copy of its input, with the above changes. + +proc maybe-handle-nn-line-numbers { text } { + global testname_with_flags + + verbose "maybe-handle-nn-line-numbers" 3 + + global nn_line_numbers_enabled + if { [expr {!$nn_line_numbers_enabled}] } { + verbose "nn_line_numbers_enabled false; bailing out" 3 + return $text + } + + verbose "maybe-handle-nn-line-numbers: text before: ${text}" 4 + + # dg.exp's dg-test trims leading whitespace from the output + # in this line: + # set comp_output [string trimleft $comp_output] + # so we can't rely on the exact leading whitespace for the + # first line in the output. + # Match initial input lines that start like: + # "25 |" + # and convert them to: + # " NN |" + set rexp2 {(^[0-9]+ \|)} + set count_a [regsub -all $rexp2 $text " NN |" text] + verbose "maybe-handle-nn-line-numbers: count_a: $count_a" 4 + + # Match lines that start like: + # " 25 |" + # and convert them to: + # " NN |" + set rexp {([ ]+[0-9]+ \|)} + set count_b [regsub -all $rexp $text " NN |" text] + verbose "maybe-handle-nn-line-numbers: count_b: $count_b" 4 + + verbose "maybe-handle-nn-line-numbers: text after: ${text}" 4 + + return $text +} diff --git a/gcc/testsuite/lib/prune.exp b/gcc/testsuite/lib/prune.exp index 6e2e84ba171c..daa8a4c6db7e 100644 --- a/gcc/testsuite/lib/prune.exp +++ b/gcc/testsuite/lib/prune.exp @@ -17,6 +17,7 @@ # Prune messages from gcc that aren't useful. load_lib multiline.exp +load_lib nn-line-numbers.exp if ![info exists TEST_ALWAYS_FLAGS] { set TEST_ALWAYS_FLAGS "" @@ -74,6 +75,10 @@ proc prune_gcc_output { text } { # Ignore harmless warnings from Xcode 4.0. regsub -all "(^|\n)\[^\n\]*ld: warning: could not create compact unwind for\[^\n\]*" $text "" text + # If dg-enable-nn-line-numbers was provided, then obscure source-margin + # line numbers by converting them to "NN" form. + set text [maybe-handle-nn-line-numbers $text] + # Call into multiline.exp to handle any multiline output directives. set text [handle-multiline-outputs $text]