public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, testsuite] Allow braces around relative line numbers
@ 2017-03-28  7:45 Tom de Vries
  2017-03-28 22:24 ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Tom de Vries @ 2017-03-28  7:45 UTC (permalink / raw)
  To: Mike Stump, Rainer Orth; +Cc: GCC Patches

[-- 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-15 15:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-28  7:45 [PATCH, testsuite] Allow braces around relative line numbers Tom de Vries
2017-03-28 22:24 ` Jakub Jelinek
2017-04-15  8:34   ` Tom de Vries
2017-04-15 15:54     ` Mike Stump

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).