public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tom de Vries <Tom_deVries@mentor.com>
To: Mike Stump <mikestump@comcast.net>,
	Rainer Orth	<ro@CeBiTec.Uni-Bielefeld.DE>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH, testsuite] Allow braces around relative line numbers
Date: Tue, 28 Mar 2017 07:45:00 -0000	[thread overview]
Message-ID: <31cf86fd-eda4-e373-5263-a3b36854109e@mentor.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1815 bytes --]

Hi,

this patch fixes testsuite PR80220 - "relative line numbers don't work 
when put between braces".


Consider gcc/testsuite/gcc.dg/990506-0.c, which has absolute line 
numbers between braces:
...
$ cat -n 990506-0.c
      1	/* Verify that a diagnostic is issued without crashing due to
      2	   --enable-checking catching a bug in the C front end.  */
      3	/* { dg-do compile } */
      4	x()
      5	{
      6	  foo (i);
      7	  /* { dg-error "undeclared" "undeclared-variable message" { 
target *-*-* } { 6 } } */
      8	  /* { dg-message "function it appears in" "reminder message" { 
target *-*-* } { 6 } } */
      9	}
...

When we rewrite the test to use relative line numbers:
...
diff --git a/gcc/testsuite/gcc.dg/990506-0.c 
b/gcc/testsuite/gcc.dg/990506-0.c
index 3cd3be3..08ba856 100644
--- a/gcc/testsuite/gcc.dg/990506-0.c
+++ b/gcc/testsuite/gcc.dg/990506-0.c
@@ -4,6 +4,6 @@
  x()
  {
    foo (i);
-  /* { dg-error "undeclared" "undeclared-variable message" { target 
*-*-* } { 6 } } */
-  /* { dg-message "function it appears in" "reminder message" { target 
*-*-* } { 6 } } */
+  /* { dg-error "undeclared" "undeclared-variable message" { target 
*-*-* } { .-1 } } */
+  /* { dg-message "function it appears in" "reminder message" { target 
*-*-* } { .-2 } } */
  }
...

we run into trouble:
...
ERROR: gcc.dg/990506-0.c: expected integer but got " .-1 " for " 
dg-error 7 "undeclared" "undeclared-variable message" { target *-*-* } { 
.-1 } "
...

The problem is that the relative line number is written between braces, 
which results in whitespace before and after the number, and the 
relative line number handling in process-message doesn't handle that 
whitespace well.

This patch fixes that.

Bootstrapped and reg-tested on x86_64.

OK for stage4 or stage1 trunk?

Thanks,
- Tom

[-- Attachment #2: 0001-Allow-braces-around-relative-line-numbers.patch --]
[-- Type: text/x-patch, Size: 2248 bytes --]

Allow braces around relative line numbers

2017-03-27  Tom de Vries  <tom@codesourcery.com>

	PR testsuite/80220
	* gcc.dg/dg-test-1.c: Add dg-error tests using relative line numbers
	between braces.
	(foo2): New function.
	* lib/gcc-dg.exp (process-message): Handle whitespace in relative line
	number argument.

---
 gcc/testsuite/gcc.dg/dg-test-1.c |  7 +++++++
 gcc/testsuite/lib/gcc-dg.exp     | 16 +++++++++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/dg-test-1.c b/gcc/testsuite/gcc.dg/dg-test-1.c
index c67f93b..2414ecc 100644
--- a/gcc/testsuite/gcc.dg/dg-test-1.c
+++ b/gcc/testsuite/gcc.dg/dg-test-1.c
@@ -40,3 +40,10 @@ baz (int i, int j)
 
 
 /* { dg-warning "unused parameter 'j'" "warn6" { target *-*-* } .-10 } */
+
+/* Test for relative line numbers in braces */
+void
+foo2 (void)
+{			/* { dg-error "'a' undeclared" "err1" { target *-*-* } { .+1 } } */
+  int z = a + b + c;    /* { dg-error "'b' undeclared" "err2" { target *-*-* } { . } } */
+}			/* { dg-error "'c' undeclared" "err3" { target *-*-* } { .-1 } } */
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index 83c38cf..e986d64 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -988,11 +988,17 @@ 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 } {
+	set linenr [lindex $dgargs 4]
+	# Strip whitespace added by using braces.
+	set linenr [string trimleft [string trimright $linenr]]
+	# Handle relative line specification, .+1 or .-1 etc.
+	if { [regsub "^\.\[+-\](\[0-9\]+)$" $linenr "\\1" num] } {
+	    set directivelinenr [lindex $dgargs 0]
+	    set op [string index $linenr 1]
+	    set linenr [expr $directivelinenr $op $num]
+	}
+	set dgargs [lreplace $dgargs 4 4 $linenr]
     }
 
     # Process the dg- directive, including adding the regular expression

             reply	other threads:[~2017-03-28  6:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-28  7:45 Tom de Vries [this message]
2017-03-28 22:24 ` Jakub Jelinek
2017-04-15  8:34   ` Tom de Vries
2017-04-15 15:54     ` Mike Stump

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=31cf86fd-eda4-e373-5263-a3b36854109e@mentor.com \
    --to=tom_devries@mentor.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).