* [RFC, testsuite] Add dg-save-linenr @ 2017-04-22 20:47 Tom de Vries 2017-04-22 21:58 ` Mike Stump ` (2 more replies) 0 siblings, 3 replies; 15+ messages in thread From: Tom de Vries @ 2017-04-22 20:47 UTC (permalink / raw) To: Mike Stump, Rainer Orth; +Cc: GCC Patches, Jakub Jelinek [-- Attachment #1: Type: text/plain, Size: 1406 bytes --] 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? - naming of directive dg-save-linenr (dg-linenr, dg-save-line-nr, dg-save-lineno, dg-save-line-number, etc) - allowed variable names (currently: start with letter, followed by alphanumerical or underscore) - 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 } */ - error message formulation Thanks, - Tom [-- Attachment #2: 0001-Add-dg-save-linenr.patch --] [-- Type: text/x-patch, Size: 5284 bytes --] Add dg-save-linenr 2017-04-22 Tom de Vries <tom@codesourcery.com> * lib/gcc-dg.exp (cleanup-after-saved-dg-test): Cleanup line number variables. (dg-save-linenr): New proc. (process-message): Handle line number variables. * objc.dg/try-catch-12.m: Use dg-save-linenr. --- gcc/testsuite/lib/gcc-dg.exp | 50 ++++++++++++++++++++++++++++++++---- gcc/testsuite/objc.dg/try-catch-12.m | 8 +++--- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp index 83c38cf..555e083 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,13 @@ 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 { + eval unset $varname + } + unset save_linenr_varnames + } } proc dg-test { args } { @@ -979,6 +987,24 @@ if { [info procs saved-dg-error] == [list] \ } } +proc dg-save-linenr { linenr varname } { + set org_varname $varname + set varname "saved_linenr_$varname" + eval global $varname + eval set var_defined [info exists $varname] + if { $var_defined } { + eval set deflinenr \$$varname + error "dg-save-linenr var $org_varname defined at line $linenr, but previously defined at line $deflinenr" + return + } + eval set $varname $linenr + 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 +1014,25 @@ 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-save-linenr + set org_varname $varname + set varname "saved_linenr_$varname" + eval global $varname + eval set var_defined [info exists $varname] + if { ! $var_defined } { + set linenr [expr [lindex $dgargs 0]] + error "dg-save-linenr var $org_varname used at line $linenr, but not defined" + return + } + 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..558ad02 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-save-linenr 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) { ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC, testsuite] Add dg-save-linenr 2017-04-22 20:47 [RFC, testsuite] Add dg-save-linenr Tom de Vries @ 2017-04-22 21:58 ` Mike Stump 2017-04-24 15:29 ` David Malcolm 2017-04-25 15:03 ` Jeff Law 2 siblings, 0 replies; 15+ messages in thread From: Mike Stump @ 2017-04-22 21:58 UTC (permalink / raw) To: Tom de Vries; +Cc: Rainer Orth, GCC Patches, Jakub Jelinek On Apr 22, 2017, at 10:49 AM, Tom de Vries <Tom_deVries@mentor.com> wrote: > > 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. > RFC: > - good idea? Seems reasonable to me. I'd like to encourage, like it, hate it comments from others and see what others think. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC, testsuite] Add dg-save-linenr 2017-04-22 20:47 [RFC, testsuite] Add dg-save-linenr Tom de Vries 2017-04-22 21:58 ` Mike Stump @ 2017-04-24 15:29 ` David Malcolm 2017-04-24 20:46 ` David Malcolm 2017-04-25 15:24 ` Tom de Vries 2017-04-25 15:03 ` Jeff Law 2 siblings, 2 replies; 15+ messages in thread From: David Malcolm @ 2017-04-24 15:29 UTC (permalink / raw) To: Tom de Vries, Mike Stump, Rainer Orth; +Cc: GCC Patches, Jakub Jelinek 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) 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. Thanks again Dave ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC, testsuite] Add dg-save-linenr 2017-04-24 15:29 ` David Malcolm @ 2017-04-24 20:46 ` David Malcolm 2017-04-25 15:24 ` Tom de Vries 1 sibling, 0 replies; 15+ messages in thread From: David Malcolm @ 2017-04-24 20:46 UTC (permalink / raw) To: Tom de Vries, Mike Stump, Rainer Orth; +Cc: GCC Patches, Jakub Jelinek On Mon, 2017-04-24 at 11:20 -0400, 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 e.g. the test cases within https://gcc.gnu.org/ml/gcc-patches/2017-04/msg01061.html ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC, testsuite] Add dg-save-linenr 2017-04-24 15:29 ` David Malcolm 2017-04-24 20:46 ` David Malcolm @ 2017-04-25 15:24 ` Tom de Vries 2017-04-25 15:35 ` Mike Stump 2017-05-16 13:14 ` Rainer Orth 1 sibling, 2 replies; 15+ messages in thread From: Tom de Vries @ 2017-04-25 15:24 UTC (permalink / raw) To: David Malcolm, Mike Stump, Rainer Orth Cc: GCC Patches, Jakub Jelinek, Jeff Law [-- Attachment #1: Type: text/plain, Size: 2540 bytes --] 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 [-- Attachment #2: 0001-Add-dg-line.patch --] [-- Type: text/x-patch, Size: 6851 bytes --] 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 <tom@codesourcery.com> * 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) { ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC, testsuite] Add dg-save-linenr 2017-04-25 15:24 ` Tom de Vries @ 2017-04-25 15:35 ` Mike Stump 2017-05-16 13:14 ` Rainer Orth 1 sibling, 0 replies; 15+ messages in thread From: Mike Stump @ 2017-04-25 15:35 UTC (permalink / raw) To: Tom de Vries Cc: David Malcolm, Rainer Orth, GCC Patches, Jakub Jelinek, Jeff Law On Apr 25, 2017, at 8:21 AM, Tom de Vries <Tom_deVries@mentor.com> wrote: > > OK for trunk? Ok. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC, testsuite] Add dg-save-linenr 2017-04-25 15:24 ` Tom de Vries 2017-04-25 15:35 ` Mike Stump @ 2017-05-16 13:14 ` Rainer Orth 2017-05-22 17:10 ` Tom de Vries 1 sibling, 1 reply; 15+ messages in thread From: Rainer Orth @ 2017-05-16 13:14 UTC (permalink / raw) To: Tom de Vries Cc: David Malcolm, Mike Stump, GCC Patches, Jakub Jelinek, Jeff Law Hi Tom, sorry for chiming in so very late: I've been on vacation and sick in between... > 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. I'd have preferred dg-linenum: it clarifiers that it's a number and we have precedent in DejaGnu's dg-linenum-format and dg-format-linenum... >>> - error message formulation >> >> Nit: the new function should have a leading comment, explaining the >> usage. >> > > Done. Not only that, but the new proc needs documenting in sourcebuild.texi. (It's already way too hard for testsuite writers to find their way with the documentation; if parts are missing, it gets next to impossible.) Besides, it may be worthwhile contributing/suggesting this upstream. Thanks. Rainer -- ----------------------------------------------------------------------------- Rainer Orth, Center for Biotechnology, Bielefeld University ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC, testsuite] Add dg-save-linenr 2017-05-16 13:14 ` Rainer Orth @ 2017-05-22 17:10 ` Tom de Vries 2017-05-23 13:40 ` Tom de Vries ` (2 more replies) 0 siblings, 3 replies; 15+ messages in thread From: Tom de Vries @ 2017-05-22 17:10 UTC (permalink / raw) To: Rainer Orth Cc: David Malcolm, Mike Stump, GCC Patches, Jakub Jelinek, Jeff Law [-- Attachment #1: Type: text/plain, Size: 3128 bytes --] On 05/16/2017 03:12 PM, Rainer Orth wrote: > Hi Tom, > > sorry for chiming in so very late: I've been on vacation and sick in > between... > thanks for review anyway. >> 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. > > I'd have preferred dg-linenum: it clarifiers that it's a number and we > have precedent in DejaGnu's dg-linenum-format and dg-format-linenum... > I see. I'll leave it dg-line for now, but I'll mention the dg-linenum variant upstream. >>>> - error message formulation >>> >>> Nit: the new function should have a leading comment, explaining the >>> usage. >>> >> >> Done. > > Not only that, but the new proc needs documenting in sourcebuild.texi. Attached patch adds the missing documentation. It looks like this in gccint.info: ... '{ dg-line LINENUMVAR }' This DejaGnu directive sets the variable LINENUMVAR to the line number of the source line. The variable LINENUMVAR can then be used in subsequent 'dg-error', 'dg-warning', 'dg-message' and 'dg-bogus' directives. For example: int a; /* { dg-line first_def_a } */ float a; /* { dg-error "conflicting types of" } */ /* { dg-message "previous declaration of" "" { target *-*-* } first_def_a } */ ... Note: AFAIK, dg-line does not work in the gnat testsuite. This is similar to PR80219 for relative line numbers. I'm not sure if we should mention this here, or how. OK for trunk like this? > (It's already way too hard for testsuite writers to find their way with > the documentation; if parts are missing, it gets next to impossible.) > Ack. I think the relative line numbers are also not documented. > Besides, it may be worthwhile contributing/suggesting this upstream. Will do. Thanks, - Tom [-- Attachment #2: 0001-Document-dg-line-directive.patch --] [-- Type: text/x-patch, Size: 1287 bytes --] Document dg-line directive 2017-05-22 Tom de Vries <tom@codesourcery.com> * doc/sourcebuild.texi: Document dg-line directive. --- gcc/doc/sourcebuild.texi | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi index 84d9a22..a887337 100644 --- a/gcc/doc/sourcebuild.texi +++ b/gcc/doc/sourcebuild.texi @@ -1180,6 +1180,18 @@ associated with the bogus message. It is usually used with @samp{xfail} to indicate that the message is a known problem for a particular set of targets. +@item @{ dg-line @var{linenumvar} @} +This DejaGnu directive sets the variable @var{linenumvar} to the line number of +the source line. The variable @var{linenumvar} can then be used in subsequent +@code{dg-error}, @code{dg-warning}, @code{dg-message} and @code{dg-bogus} +directives. For example: + +@smallexample +int a; /* @{ dg-line first_def_a @} */ +float a; /* @{ dg-error "conflicting types of" @} */ +/* @{ dg-message "previous declaration of" "" @{ target *-*-* @} first_def_a @} */ +@end smallexample + @item @{ dg-excess-errors @var{comment} [@{ target/xfail @var{selector} @}] @} This DejaGnu directive indicates that the test is expected to fail due to compiler messages that are not handled by @samp{dg-error}, ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC, testsuite] Add dg-save-linenr 2017-05-22 17:10 ` Tom de Vries @ 2017-05-23 13:40 ` Tom de Vries 2017-05-23 15:24 ` Mike Stump 2020-10-30 11:34 ` Thomas Schwinge 2 siblings, 0 replies; 15+ messages in thread From: Tom de Vries @ 2017-05-23 13:40 UTC (permalink / raw) To: Rainer Orth Cc: David Malcolm, Mike Stump, GCC Patches, Jakub Jelinek, Jeff Law On 05/22/2017 06:55 PM, Tom de Vries wrote: >> Besides, it may be worthwhile contributing/suggesting this upstream. > > Will do. Sent 'relative line numbers and dg-line directive' to dejagnu ml ( http://lists.gnu.org/archive/html/dejagnu/2017-05/msg00000.html ). Thanks, - Tom ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC, testsuite] Add dg-save-linenr 2017-05-22 17:10 ` Tom de Vries 2017-05-23 13:40 ` Tom de Vries @ 2017-05-23 15:24 ` Mike Stump 2020-10-30 11:34 ` Thomas Schwinge 2 siblings, 0 replies; 15+ messages in thread From: Mike Stump @ 2017-05-23 15:24 UTC (permalink / raw) To: Tom de Vries Cc: Rainer Orth, David Malcolm, GCC Patches, Jakub Jelinek, Jeff Law On May 22, 2017, at 9:55 AM, Tom de Vries <Tom_deVries@mentor.com> wrote: > > Attached patch adds the missing documentation. > > It looks like this in gccint.info: > ... > '{ dg-line LINENUMVAR }' > This DejaGnu directive sets the variable LINENUMVAR to the line > number of the source line. The variable LINENUMVAR can then be > used in subsequent 'dg-error', 'dg-warning', 'dg-message' and > 'dg-bogus' directives. For example: > > int a; /* { dg-line first_def_a } */ > float a; /* { dg-error "conflicting types of" } */ > /* { dg-message "previous declaration of" "" { target *-*-* } first_def_a } */ > ... > > Note: AFAIK, dg-line does not work in the gnat testsuite. This is similar to PR80219 for relative line numbers. I'm not sure if we should mention this here, or how. > > OK for trunk like this? Ok. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC, testsuite] Add dg-save-linenr 2017-05-22 17:10 ` Tom de Vries 2017-05-23 13:40 ` Tom de Vries 2017-05-23 15:24 ` Mike Stump @ 2020-10-30 11:34 ` Thomas Schwinge 2020-10-30 11:40 ` Jakub Jelinek 2020-11-17 21:47 ` Jeff Law 2 siblings, 2 replies; 15+ messages in thread From: Thomas Schwinge @ 2020-10-30 11:34 UTC (permalink / raw) To: Rainer Orth, Mike Stump, gcc-patches Cc: Tom de Vries, David Malcolm, Jakub Jelinek, Jeff Law [-- Attachment #1: Type: text/plain, Size: 2342 bytes --] Hi! On 2017-05-22T18:55:29+0200, Tom de Vries <Tom_deVries@mentor.com> wrote: > On 05/16/2017 03:12 PM, Rainer Orth wrote: >> [...], but the new proc ['dg-line'] needs documenting in sourcebuild.texi. > > Attached patch adds the missing documentation. OK to expand that with the attached patch to "Document that 'linenumvar' in 'dg-line' may contain Tcl syntax"? (Hooray for embedded Tcl! -- Don't hurt me; I (later) have a use case where this does make things easier.) '{ dg-line LINENUMVAR }' This DejaGnu directive sets the variable LINENUMVAR to the line number of the source line. The variable LINENUMVAR, which must be unique per testcase, may then be used in subsequent 'dg-error', 'dg-warning', 'dg-message' and 'dg-bogus' directives. For example: int a; /* { dg-line first_def_a } */ float a; /* { dg-error "conflicting types of" } */ /* { dg-message "previous declaration of" "" { target *-*-* } first_def_a } */ Note that LINENUMVAR may contain Tcl syntax, for example: #pragma acc parallel loop [...] /* { dg-line line[incr line_count] } */ /* { dg-message "note: [...]" "" { target *-*-* } line$line_count } */ /* { dg-message "optimized: [...]" "" { target *-*-* } line$line_count } */ for (int j = 0; j < nj; ++j) { #pragma acc loop [...] /* { dg-line line[incr line_count] } */ /* { dg-message "missed: [...]" "" { target *-*-* } line$line_count } */ /* { dg-message "optimized: [...]" "" { target *-*-* } line$line_count } */ /* { dg-message "note: [...]" "" { target *-*-* } line$line_count } */ for (int i = 0; i < ni; ++i) For each 'dg-line', this increments a counter variable 'line_count' to construct unique 'line$line_count' names for LINENUMVAR: 'line1', 'line2', .... The preceding 'dg-line' may then be referred to via 'line$line_count'. Grüße Thomas ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Document-that-linenumvar-in-dg-line-may-contain-Tcl-.patch --] [-- Type: text/x-diff, Size: 2485 bytes --] From 2211acd9a902a5cab874762166dbca116a98bea5 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge <thomas@codesourcery.com> Date: Thu, 29 Oct 2020 07:04:54 +0100 Subject: [PATCH] Document that 'linenumvar' in 'dg-line' may contain Tcl syntax gcc/ * doc/sourcebuild.texi (dg-line): Document that 'linenumvar' may contain Tcl syntax. --- gcc/doc/sourcebuild.texi | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi index 49316a5d0ff9..92e9f4353d3f 100644 --- a/gcc/doc/sourcebuild.texi +++ b/gcc/doc/sourcebuild.texi @@ -1226,7 +1226,9 @@ targets. @item @{ dg-line @var{linenumvar} @} This DejaGnu directive sets the variable @var{linenumvar} to the line number of -the source line. The variable @var{linenumvar} can then be used in subsequent +the source line. +The variable @var{linenumvar}, which must be unique per testcase, may +then be used in subsequent @code{dg-error}, @code{dg-warning}, @code{dg-message} and @code{dg-bogus} directives. For example: @@ -1236,6 +1238,27 @@ float a; /* @{ dg-error "conflicting types of" @} */ /* @{ dg-message "previous declaration of" "" @{ target *-*-* @} first_def_a @} */ @end smallexample +Note that @var{linenumvar} may contain Tcl syntax, for example: + +@smallexample +#pragma acc parallel loop [...] /* @{ dg-line line[incr line_count] @} */ + /* @{ dg-message "note: [...]" "" @{ target *-*-* @} line$line_count @} */ + /* @{ dg-message "optimized: [...]" "" @{ target *-*-* @} line$line_count @} */ + for (int j = 0; j < nj; ++j) + @{ + #pragma acc loop [...] /* @{ dg-line line[incr line_count] @} */ + /* @{ dg-message "missed: [...]" "" @{ target *-*-* @} line$line_count @} */ + /* @{ dg-message "optimized: [...]" "" @{ target *-*-* @} line$line_count @} */ + /* @{ dg-message "note: [...]" "" @{ target *-*-* @} line$line_count @} */ + for (int i = 0; i < ni; ++i) +@end smallexample + +For each @code{dg-line}, this increments a counter variable +@code{line_count} to construct unique @code{line$line_count} names for +@var{linenumvar}: @code{line1}, @code{line2}, @dots{}. +The preceding @code{dg-line} may then be referred to via +@code{line$line_count}. + @item @{ dg-excess-errors @var{comment} [@{ target/xfail @var{selector} @}] @} This DejaGnu directive indicates that the test is expected to fail due to compiler messages that are not handled by @samp{dg-error}, -- 2.17.1 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC, testsuite] Add dg-save-linenr 2020-10-30 11:34 ` Thomas Schwinge @ 2020-10-30 11:40 ` Jakub Jelinek 2020-10-30 13:40 ` Thomas Schwinge 2020-11-17 21:47 ` Jeff Law 1 sibling, 1 reply; 15+ messages in thread From: Jakub Jelinek @ 2020-10-30 11:40 UTC (permalink / raw) To: Thomas Schwinge Cc: Rainer Orth, Mike Stump, gcc-patches, Tom de Vries, David Malcolm, Jeff Law On Fri, Oct 30, 2020 at 12:34:57PM +0100, Thomas Schwinge wrote: > Hi! > > On 2017-05-22T18:55:29+0200, Tom de Vries <Tom_deVries@mentor.com> wrote: > > On 05/16/2017 03:12 PM, Rainer Orth wrote: > >> [...], but the new proc ['dg-line'] needs documenting in sourcebuild.texi. > > > > Attached patch adds the missing documentation. > > OK to expand that with the attached patch to "Document that 'linenumvar' > in 'dg-line' may contain Tcl syntax"? (Hooray for embedded Tcl! -- > Don't hurt me; I (later) have a use case where this does make things > easier.) Is it desirable though? I mean if we ever decide to switch from dejagnu to something else, adding parsing of our dg-* grammar is not that hard, and while we rely on some tcl details already (e.g. the {}s vs. ""s for regular expressions etc.), allowing arbitrary embedded tcl will make that effort even harder. Jakub ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC, testsuite] Add dg-save-linenr 2020-10-30 11:40 ` Jakub Jelinek @ 2020-10-30 13:40 ` Thomas Schwinge 0 siblings, 0 replies; 15+ messages in thread From: Thomas Schwinge @ 2020-10-30 13:40 UTC (permalink / raw) To: Jakub Jelinek Cc: Rainer Orth, Mike Stump, gcc-patches, Tom de Vries, David Malcolm, Jeff Law Hi Jakub! On 2020-10-30T12:40:02+0100, Jakub Jelinek <jakub@redhat.com> wrote: > On Fri, Oct 30, 2020 at 12:34:57PM +0100, Thomas Schwinge wrote: >> On 2017-05-22T18:55:29+0200, Tom de Vries <Tom_deVries@mentor.com> wrote: >> > On 05/16/2017 03:12 PM, Rainer Orth wrote: >> >> [...], but the new proc ['dg-line'] needs documenting in sourcebuild.texi. >> > >> > Attached patch adds the missing documentation. >> >> OK to expand that with the attached patch to "Document that 'linenumvar' >> in 'dg-line' may contain Tcl syntax"? (Hooray for embedded Tcl! -- >> Don't hurt me; I (later) have a use case where this does make things >> easier.) > > Is it desirable though? I hear you. > I mean if we ever decide to switch from dejagnu to something else, > adding parsing of our dg-* grammar is not that hard, and while we rely > on some tcl details already (e.g. the {}s vs. ""s for regular expressions > etc.), allowing arbitrary embedded tcl will make that effort even harder. (It's not much, but note that there already are some more "arbitrary" Tcl-y idioms in the testsuite.) I had considered the point you're making, but it's already many years (decades?) that we (meaning: some?) would like to switch away from DejaGnu (to what else -- QMTest apparently isn't it?) -- so, this isn't going to happen next week. If we then ever port to something else, I'm sure the new system will be likewise expressive/extensible. Thus I decided to use the convenience now, and defer the potential (minor, compared to the overall effort) complication until then. Grüße Thomas ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC, testsuite] Add dg-save-linenr 2020-10-30 11:34 ` Thomas Schwinge 2020-10-30 11:40 ` Jakub Jelinek @ 2020-11-17 21:47 ` Jeff Law 1 sibling, 0 replies; 15+ messages in thread From: Jeff Law @ 2020-11-17 21:47 UTC (permalink / raw) To: Thomas Schwinge, Rainer Orth, Mike Stump, gcc-patches Cc: Tom de Vries, David Malcolm, Jakub Jelinek On 10/30/20 5:34 AM, Thomas Schwinge wrote: > Hi! > > On 2017-05-22T18:55:29+0200, Tom de Vries <Tom_deVries@mentor.com> wrote: >> On 05/16/2017 03:12 PM, Rainer Orth wrote: >>> [...], but the new proc ['dg-line'] needs documenting in sourcebuild.texi. >> Attached patch adds the missing documentation. > OK to expand that with the attached patch to "Document that 'linenumvar' > in 'dg-line' may contain Tcl syntax"? (Hooray for embedded Tcl! -- > Don't hurt me; I (later) have a use case where this does make things > easier.) > > '{ dg-line LINENUMVAR }' > This DejaGnu directive sets the variable LINENUMVAR to the line > number of the source line. The variable LINENUMVAR, which must be > unique per testcase, may then be used in subsequent 'dg-error', > 'dg-warning', 'dg-message' and 'dg-bogus' directives. For example: > > int a; /* { dg-line first_def_a } */ > float a; /* { dg-error "conflicting types of" } */ > /* { dg-message "previous declaration of" "" { target *-*-* } first_def_a } */ > > Note that LINENUMVAR may contain Tcl syntax, for example: > > #pragma acc parallel loop [...] /* { dg-line line[incr line_count] } */ > /* { dg-message "note: [...]" "" { target *-*-* } line$line_count } */ > /* { dg-message "optimized: [...]" "" { target *-*-* } line$line_count } */ > for (int j = 0; j < nj; ++j) > { > #pragma acc loop [...] /* { dg-line line[incr line_count] } */ > /* { dg-message "missed: [...]" "" { target *-*-* } line$line_count } */ > /* { dg-message "optimized: [...]" "" { target *-*-* } line$line_count } */ > /* { dg-message "note: [...]" "" { target *-*-* } line$line_count } */ > for (int i = 0; i < ni; ++i) > > For each 'dg-line', this increments a counter variable 'line_count' > to construct unique 'line$line_count' names for LINENUMVAR: > 'line1', 'line2', .... The preceding 'dg-line' may then be > referred to via 'line$line_count'. > > > Grüße > Thomas > > > ----------------- > Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany > Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter > > 0001-Document-that-linenumvar-in-dg-line-may-contain-Tcl-.patch > > From 2211acd9a902a5cab874762166dbca116a98bea5 Mon Sep 17 00:00:00 2001 > From: Thomas Schwinge <thomas@codesourcery.com> > Date: Thu, 29 Oct 2020 07:04:54 +0100 > Subject: [PATCH] Document that 'linenumvar' in 'dg-line' may contain Tcl > syntax > > gcc/ > * doc/sourcebuild.texi (dg-line): Document that 'linenumvar' may > contain Tcl syntax. OK jeff ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFC, testsuite] Add dg-save-linenr 2017-04-22 20:47 [RFC, testsuite] Add dg-save-linenr Tom de Vries 2017-04-22 21:58 ` Mike Stump 2017-04-24 15:29 ` David Malcolm @ 2017-04-25 15:03 ` Jeff Law 2 siblings, 0 replies; 15+ messages in thread From: Jeff Law @ 2017-04-25 15:03 UTC (permalink / raw) To: Tom de Vries, Mike Stump, Rainer Orth; +Cc: GCC Patches, Jakub Jelinek On 04/22/2017 11:49 AM, 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? Yes. > - naming of directive dg-save-linenr (dg-linenr, dg-save-line-nr, > dg-save-lineno, dg-save-line-number, etc) No strong opinions. We often use "save" in various ways within the GCC source for similar concepts, so any of those work for me. > - allowed variable names (currently: start with letter, followed by > alphanumerical or underscore) Seems reasonable. > - 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 } */ I'm not sure what the value here would be. Jeff ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2020-11-17 21:47 UTC | newest] Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-04-22 20:47 [RFC, testsuite] Add dg-save-linenr Tom de Vries 2017-04-22 21:58 ` Mike Stump 2017-04-24 15:29 ` David Malcolm 2017-04-24 20:46 ` David Malcolm 2017-04-25 15:24 ` Tom de Vries 2017-04-25 15:35 ` Mike Stump 2017-05-16 13:14 ` Rainer Orth 2017-05-22 17:10 ` Tom de Vries 2017-05-23 13:40 ` Tom de Vries 2017-05-23 15:24 ` Mike Stump 2020-10-30 11:34 ` Thomas Schwinge 2020-10-30 11:40 ` Jakub Jelinek 2020-10-30 13:40 ` Thomas Schwinge 2020-11-17 21:47 ` Jeff Law 2017-04-25 15:03 ` Jeff Law
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).