public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>,
	       Mike Stump <mikestump@comcast.net>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] Extend dg-{error,warning,message,bogus} line specification to allow relative line numbers
Date: Thu, 22 Sep 2016 20:10:00 -0000	[thread overview]
Message-ID: <20160922200546.GH7282@tucnak.redhat.com> (raw)

Hi!

This is something I've been unhappy for a long time with, and finally got to
write something for it.
When some test expects more than one error or warning or message on the same
source line, people have to use absolute line number on the dg-* directives
that is not on the right line, as DejaGNU handles just . (current line, the
default if the directive doesn't have all the arguments), 0 (no expected
line) and <number> for absolute line number.

This patch extends it, so one can write relative line numbers, . +/- <number>
as a single argument, say .-1 for the previous line number, .+1 for the next line
number, etc.  While one still has to supply the comment and target/xfail
arguments, the advantage of doing this is that if you adjust the testcase,
say add a line somewhere early, etc., you don't have to renumber all the
line numbers, and from what I saw in some clang testcases, it can be also
useful if multiple errors are issued for consecutive lines with different
wordings depending on some target supports etc. macros, one can e.g. use
  stmt1;	/* { dg-error "..." "" { target c } } */
  stmt2;	/* { dg-error "..." "" { target c } } */
  stmt3;	/* { dg-error "..." "" { target c } } */
		/* { dg-error "..." "" { target c++ } .-3 } */
		/* { dg-error "..." "" { target c++ } .-3 } */
		/* { dg-error "..." "" { target c++ } .-3 } */
which would be more readable than intermix the two sets of diagnostics.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-09-22  Jakub Jelinek  <jakub@redhat.com>

	* lib/gcc-dg.exp (process-message): Support relative line number
	notation - .+4 or .-1 etc.
	* gcc.dg/dg-test-1.c: New test.

--- gcc/testsuite/lib/gcc-dg.exp.jj	2016-06-24 12:59:19.000000000 +0200
+++ gcc/testsuite/lib/gcc-dg.exp	2016-09-22 17:29:21.912995332 +0200
@@ -986,6 +986,13 @@ if { [info procs saved-dg-error] == [lis
 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]
+    }
+
     # Process the dg- directive, including adding the regular expression
     # to the new message entry in dg-messages.
     set msgcnt [llength ${dg-messages}]
--- gcc/testsuite/gcc.dg/dg-test-1.c.jj	2016-09-22 17:19:39.984407351 +0200
+++ gcc/testsuite/gcc.dg/dg-test-1.c	2016-09-22 17:22:14.000000000 +0200
@@ -0,0 +1,18 @@
+/* Test relative line number specification extensions over what DejaGNU supports.  */
+/* { dg-do compile } */
+/* { dg-options "-Wunused-parameter" } */
+
+void
+foo (void)
+{			/* { dg-error "'a' undeclared" "err1" { target *-*-* } .+1 } */
+  int z = a + b + c + d;/* { dg-error "'b' undeclared" "err2" { target *-*-* } . } */
+}			/* { dg-error "'c' undeclared" "err3" { target *-*-* } .-1 } */
+
+
+/* { dg-error "'d' undeclared" "err4" { target *-*-* } .-4 } */
+/* { dg-warning "unused parameter 'e'" "warn1" { target *-*-* } .+3 } */
+
+void				/* { dg-warning "unused parameter 'f'" "warn2" { target *-*-* } .+1 } */
+bar (int e, int f, int g, int h)/* { dg-warning "unused parameter 'g'" "warn3" { target *-*-* } . } */
+{				/* { dg-warning "unused parameter 'h'" "warn4" { target *-*-* } .-1 } */
+}

	Jakub

             reply	other threads:[~2016-09-22 20:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-22 20:10 Jakub Jelinek [this message]
2016-09-23  1:21 ` Mike Stump
2016-09-23 15:02 ` Dominik Vogt
2016-09-23 15:05   ` Jakub Jelinek
2016-09-23 15:14     ` Dominik Vogt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160922200546.GH7282@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mikestump@comcast.net \
    --cc=ro@CeBiTec.Uni-Bielefeld.DE \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).