Re: [RFC, testsuite] Add dg-save-linenr

2020-11-17 Thread Jeff Law via Gcc-patches



On 10/30/20 5:34 AM, Thomas Schwinge wrote:
> Hi!
>
> On 2017-05-22T18:55:29+0200, Tom de Vries  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 
> 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



Re: [RFC, testsuite] Add dg-save-linenr

2020-10-30 Thread Thomas Schwinge
Hi Jakub!

On 2020-10-30T12:40:02+0100, Jakub Jelinek  wrote:
> On Fri, Oct 30, 2020 at 12:34:57PM +0100, Thomas Schwinge wrote:
>> On 2017-05-22T18:55:29+0200, Tom de Vries  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


Re: [RFC, testsuite] Add dg-save-linenr

2020-10-30 Thread Jakub Jelinek via Gcc-patches
On Fri, Oct 30, 2020 at 12:34:57PM +0100, Thomas Schwinge wrote:
> Hi!
> 
> On 2017-05-22T18:55:29+0200, Tom de Vries  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



Re: [RFC, testsuite] Add dg-save-linenr

2020-10-30 Thread Thomas Schwinge
Hi!

On 2017-05-22T18:55:29+0200, Tom de Vries  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
>From 2211acd9a902a5cab874762166dbca116a98bea5 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge 
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



Re: [RFC, testsuite] Add dg-save-linenr

2017-05-23 Thread Mike Stump
On May 22, 2017, at 9:55 AM, Tom de Vries  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.

Re: [RFC, testsuite] Add dg-save-linenr

2017-05-23 Thread Tom de Vries

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/msg0.html ).


Thanks,
- Tom


Re: [RFC, testsuite] Add dg-save-linenr

2017-05-22 Thread Tom de Vries

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
Document dg-line directive

2017-05-22  Tom de Vries  

	* 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},


Re: [RFC, testsuite] Add dg-save-linenr

2017-05-16 Thread Rainer Orth
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


Re: [RFC, testsuite] Add dg-save-linenr

2017-04-25 Thread Mike Stump
On Apr 25, 2017, at 8:21 AM, Tom de Vries  wrote:
> 
> OK for trunk?

Ok.



Re: [RFC, testsuite] Add dg-save-linenr

2017-04-25 Thread Tom de Vries

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

Re: [RFC, testsuite] Add dg-save-linenr

2017-04-25 Thread Jeff Law

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


Re: [RFC, testsuite] Add dg-save-linenr

2017-04-24 Thread David Malcolm
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



Re: [RFC, testsuite] Add dg-save-linenr

2017-04-24 Thread David Malcolm
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


Re: [RFC, testsuite] Add dg-save-linenr

2017-04-22 Thread Mike Stump
On Apr 22, 2017, at 10:49 AM, Tom de Vries  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.



[RFC, testsuite] Add dg-save-linenr

2017-04-22 Thread Tom de Vries

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
Add dg-save-linenr

2017-04-22  Tom de Vries  

	* 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