diff mbox

[RFC,testsuite] Add dg-save-linenr

Message ID 9feb5b24-5ba2-4316-c8d1-012d5a297029@mentor.com
State New
Headers show

Commit Message

Tom de Vries May 22, 2017, 4:55 p.m. UTC
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

Comments

Tom de Vries May 23, 2017, 1:24 p.m. UTC | #1
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
Mike Stump May 23, 2017, 3:14 p.m. UTC | #2
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.
Thomas Schwinge Oct. 30, 2020, 11:34 a.m. UTC | #3
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
Jakub Jelinek Oct. 30, 2020, 11:40 a.m. UTC | #4
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
Thomas Schwinge Oct. 30, 2020, 1:40 p.m. UTC | #5
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
Jeff Law Nov. 17, 2020, 9:47 p.m. UTC | #6
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
diff mbox

Patch

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