This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 04/14] Update testsuite to show improvements
- From: David Malcolm <dmalcolm at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: Nathan Sidwell <nathan at acm dot org>, Jakub Jelinek <jakub at redhat dot com>, Richard Biener <richard dot guenther at gmail dot com>, gcc-patches List <gcc-patches at gcc dot gnu dot org>, David Malcolm <dmalcolm at redhat dot com>
- Date: Fri, 10 Nov 2017 16:45:19 -0500
- Subject: [PATCH 04/14] Update testsuite to show improvements
- Authentication-results: sourceware.org; auth=none
- References: <CADzB+2kfB26fTGXk2AVWuN1mv641OrcEBze+Lq-KexXHeS=Y9A@mail.gmail.com> <1510350329-48956-1-git-send-email-dmalcolm@redhat.com>
gcc/testsuite/ChangeLog:
PR c++/43486
* g++.dg/diagnostic/param-type-mismatch.C: Update expected results
to reflect that the arguments are correctly underlined.
* g++.dg/plugin/diagnostic-test-expressions-1.C: Add test coverage
for globals, params, locals and literals.
(test_sizeof): Directly test the location of "sizeof", rather than
when used in compound expressions.
(test_alignof): Likewise for "alignof".
(test_string_literals): Likewise for string literals.
(test_numeric_literals): Likewise for numeric literals.
(test_builtin_offsetof): Likewise for "__builtin_offsetof".
(test_typeid): Likewise for typeid.
(test_unary_plus): New.
---
.../g++.dg/diagnostic/param-type-mismatch.C | 27 +--
.../g++.dg/plugin/diagnostic-test-expressions-1.C | 260 +++++++++++++--------
2 files changed, 172 insertions(+), 115 deletions(-)
diff --git a/gcc/testsuite/g++.dg/diagnostic/param-type-mismatch.C b/gcc/testsuite/g++.dg/diagnostic/param-type-mismatch.C
index bc3a938..5fcde0b 100644
--- a/gcc/testsuite/g++.dg/diagnostic/param-type-mismatch.C
+++ b/gcc/testsuite/g++.dg/diagnostic/param-type-mismatch.C
@@ -1,9 +1,6 @@
// { dg-options "-fdiagnostics-show-caret" }
-/* A collection of calls where argument 2 is of the wrong type.
-
- TODO: we should put the caret and underline for the diagnostic
- at the second argument, rather than the close paren. */
+/* A collection of calls where argument 2 is of the wrong type. */
/* decl, with argname. */
@@ -14,7 +11,7 @@ int test_1 (int first, int second, float third)
return callee_1 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
/* { dg-begin-multiline-output "" }
return callee_1 (first, second, third);
- ^
+ ^~~~~~
{ dg-end-multiline-output "" } */
// { dg-message "initializing argument 2 of 'int callee_1\\(int, const char\\*, float\\)'" "" { target *-*-* } callee_1 }
/* { dg-begin-multiline-output "" }
@@ -32,7 +29,7 @@ int test_2 (int first, int second, float third)
return callee_2 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
/* { dg-begin-multiline-output "" }
return callee_2 (first, second, third);
- ^
+ ^~~~~~
{ dg-end-multiline-output "" } */
// { dg-message "initializing argument 2 of 'int callee_2\\(int, const char\\*, float\\)'" "" { target *-*-* } callee_2 }
/* { dg-begin-multiline-output "" }
@@ -53,7 +50,7 @@ int test_3 (int first, int second, float third)
return callee_3 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
/* { dg-begin-multiline-output "" }
return callee_3 (first, second, third);
- ^
+ ^~~~~~
{ dg-end-multiline-output "" } */
// { dg-message "initializing argument 2 of 'int callee_3\\(int, const char\\*, float\\)'" "" { target *-*-* } callee_3 }
/* { dg-begin-multiline-output "" }
@@ -71,7 +68,7 @@ int test_4 (int first, int second, float third)
return s4::member_1 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
/* { dg-begin-multiline-output "" }
return s4::member_1 (first, second, third);
- ^
+ ^~~~~~
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
struct s4 { static int member_1 (int one, const char *two, float three); };
@@ -89,7 +86,7 @@ int test_5 (int first, int second, float third)
return inst.member_1 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
/* { dg-begin-multiline-output "" }
return inst.member_1 (first, second, third);
- ^
+ ^~~~~~
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
struct s5 { int member_1 (int one, const char *two, float three); };
@@ -106,7 +103,7 @@ int test_6 (int first, int second, float third, s6 *ptr)
return ptr->member_1 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
/* { dg-begin-multiline-output "" }
return ptr->member_1 (first, second, third);
- ^
+ ^~~~~~
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
struct s6 { int member_1 (int one, const char *two, float three); };
@@ -128,7 +125,7 @@ int test_7 (int first, int second, float third)
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
return test_7 <const char *> (first, second, third);
- ^
+ ^~~~~~
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
int test_7 (int one, T two, float three);
@@ -146,7 +143,7 @@ int test_8 (int first, int second, float third)
return s8 <const char *>::member_1 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
/* { dg-begin-multiline-output "" }
return s8 <const char *>::member_1 (first, second, third);
- ^
+ ^~~~~~
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
struct s8 { static int member_1 (int one, T two, float three); };
@@ -165,7 +162,7 @@ int test_9 (int first, int second, float third)
return inst.member_1 (first, second, third); // { dg-error "invalid conversion from 'int' to 'const char\\*'" }
/* { dg-begin-multiline-output "" }
return inst.member_1 (first, second, third);
- ^
+ ^~~~~~
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
struct s9 { int member_1 (int one, T two, float three); };
@@ -182,7 +179,7 @@ int test_10 (int first, int second, float third)
return callee_10 (first, second, third); // { dg-error "invalid conversion from 'int' to 'int \\(\\*\\)\\(int, int\\)'" }
/* { dg-begin-multiline-output "" }
return callee_10 (first, second, third);
- ^
+ ^~~~~~
{ dg-end-multiline-output "" } */
// { dg-message "initializing argument 2 of 'int callee_10\\(int, int \\(\\*\\)\\(int, int\\), float\\)'" "" { target *-*-* } callee_10 }
/* { dg-begin-multiline-output "" }
@@ -200,7 +197,7 @@ int test_11 (int first, int second, float third)
return callee_11 (first, second, third); // { dg-error "invalid conversion from 'int' to 'int \\(\\*\\)\\(int, int\\)'" }
/* { dg-begin-multiline-output "" }
return callee_11 (first, second, third);
- ^
+ ^~~~~~
{ dg-end-multiline-output "" } */
// { dg-message "initializing argument 2 of 'int callee_11\\(int, int \\(\\*\\)\\(int, int\\), float\\)'" "" { target *-*-* } callee_11 }
/* { dg-begin-multiline-output "" }
diff --git a/gcc/testsuite/g++.dg/plugin/diagnostic-test-expressions-1.C b/gcc/testsuite/g++.dg/plugin/diagnostic-test-expressions-1.C
index a145dfe..5e4d78b 100644
--- a/gcc/testsuite/g++.dg/plugin/diagnostic-test-expressions-1.C
+++ b/gcc/testsuite/g++.dg/plugin/diagnostic-test-expressions-1.C
@@ -19,6 +19,113 @@ extern void __emit_expression_range (int dummy, ...);
int global;
+void test_global (void)
+{
+ __emit_expression_range (0, global); /* { dg-warning "range" } */
+/* { dg-begin-multiline-output "" }
+ __emit_expression_range (0, global);
+ ^~~~~~
+ { dg-end-multiline-output "" } */
+}
+
+void test_param (int param)
+{
+ __emit_expression_range (0, param); /* { dg-warning "range" } */
+/* { dg-begin-multiline-output "" }
+ __emit_expression_range (0, param);
+ ^~~~~
+ { dg-end-multiline-output "" } */
+}
+
+void test_local (void)
+{
+ int local = 5;
+
+ __emit_expression_range (0, local); /* { dg-warning "range" } */
+/* { dg-begin-multiline-output "" }
+ __emit_expression_range (0, local);
+ ^~~~~
+ { dg-end-multiline-output "" } */
+}
+
+void test_integer_constants (void)
+{
+ __emit_expression_range (0, 1234); /* { dg-warning "range" } */
+/* { dg-begin-multiline-output "" }
+ __emit_expression_range (0, 1234);
+ ^~~~
+ { dg-end-multiline-output "" } */
+
+ /* Ensure that zero works. */
+
+ __emit_expression_range (0, 0); /* { dg-warning "range" } */
+/* { dg-begin-multiline-output "" }
+ __emit_expression_range (0, 0);
+ ^
+ { dg-end-multiline-output "" } */
+}
+
+void test_character_constants (void)
+{
+ __emit_expression_range (0, 'a'); /* { dg-warning "range" } */
+/* { dg-begin-multiline-output "" }
+ __emit_expression_range (0, 'a');
+ ^~~
+ { dg-end-multiline-output "" } */
+}
+
+void test_floating_constants (void)
+{
+ __emit_expression_range (0, 98.6); /* { dg-warning "range" } */
+/* { dg-begin-multiline-output "" }
+ __emit_expression_range (0, 98.6);
+ ^~~~
+ { dg-end-multiline-output "" } */
+
+ __emit_expression_range (0, .6); /* { dg-warning "range" } */
+/* { dg-begin-multiline-output "" }
+ __emit_expression_range (0, .6);
+ ^~
+ { dg-end-multiline-output "" } */
+
+ __emit_expression_range (0, 98.); /* { dg-warning "range" } */
+/* { dg-begin-multiline-output "" }
+ __emit_expression_range (0, 98.);
+ ^~~
+ { dg-end-multiline-output "" } */
+
+ __emit_expression_range (0, 6.022140857e23 ); /* { dg-warning "range" } */
+/* { dg-begin-multiline-output "" }
+ __emit_expression_range (0, 6.022140857e23 );
+ ^~~~~~~~~~~~~~
+ { dg-end-multiline-output "" } */
+
+ __emit_expression_range (0, 98.6f ); /* { dg-warning "range" } */
+/* { dg-begin-multiline-output "" }
+ __emit_expression_range (0, 98.6f );
+ ^~~~~
+ { dg-end-multiline-output "" } */
+
+ __emit_expression_range (0, 6.022140857e23l ); /* { dg-warning "range" } */
+/* { dg-begin-multiline-output "" }
+ __emit_expression_range (0, 6.022140857e23l );
+ ^~~~~~~~~~~~~~~
+ { dg-end-multiline-output "" } */
+}
+
+enum test_enum {
+ TEST_ENUM_VALUE
+};
+
+void test_enumeration_constant (void)
+{
+ __emit_expression_range (0, TEST_ENUM_VALUE ); /* { dg-warning "range" } */
+/* { dg-begin-multiline-output "" }
+ __emit_expression_range (0, TEST_ENUM_VALUE );
+ ^~~~~~~~~~~~~~~
+ { dg-end-multiline-output "" } */
+}
+
void test_parentheses (int a, int b)
{
__emit_expression_range (0, (a + b) ); /* { dg-warning "range" } */
@@ -103,67 +210,36 @@ int test_postfix_incdec (int i)
int test_sizeof (int i)
{
- __emit_expression_range (0, sizeof(int) + i); /* { dg-warning "range" } */
-/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, sizeof(int) + i);
- ~~~~~~~~~~~~^~~
- { dg-end-multiline-output "" } */
-
- __emit_expression_range (0, i + sizeof(int)); /* { dg-warning "range" } */
-/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, i + sizeof(int));
- ~~^~~~~~~~~~~~~
- { dg-end-multiline-output "" } */
-
- __emit_expression_range (0, sizeof i + i); /* { dg-warning "range" } */
+ __emit_expression_range (0, sizeof i ); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, sizeof i + i);
- ~~~~~~~~~^~~
+ __emit_expression_range (0, sizeof i );
+ ^~~~~~~~
{ dg-end-multiline-output "" } */
- __emit_expression_range (0, i + sizeof i); /* { dg-warning "range" } */
+ __emit_expression_range (0, sizeof (char) ); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, i + sizeof i);
- ~~^~~~~~~~~~
+ __emit_expression_range (0, sizeof (char) );
+ ^~~~~~~~~~~~~
{ dg-end-multiline-output "" } */
}
int test_alignof (int i)
{
- __emit_expression_range (0, alignof(int) + i); /* { dg-warning "range" } */
+ __emit_expression_range (0, alignof(int)); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, alignof(int) + i);
- ~~~~~~~~~~~~~^~~
- { dg-end-multiline-output "" } */
-
- __emit_expression_range (0, i + alignof(int)); /* { dg-warning "range" } */
-/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, i + alignof(int));
- ~~^~~~~~~~~~~~~~
- { dg-end-multiline-output "" } */
-
- __emit_expression_range (0, __alignof__(int) + i); /* { dg-warning "range" } */
-/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, __alignof__(int) + i);
- ~~~~~~~~~~~~~~~~~^~~
- { dg-end-multiline-output "" } */
-
- __emit_expression_range (0, i + __alignof__(int)); /* { dg-warning "range" } */
-/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, i + __alignof__(int));
- ~~^~~~~~~~~~~~~~~~~~
+ __emit_expression_range (0, alignof(int));
+ ^~~~~~~~~~~~
{ dg-end-multiline-output "" } */
- __emit_expression_range (0, __alignof__ i + i); /* { dg-warning "range" } */
+ __emit_expression_range (0, __alignof__(int)); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, __alignof__ i + i);
- ~~~~~~~~~~~~~~^~~
+ __emit_expression_range (0, __alignof__(int));
+ ^~~~~~~~~~~~~~~~
{ dg-end-multiline-output "" } */
-
- __emit_expression_range (0, i + __alignof__ i); /* { dg-warning "range" } */
+ __emit_expression_range (0, __alignof__ i); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, i + __alignof__ i);
- ~~^~~~~~~~~~~~~~~
+ __emit_expression_range (0, __alignof__ i);
+ ^~~~~~~~~~~~~
{ dg-end-multiline-output "" } */
}
@@ -200,6 +276,15 @@ void test_indirection (int *ptr)
{ dg-end-multiline-output "" } */
}
+void test_unary_plus (int i)
+{
+ __emit_expression_range (0, +i ); /* { dg-warning "range" } */
+/* { dg-begin-multiline-output "" }
+ __emit_expression_range (0, +i );
+ ^~
+ { dg-end-multiline-output "" } */
+}
+
void test_unary_minus (int i)
{
__emit_expression_range (0, -i ); /* { dg-warning "range" } */
@@ -471,53 +556,36 @@ void test_comma_operator (int a, int b)
/* Literals. **************************************************/
-/* We can't test the ranges of literals directly, since the underlying
- tree nodes don't retain a location. However, we can test that they
- have ranges during parsing by building compound expressions using
- them, and verifying the ranges of the compound expressions. */
-
-void test_string_literals (int i)
+void test_string_literals ()
{
- __emit_expression_range (0, "foo"[i] ); /* { dg-warning "range" } */
+ __emit_expression_range (0, "0123456789"); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, "foo"[i] );
- ~~~~~~~^
+ __emit_expression_range (0, "0123456789");
+ ^~~~~~~~~~~~
{ dg-end-multiline-output "" } */
- __emit_expression_range (0, &"foo" "bar" ); /* { dg-warning "range" } */
+ __emit_expression_range (0, "foo" "bar" ); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, &"foo" "bar" );
- ^~~~~~~~~~~~
+ __emit_expression_range (0, "foo" "bar" );
+ ^~~~~~~~~~~
{ dg-end-multiline-output "" } */
}
void test_numeric_literals (int i)
{
- __emit_expression_range (0, 42 + i ); /* { dg-warning "range" } */
-/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, 42 + i );
- ~~~^~~
- { dg-end-multiline-output "" } */
-
- __emit_expression_range (0, i + 42 ); /* { dg-warning "range" } */
+ __emit_expression_range (0, 42 ); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, i + 42 );
- ~~^~~~
+ __emit_expression_range (0, 42 );
+ ^~
{ dg-end-multiline-output "" } */
/* Verify locations of negative literals (via folding of
unary negation). */
- __emit_expression_range (0, -42 + i ); /* { dg-warning "range" } */
-/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, -42 + i );
- ~~~~^~~
- { dg-end-multiline-output "" } */
-
- __emit_expression_range (0, i + -42 ); /* { dg-warning "range" } */
+ __emit_expression_range (0, -42 ); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, i + -42 );
- ~~^~~~~
+ __emit_expression_range (0, -42 );
+ ^~~
{ dg-end-multiline-output "" } */
__emit_expression_range (0, i ? 0 : -1 ); /* { dg-warning "range" } */
@@ -529,6 +597,8 @@ void test_numeric_literals (int i)
/* Braced initializers. ***************************************/
+// FIXME:
+
/* We can't test the ranges of these directly, since the underlying
tree nodes don't retain a location. However, we can test that they
have ranges during parsing by building compound expressions using
@@ -556,6 +626,8 @@ void test_braced_init (void)
/* Statement expressions. ***************************************/
+// FIXME:
+
void test_statement_expression (void)
{
__emit_expression_range (0, ({ static int a; a; }) + 1); /* { dg-warning "range" } */
@@ -638,16 +710,10 @@ struct s { int i; float f; };
void test_builtin_offsetof (int i)
{
- __emit_expression_range (0, i + __builtin_offsetof (struct s, f) ); /* { dg-warning "range" } */
+ __emit_expression_range (0, __builtin_offsetof (struct s, f) ); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, i + __builtin_offsetof (struct s, f) );
- ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- { dg-end-multiline-output "" } */
-
- __emit_expression_range (0, __builtin_offsetof (struct s, f) + i ); /* { dg-warning "range" } */
-/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, __builtin_offsetof (struct s, f) + i );
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
+ __emit_expression_range (0, __builtin_offsetof (struct s, f) );
+ ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
{ dg-end-multiline-output "" } */
}
@@ -856,28 +922,22 @@ namespace std
void test_typeid (int i)
{
- __emit_expression_range (0, &typeid(i)); /* { dg-warning "range" } */
+ __emit_expression_range (0, typeid(i)); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, &typeid(i));
- ^~~~~~~~~~
- { dg-end-multiline-output "" } */
-
- __emit_expression_range (0, &typeid(int)); /* { dg-warning "range" } */
-/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, &typeid(int));
- ^~~~~~~~~~~~
+ __emit_expression_range (0, typeid(i));
+ ^~~~~~~~~
{ dg-end-multiline-output "" } */
- __emit_expression_range (0, &typeid(i * 2)); /* { dg-warning "range" } */
+ __emit_expression_range (0, typeid(int)); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, &typeid(i * 2));
- ^~~~~~~~~~~~~~
+ __emit_expression_range (0, typeid(int));
+ ^~~~~~~~~~~
{ dg-end-multiline-output "" } */
- __emit_expression_range (0, typeid(int).foo); /* { dg-warning "range" } */
+ __emit_expression_range (0, typeid(i * 2)); /* { dg-warning "range" } */
/* { dg-begin-multiline-output "" }
- __emit_expression_range (0, typeid(int).foo);
- ~~~~~~~~~~~~^~~
+ __emit_expression_range (0, typeid(i * 2));
+ ^~~~~~~~~~~~~
{ dg-end-multiline-output "" } */
}
--
1.8.5.3