From patchwork Tue Apr 25 15:21:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 754864 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3wC6Pb4kYjz9s8G for ; Wed, 26 Apr 2017 01:21:38 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="LT/EDfCO"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=gkgLl8YsYVTAVotrG /Ipbt+Wj4vmLSPuXCKl0t45C4QkELy9+o54MgnxHC+WbhGec6+uQq9SHtVwix/K9 XnG9HKd7Cc2BoY0IH5avsoPqEbZ4N/0tuZXsyH9FOICvVQ1nRxsy1zpTcd5WmzF7 DLq7112m+G+4Hte3qTPzteN5ng= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=urnb1FXHdZ8ysNBY4/xGyUm OQKw=; b=LT/EDfCOZ0ufpNtv6mKRmOptqzi4fPdykysx0UWCUlh7Y1M8oj4G+yr o50RMjdmhz1NlG6GOt8cJYdvo8DKpbaH0H+e1xMNEBP3R8EsEYG6JVNELeVxiGtC GyhSfrLE6cjt+MQ69PY4D1C4Y06L24CtQCGzXhO/hg6X3RnmoGLA= Received: (qmail 51837 invoked by alias); 25 Apr 2017 15:21:27 -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 51819 invoked by uid 89); 25 Apr 2017 15:21:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=9796, exc X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Apr 2017 15:21:23 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-MBX-04.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1d32HI-00041M-Oy from Tom_deVries@mentor.com ; Tue, 25 Apr 2017 08:21:21 -0700 Received: from [127.0.0.1] (137.202.0.87) by SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Tue, 25 Apr 2017 16:21:14 +0100 Subject: Re: [RFC, testsuite] Add dg-save-linenr To: David Malcolm , Mike Stump , Rainer Orth References: <1493047222.9106.82.camel@redhat.com> CC: GCC Patches , Jakub Jelinek , Jeff Law From: Tom de Vries Message-ID: <464d854a-3387-ca8f-86bb-54cfc9da8767@mentor.com> Date: Tue, 25 Apr 2017 17:21:10 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <1493047222.9106.82.camel@redhat.com> X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) On 04/24/2017 05:20 PM, David Malcolm wrote: > On Sat, 2017-04-22 at 19:49 +0200, Tom de Vries wrote: >> Hi, >> >> there are currently two types of line number supported in >> dg-{error,warning,message,bogus} directives: absolute and relative. >> With an absolute line number, it's immediately clear what line number >> is >> meant, but when a line is added at the start of the file, the line >> number needs to be updated. With a relative line number, that >> problem >> is solved, but when relative line numbers become large, it becomes >> less >> clear what line it refers to, and when adding a line inbetween the >> directive using the relative line number and the line it refers to, >> the >> relative line number still needs to be updated. >> >> This patch adds a directive dg-save-linenr with argument varname, >> that >> saves the line number of the directive in a variable varname, which >> can >> be used as line number in dg directives. >> >> Testing status: >> - tested updated test-case objc.dg/try-catch-12.m >> - ran tree-ssa.exp >> >> RFC: >> - good idea? > > Excellent idea; thanks! There are various places where I'd find this > useful. > >> - naming of directive dg-save-linenr (dg-linenr, dg-save-line-nr, >> dg-save-lineno, dg-save-line-number, etc) > > How about just "dg-line"? (if it's not already taken) Done. > or "dg-name-line" / "dg-named-line" ? > in that the directive is effectively giving the line a name, giving: > > [...] > > extern void some_func (int *); /* { dg-line some_func_decl } */ > > [...] > > /* { dg-message "but argument is of type" "" { target *-*-* } > some_func_decl } */ > > > >> - allowed variable names (currently: start with letter, followed by >> alphanumerical or underscore) > > Seems reasonable; lack of leading digit allows it to be distinguished > from absolute and relative numbers. > >> - should we use a prefix symbol or some such when the variable is >> used >> (and possibly defined as well)? F.i.: >> /* { dg-save-linenr %some_func_decl } *./ >> /* { dg-message "but argument is of type" "" { target *-*-* } >> %some_func_decl } */ > > These are sometimes called "sigils". > > I'd prefer not. > >> - error message formulation > > Nit: the new function should have a leading comment, explaining the > usage. > Done. I've also: - added a set-but-not-used warning, - fixed a few bugs that surfaced during full-scale testing, and - added more comments. Reg-tested on x86_64 with ---target_board='unix/ unix/-m32'. OK for trunk? Thanks, - Tom Add dg-line Context: there are currently two types of line number supported in dg-{error,warning,message,bogus} directives: absolute and relative. With an absolute line number, it's immediately clear what line number is meant, but when a line is added at the start of the file, the line number needs to be updated. With a relative line number, that problem is solved, but when relative line numbers become large, it becomes less clear what line it refers to, and when adding a line inbetween the directive using the relative line number and the line it refers to, the relative line number still needs to be updated. Add a directive dg-line with argument varname, that saves the line number of the directive in a variable varname, which can be used as line number in dg directives. 2017-04-22 Tom de Vries * lib/gcc-dg.exp (cleanup-after-saved-dg-test): Cleanup line number variables. (dg-line): New proc. (process-message): Handle line number variables. * objc.dg/try-catch-12.m: Use dg-line. --- gcc/testsuite/lib/gcc-dg.exp | 82 +++++++++++++++++++++++++++++++++--- gcc/testsuite/objc.dg/try-catch-12.m | 8 ++-- 2 files changed, 81 insertions(+), 9 deletions(-) diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp index 83c38cf..f4b288a 100644 --- a/gcc/testsuite/lib/gcc-dg.exp +++ b/gcc/testsuite/lib/gcc-dg.exp @@ -902,6 +902,7 @@ if { [info procs saved-dg-test] == [list] } { global keep_saved_temps_suffixes global multiline_expected_outputs global freeform_regexps + global save_linenr_varnames set additional_files "" set additional_sources "" @@ -928,6 +929,27 @@ if { [info procs saved-dg-test] == [list] } { } set multiline_expected_outputs [] set freeform_regexps [] + + if { [info exists save_linenr_varnames] } { + foreach varname $save_linenr_varnames { + # Cleanup varname + eval global $varname + eval unset $varname + + # Cleanup varname_used, or generate defined-but-not-used + # warning. + set varname_used used_$varname + eval global $varname_used + eval set used [info exists $varname_used] + if { $used } { + eval unset $varname_used + } else { + regsub {^saved_linenr_} $varname "" org_varname + warning "dg-line var $org_varname defined, but not used" + } + } + unset save_linenr_varnames + } } proc dg-test { args } { @@ -979,6 +1001,32 @@ if { [info procs saved-dg-error] == [list] \ } } +# Set variable VARNAME to LINENR + +proc dg-line { linenr varname } { + set org_varname $varname + set varname "saved_linenr_$varname" + eval global $varname + + # Generate defined-but-previously-defined error. + eval set var_defined [info exists $varname] + if { $var_defined } { + eval set deflinenr \$$varname + error "dg-line var $org_varname defined at line $linenr, but previously defined at line $deflinenr" + return + } + + eval set $varname $linenr + + # Schedule cleanup of varname by cleanup-after-saved-dg-test + global save_linenr_varnames + if { [info exists save_linenr_varnames] } { + lappend save_linenr_varnames $varname + } else { + set save_linenr_varnames [list $varname] + } +} + # Modify the regular expression saved by a DejaGnu message directive to # include a prefix and to force the expression to match a single line. # MSGPROC is the procedure to call. @@ -988,11 +1036,35 @@ if { [info procs saved-dg-error] == [list] \ proc process-message { msgproc msgprefix dgargs } { upvar dg-messages dg-messages - # Handle relative line specification, .+1 or .-1 etc. - if { [llength $dgargs] == 5 - && [regsub "^\.\[+-\](\[0-9\]+)$" [lindex $dgargs 4] "\\1" num] } { - set num [expr [lindex $dgargs 0] [string index [lindex $dgargs 4] 1] $num] - set dgargs [lreplace $dgargs 4 4 $num] + if { [llength $dgargs] == 5 } { + if { [regsub "^\.\[+-\](\[0-9\]+)$" [lindex $dgargs 4] "\\1" num] } { + # Handle relative line specification, .+1 or .-1 etc. + set num [expr [lindex $dgargs 0] [string index [lindex $dgargs 4] 1] $num] + set dgargs [lreplace $dgargs 4 4 $num] + } elseif { [regsub "^(\[a-zA-Z\]\[a-zA-Z0-9_\]*)$" [lindex $dgargs 4] "\\1" varname] } { + # Handle linenr variable defined by dg-line + + set org_varname $varname + set varname "saved_linenr_$varname" + eval global $varname + + # Generate used-but-not-defined error. + eval set var_defined [info exists $varname] + if { ! $var_defined } { + set linenr [expr [lindex $dgargs 0]] + error "dg-line var $org_varname used at line $linenr, but not defined" + return + } + + # Note that varname has been used. + set varname_used "used_$varname" + eval global $varname_used + eval set $varname_used 1 + + # Get line number from var and use it. + eval set num \$$varname + set dgargs [lreplace $dgargs 4 4 $num] + } } # Process the dg- directive, including adding the regular expression diff --git a/gcc/testsuite/objc.dg/try-catch-12.m b/gcc/testsuite/objc.dg/try-catch-12.m index 61e2703..ce26b32 100644 --- a/gcc/testsuite/objc.dg/try-catch-12.m +++ b/gcc/testsuite/objc.dg/try-catch-12.m @@ -9,7 +9,7 @@ - (void) testSpoon; @end -extern void some_func (int *); +extern void some_func (int *); /* { dg-line some_func_decl } */ @implementation TestMyTests - (void) testSpoon { @@ -21,7 +21,7 @@ extern void some_func (int *); typeof(i) j = 6; typeof(q) k = 66; some_func (&j); /* { dg-warning "discards .volatile. qualifier from pointer target type" } */ - /* { dg-message "but argument is of type" "" { target *-*-* } 12 } */ + /* { dg-message "but argument is of type" "" { target *-*-* } some_func_decl } */ some_func (&k); } @catch (id exc) { @@ -37,7 +37,7 @@ extern void some_func (int *); some_func (&j); /* { dg-warning "discards .volatile. qualifier from pointer target type" } */ /* The following is disabled as it is already checked above and the testsuites seems to count multiple different identical errors on the same line only once */ - /* dg-message "but argument is of type" "" { target *-*-* } 12 */ + /* dg-message "but argument is of type" "" { target *-*-* } some_func_decl */ } @catch (id exc) { @throw; @@ -51,7 +51,7 @@ extern void some_func (int *); some_func (&j); /* { dg-warning "discards .volatile. qualifier from pointer target type" } */ /* The following is disabled as it is already checked above and the testsuites seems to count multiple different identical errors on the same line only once */ - /* dg-message "but argument is of type" "" { target *-*-* } 12 */ + /* dg-message "but argument is of type" "" { target *-*-* } some_func_decl */ some_func (&k); } @catch (id exc) {