* [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
* Re: [PATCH, testsuite] Allow braces around relative line numbers
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
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2017-03-28 22:24 UTC (permalink / raw)
To: Tom de Vries; +Cc: Mike Stump, Rainer Orth, GCC Patches
On Tue, Mar 28, 2017 at 08:27:54AM +0200, Tom de Vries wrote:
> this patch fixes testsuite PR80220 - "relative line numbers don't work when
> put between braces".
What is the advantage of putting the line numbers between braces?
Isn't it easier to just drop those?
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH, testsuite] Allow braces around relative line numbers
2017-03-28 22:24 ` Jakub Jelinek
@ 2017-04-15 8:34 ` Tom de Vries
2017-04-15 15:54 ` Mike Stump
0 siblings, 1 reply; 4+ messages in thread
From: Tom de Vries @ 2017-04-15 8:34 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Mike Stump, Rainer Orth, GCC Patches
[-- Attachment #1: Type: text/plain, Size: 730 bytes --]
On 03/29/2017 12:23 AM, Jakub Jelinek wrote:
> On Tue, Mar 28, 2017 at 08:27:54AM +0200, Tom de Vries wrote:
>> this patch fixes testsuite PR80220 - "relative line numbers don't work when
>> put between braces".
>
> What is the advantage of putting the line numbers between braces?
I don't know of any advantages.
> Isn't it easier to just drop those?
I've attached two patches:
- first patch implements a script
contrib/tests-normalize-line-number.sh that removes braces around
line numbers.
- second patch is the result of running the script.
Tested by running the patched test-cases.
Second patch OK for stage4/stage1 trunk?
[ I'm not sure if the first patch is useful enough to commit to contrib. ]
Thanks,
- Tom
[-- Attachment #2: 0001-Add-contrib-tests-normalize-line-number.sh.patch --]
[-- Type: text/x-patch, Size: 2831 bytes --]
Add contrib/tests-normalize-line-number.sh
2017-04-15 Tom de Vries <tom@codesourcery.com>
* tests-normalize-line-number.sh: New file.
---
contrib/tests-normalize-line-number.sh | 78 ++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
diff --git a/contrib/tests-normalize-line-number.sh b/contrib/tests-normalize-line-number.sh
new file mode 100755
index 0000000..9ecba6a
--- /dev/null
+++ b/contrib/tests-normalize-line-number.sh
@@ -0,0 +1,78 @@
+#!/usr/bin/env python2
+
+# We hit a bug with python 3 when doing replace_in_file_p() with
+# ./libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/10132-1.cc, so let's
+# use python 2 and import the print function from python 3.
+from __future__ import print_function
+
+import os, re
+import fileinput
+
+# A non-negative number.
+number="[0-9][0-9]*"
+# Allow quotes around the number.
+number=(
+ "(?:" +
+ number + "|" +
+ '"' + number + '"' + "|" +
+ "'" + number + "'" +
+ ")"
+)
+# Directives using a line number.
+directive="dg-(?:error|warning|message|bogus)"
+# Line containing directive.
+directiveline=(
+ "(.*\{\s*%s.*)" % directive + # Part before line number. Save it.
+ "\{\s*(%s)\s*\}" % number + # A number in braces. Save the number.
+ "\s*\}" + # Closing brace of directive.
+ "(.*)" # Rest of line. Save it.
+)
+# Match the entire line
+directiveline=(
+ "^" +
+ directiveline +
+ "$"
+)
+pattern=re.compile(directiveline)
+
+extensions="c|cc|C|cpp|f|F|[fF]03|[fF]08|[fF]90|[fF]95|go|h|i|m|mm|S|adb|ads"
+extensionspattern=re.compile(".*\.(?:" + extensions + ")$")
+
+def do_replace_in_file(file):
+ for line in fileinput.input(files=file,inplace=True):
+ match=pattern.search(line)
+ if match:
+ line=(
+ match.group(1) + # Part before line number.
+ match.group(2) + # Line number.
+ " }" + # Closing brace of directive.
+ match.group(3) # Rest of line.
+ )
+ line+="\n"
+
+ print(line, end='')
+
+def replace_in_file_p(file):
+ filehandle = open(file, 'r')
+ for line in filehandle:
+ match=pattern.search(line)
+ if match:
+ return True
+
+ return False
+
+def do_testsuite_dir(testsuite_dir):
+ for root, dirs, files in os.walk(testsuite_dir):
+ for file in files:
+ if extensionspattern.match(file):
+ fullname=os.path.join(root, file)
+ if replace_in_file_p(fullname):
+ do_replace_in_file(fullname)
+
+def do_dir(rootdir):
+ for root, dirs, files in os.walk(rootdir):
+ for dir in dirs:
+ if dir == "testsuite":
+ do_testsuite_dir(os.path.join(root, dir))
+
+do_dir(".")
[-- Attachment #3: 0002-Remove-braces-around-line-number-in-dejagnu-directive.patch --]
[-- Type: text/x-patch, Size: 6785 bytes --]
Remove braces around line number in dejagnu directive
2017-04-14 Tom de Vries <tom@codesourcery.com>
* g++.dg/parse/error11.C: Remove braces around line number in dejagnu
directive.
* g++.dg/parse/error3.C: Same.
* g++.old-deja/g++.pt/niklas01a.C: Same.
* gcc.dg/990506-0.c: Same.
* gcc.dg/cpp/19990413-1.c: Same.
* gcc.dg/cpp/pragma-1.c: Same.
* gcc.dg/cpp/pragma-2.c: Same.
* gcc.dg/m-un-2.c: Same.
* objc.dg/private-1.m: Same.
---
gcc/testsuite/g++.dg/parse/error11.C | 2 +-
gcc/testsuite/g++.dg/parse/error3.C | 2 +-
gcc/testsuite/g++.old-deja/g++.pt/niklas01a.C | 2 +-
gcc/testsuite/gcc.dg/990506-0.c | 4 ++--
gcc/testsuite/gcc.dg/cpp/19990413-1.c | 2 +-
gcc/testsuite/gcc.dg/cpp/pragma-1.c | 4 ++--
gcc/testsuite/gcc.dg/cpp/pragma-2.c | 4 ++--
gcc/testsuite/gcc.dg/m-un-2.c | 4 ++--
gcc/testsuite/objc.dg/private-1.m | 2 +-
9 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/gcc/testsuite/g++.dg/parse/error11.C b/gcc/testsuite/g++.dg/parse/error11.C
index 846e676..a67160b 100644
--- a/gcc/testsuite/g++.dg/parse/error11.C
+++ b/gcc/testsuite/g++.dg/parse/error11.C
@@ -50,7 +50,7 @@ void func(void)
// the special error message.
Foo<: :B> k2; // { dg-bogus "cannot begin|alternate spelling" "smart error should not be triggered here" }
Foo[:B> k1; // { dg-bogus "cannot begin|alternate spelling" "smart error should not be triggered here" }
-// { dg-error "6:missing template arguments before" "template" { target *-*-* } { 51 } }
+// { dg-error "6:missing template arguments before" "template" { target *-*-* } 51 }
// { dg-error "9:expected primary-expression before ':' token" "primary" { target *-*-* } 51 }
// { dg-error "9:expected '\]' before ':' token" "backslash" { target *-*-* } 51 }
// { dg-error "6:missing template arguments before" "template" { target *-*-* } 52 }
diff --git a/gcc/testsuite/g++.dg/parse/error3.C b/gcc/testsuite/g++.dg/parse/error3.C
index 938ab45..cf01dbe 100644
--- a/gcc/testsuite/g++.dg/parse/error3.C
+++ b/gcc/testsuite/g++.dg/parse/error3.C
@@ -5,4 +5,4 @@ static void InstantiateConstraint(const float&, unsigned,
void(*AddFunction)(const TYPE&,bool&,
char*, char*,
unsigned*));
-// { dg-error "60: 'TYPE' does not name a type" "does not" { target *-*-* } { 5 } }
+// { dg-error "60: 'TYPE' does not name a type" "does not" { target *-*-* } 5 }
diff --git a/gcc/testsuite/g++.old-deja/g++.pt/niklas01a.C b/gcc/testsuite/g++.old-deja/g++.pt/niklas01a.C
index 3130d32..f2b27a6 100644
--- a/gcc/testsuite/g++.old-deja/g++.pt/niklas01a.C
+++ b/gcc/testsuite/g++.old-deja/g++.pt/niklas01a.C
@@ -4,6 +4,6 @@
struct A { // { dg-message "" } forward declaration
friend struct B : A { // { dg-error "invalid use of incomplete type 'struct A" "invalid" }
int x;
- }; // { dg-error "class definition may not be declared a friend" "may not" { target *-*-* } { 5 } }
+ }; // { dg-error "class definition may not be declared a friend" "may not" { target *-*-* } 5 }
int y;
};
diff --git a/gcc/testsuite/gcc.dg/990506-0.c b/gcc/testsuite/gcc.dg/990506-0.c
index 3cd3be3..3f5f02d 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 *-*-* } 6 } */
+ /* { dg-message "function it appears in" "reminder message" { target *-*-* } 6 } */
}
diff --git a/gcc/testsuite/gcc.dg/cpp/19990413-1.c b/gcc/testsuite/gcc.dg/cpp/19990413-1.c
index 17d8441..c72c3a2 100644
--- a/gcc/testsuite/gcc.dg/cpp/19990413-1.c
+++ b/gcc/testsuite/gcc.dg/cpp/19990413-1.c
@@ -9,5 +9,5 @@ func(void)
{
FOO(i
= 4)
- else; /* { dg-error "'else' without a previous 'if'" "error on this line" { target *-*-* } { 12 } } */
+ else; /* { dg-error "'else' without a previous 'if'" "error on this line" { target *-*-* } 12 } */
}
diff --git a/gcc/testsuite/gcc.dg/cpp/pragma-1.c b/gcc/testsuite/gcc.dg/cpp/pragma-1.c
index 7fab025..7b4ee36 100644
--- a/gcc/testsuite/gcc.dg/cpp/pragma-1.c
+++ b/gcc/testsuite/gcc.dg/cpp/pragma-1.c
@@ -7,7 +7,7 @@ main ()
#pragma unknown
{
error;
- /* { dg-error "undeclared" "undeclared-variable message" { target *-*-* } { 9 } } */
- /* { dg-message "function it appears in" "reminder message" { target *-*-* } { 9 } } */
+ /* { dg-error "undeclared" "undeclared-variable message" { target *-*-* } 9 } */
+ /* { dg-message "function it appears in" "reminder message" { target *-*-* } 9 } */
}
}
diff --git a/gcc/testsuite/gcc.dg/cpp/pragma-2.c b/gcc/testsuite/gcc.dg/cpp/pragma-2.c
index 921f4e5..001365f 100644
--- a/gcc/testsuite/gcc.dg/cpp/pragma-2.c
+++ b/gcc/testsuite/gcc.dg/cpp/pragma-2.c
@@ -11,6 +11,6 @@ int main () {
#pragma unknown
{}
error;
- /* { dg-error "undeclared" "undeclared-variable message" { target *-*-* } { 13 } } */
- /* { dg-message "function it appears in" "reminder message" { target *-*-* } { 13 } } */
+ /* { dg-error "undeclared" "undeclared-variable message" { target *-*-* } 13 } */
+ /* { dg-message "function it appears in" "reminder message" { target *-*-* } 13 } */
}
diff --git a/gcc/testsuite/gcc.dg/m-un-2.c b/gcc/testsuite/gcc.dg/m-un-2.c
index 0b96628..882ae88 100644
--- a/gcc/testsuite/gcc.dg/m-un-2.c
+++ b/gcc/testsuite/gcc.dg/m-un-2.c
@@ -15,8 +15,8 @@ struct vtable {
struct vtable mtable = {
malloc,
free
-}; /* { dg-warning "missing initializer" "warning regression" { target *-*-* } {18} } */
- /* { dg-message "declared here" "warning regression 2" { target *-*-* } {12} } */
+}; /* { dg-warning "missing initializer" "warning regression" { target *-*-* } 18 } */
+ /* { dg-message "declared here" "warning regression 2" { target *-*-* } 12 } */
/* With designated initializers, we assume you meant to leave out the
initialization of any blank fields. */
diff --git a/gcc/testsuite/objc.dg/private-1.m b/gcc/testsuite/objc.dg/private-1.m
index a11183c..790ba19 100644
--- a/gcc/testsuite/objc.dg/private-1.m
+++ b/gcc/testsuite/objc.dg/private-1.m
@@ -35,7 +35,7 @@
{
/* Private variables simply don't exist in the subclass. */
private = 12; /* { dg-error "instance variable" } */
- /* { dg-message "function it appears in" "" { target *-*-* } { 37 } } */
+ /* { dg-message "function it appears in" "" { target *-*-* } 37 } */
protected = 12; /* Ok */
public = 12; /* Ok */
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH, testsuite] Allow braces around relative line numbers
2017-04-15 8:34 ` Tom de Vries
@ 2017-04-15 15:54 ` Mike Stump
0 siblings, 0 replies; 4+ messages in thread
From: Mike Stump @ 2017-04-15 15:54 UTC (permalink / raw)
To: Tom de Vries; +Cc: Jakub Jelinek, Rainer Orth, GCC Patches
On Apr 15, 2017, at 1:07 AM, Tom de Vries <Tom_deVries@mentor.com> wrote:
> I've attached two patches:
>
> - second patch is the result of running the script.
> Second patch OK for stage4/stage1 trunk?
Ok.
> [ I'm not sure if the first patch is useful enough to commit to contrib. ]
Once the script it run, we shouldn't have to run it again. So, I think it can live as a reference on the mailing list.
> 2017-04-14 Tom de Vries <tom@codesourcery.com>
>
> * g++.dg/parse/error11.C: Remove braces around line number in dejagnu
> directive.
> * g++.dg/parse/error3.C: Same.
> * g++.old-deja/g++.pt/niklas01a.C: Same.
> * gcc.dg/990506-0.c: Same.
> * gcc.dg/cpp/19990413-1.c: Same.
> * gcc.dg/cpp/pragma-1.c: Same.
> * gcc.dg/cpp/pragma-2.c: Same.
> * gcc.dg/m-un-2.c: Same.
> * objc.dg/private-1.m: Same.
^ 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).