From 81d59e2d44ae38ecf94296dba61277140032e821 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 31 Aug 2015 21:36:46 -0400
Subject: [PATCH 63/71] FIXME: Add a bunch of testcases that I think needed
 location-hacks to function

---
 gcc/testsuite/g++.dg/diagnostic/20150303-02.C      | 18 ++++++
 gcc/testsuite/g++.dg/diagnostic/20150303-03.C      | 12 ++++
 gcc/testsuite/g++.dg/diagnostic/20150304-02.C      | 23 ++++++++
 gcc/testsuite/g++.dg/diagnostic/20150324-01.C      | 14 +++++
 .../g++.dg/diagnostic/multiline-rich-location-01.C | 21 +++++++
 .../g++.dg/diagnostic/multiline-rich-location-02.C | 64 ++++++++++++++++++++++
 .../g++.dg/diagnostic/multiline-rich-location-03.C | 34 ++++++++++++
 .../pr52952-mismatching-argument-type-ucn-4.C      | 17 ++++++
 .../pr52952-mismatching-argument-type-ucn-8.C      | 17 ++++++
 gcc/testsuite/gcc.dg/20150303-01.c                 | 24 ++++++++
 gcc/testsuite/gcc.dg/20150303-04.c                 | 16 ++++++
 gcc/testsuite/gcc.dg/20150304-01.c                 | 24 ++++++++
 gcc/testsuite/gcc.dg/cpp-divbyzero.c               | 18 ++++++
 13 files changed, 302 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/20150303-02.C
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/20150303-03.C
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/20150304-02.C
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/20150324-01.C
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/multiline-rich-location-01.C
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/multiline-rich-location-02.C
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/multiline-rich-location-03.C
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/pr52952-mismatching-argument-type-ucn-4.C
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/pr52952-mismatching-argument-type-ucn-8.C
 create mode 100644 gcc/testsuite/gcc.dg/20150303-01.c
 create mode 100644 gcc/testsuite/gcc.dg/20150303-04.c
 create mode 100644 gcc/testsuite/gcc.dg/20150304-01.c
 create mode 100644 gcc/testsuite/gcc.dg/cpp-divbyzero.c

diff --git a/gcc/testsuite/g++.dg/diagnostic/20150303-02.C b/gcc/testsuite/g++.dg/diagnostic/20150303-02.C
new file mode 100644
index 0000000..9df5365
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/20150303-02.C
@@ -0,0 +1,18 @@
+// Adapted from https://gcc.gnu.org/wiki/ClangDiagnosticsComparison
+// { dg-options "-fdiagnostics-show-caret" }
+
+struct a {
+  virtual int bar();
+};
+
+struct foo : public virtual a {
+};
+
+int test(foo *P) {
+  return P->bar() + *P; // { dg-error "no match" }
+}
+
+/* { dg-begin-multiline-output "" }
+   return P->bar() + *P;
+          ~~~~~~~~ ^ ~~
+   { dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/g++.dg/diagnostic/20150303-03.C b/gcc/testsuite/g++.dg/diagnostic/20150303-03.C
new file mode 100644
index 0000000..472c674
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/20150303-03.C
@@ -0,0 +1,12 @@
+// Adapted from https://gcc.gnu.org/wiki/ClangDiagnosticsComparison
+// { dg-options "-fdiagnostics-show-caret" }
+
+void test(int *P) {
+  return *P + *P; // { dg-error "return-statement with a value" }
+}
+
+/*
+{ dg-begin-multiline-output "" }
+   return *P + *P;
+          ~~~~~~^
+{ dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/g++.dg/diagnostic/20150304-02.C b/gcc/testsuite/g++.dg/diagnostic/20150304-02.C
new file mode 100644
index 0000000..549de0b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/20150304-02.C
@@ -0,0 +1,23 @@
+// Adapted from https://gcc.gnu.org/wiki/ClangDiagnosticsComparison
+// { dg-options "-fdiagnostics-show-caret" }
+
+template<class T> void f(typename T::type) { } // { dg-message "candidate: template<class T> void f\\(typename T::type\\)|no type named 'type' in 'struct A'" }
+
+struct A { };
+void g()
+{
+   A a;
+   f<A>(a); // { dg-error "no matching function for call to 'f\\(A&\\)'" }
+}
+
+/*
+{ dg-begin-multiline-output "" }
+    f<A>(a);
+    ~~~~  ^
+{ dg-end-multiline-output "" }
+
+{ dg-begin-multiline-output "" }
+ template<class T> void f(typename T::type) { }
+                        ^
+{ dg-end-multiline-output "" }
+*/
diff --git a/gcc/testsuite/g++.dg/diagnostic/20150324-01.C b/gcc/testsuite/g++.dg/diagnostic/20150324-01.C
new file mode 100644
index 0000000..85ac27f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/20150324-01.C
@@ -0,0 +1,14 @@
+// Adapted from https://gcc.gnu.org/wiki/ClangDiagnosticsComparison
+// Example of range information that's on the same line as the caret
+// { dg-options "-fdump-location-details" }
+
+struct a {
+  virtual int bar();
+};
+
+struct foo : public virtual a {
+};
+
+int test(foo *P) {
+  return P->bar() + *P; // { dg-error "19:type 'int'@c10-c17:type 'foo'@c21-c22: no match " }
+}
diff --git a/gcc/testsuite/g++.dg/diagnostic/multiline-rich-location-01.C b/gcc/testsuite/g++.dg/diagnostic/multiline-rich-location-01.C
new file mode 100644
index 0000000..0a5a193
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/multiline-rich-location-01.C
@@ -0,0 +1,21 @@
+// Verify that we can print range information that spans
+// multiple source lines.
+
+// { dg-options "-fdiagnostics-show-caret" }
+
+struct s {};
+extern int first_function_with_a_very_long_name ();
+extern s   second_function_with_a_very_long_name ();
+
+int test()
+{
+  return (first_function_with_a_very_long_name ()
+          + second_function_with_a_very_long_name ()); // { dg-error "no match" }
+}
+
+/* { dg-begin-multiline-output "" }
+   return (first_function_with_a_very_long_name ()|
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+type 'int'
+           + second_function_with_a_very_long_name ());                           |
+           ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                             +type 's'
+   { dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/g++.dg/diagnostic/multiline-rich-location-02.C b/gcc/testsuite/g++.dg/diagnostic/multiline-rich-location-02.C
new file mode 100644
index 0000000..c1577d4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/multiline-rich-location-02.C
@@ -0,0 +1,64 @@
+// Verify that we can print range information that spans
+// multiple source lines, where the ranges themselves
+// are multiline
+
+// { dg-options "-fdiagnostics-show-caret" }
+
+struct s {};
+extern int first_function_with_a_very_long_name
+  (int lorem, int ipsum, int dolor, int sit, int amet, int consectetur,
+   int adipiscing, int elit, int sed, int eiusmod, int tempor,
+   int incididunt, int ut, int labore, int et, int dolore, int magna,
+   int aliqua);
+extern s second_function_with_a_very_long_name
+  (int lorem, int ipsum, int dolor, int sit, int amet, int consectetur,
+   int adipiscing, int elit, int sed, int eiusmod, int tempor,
+   int incididunt, int ut, int labore, int et, int dolore, int magna,
+   int aliqua);
+
+int test (int lorem, int ipsum, int dolor, int sit, int amet, int consectetur,
+          int adipiscing, int elit, int sed, int eiusmod, int tempor,
+          int incididunt, int ut, int labore, int et, int dolore, int magna,
+          int aliqua)
+{
+  /* The next line deliberately contains trailing whitespace.  */
+  return (first_function_with_a_very_long_name (lorem, ipsum, dolor, sit, amet,       
+                                                consectetur, adipiscing, elit,
+                                                sed, eiusmod, tempor,
+                                                incididunt, ut, labore, et,
+                                                dolore, magna, aliqua)
+          + second_function_with_a_very_long_name (lorem, ipsum, dolor, sit, // { dg-error "no match" }
+                                                   amet, consectetur,
+                                                   adipiscing, elit, sed,
+                                                   eiusmod, tempor, incididunt,
+                                                   ut, labore, et, dolore,
+                                                   magna, aliqua));
+}
+
+/* Note that the carets under the first line of the RHS of the expression
+   appear longer than they should: the quotes source line contains a dg
+   directive, which we can't quote in full.  The carets underline it.
+{ dg-begin-multiline-output "" }
+   return (first_function_with_a_very_long_name (lorem, ipsum, dolor, sit, amet,|
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
+                                                 consectetur, adipiscing, elit, |
+                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+                                                 sed, eiusmod, tempor,          |
+                                                 ~~~~~~~~~~~~~~~~~~~~~          +type 'int'
+                                                 incididunt, ut, labore, et,    |
+                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~    |
+                                                 dolore, magna, aliqua)         |
+                                                 ~~~~~~~~~~~~~~~~~~~~~~         |
+           + second_function_with_a_very_long_name (lorem, ipsum, dolor, sit,                           |
+           ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
+                                                    amet, consectetur,                                  |
+                                                    ~~~~~~~~~~~~~~~~~~                                  |
+                                                    adipiscing, elit, sed,                              |
+                                                    ~~~~~~~~~~~~~~~~~~~~~~                              +type 's'
+                                                    eiusmod, tempor, incididunt,                        |
+                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~                        |
+                                                    ut, labore, et, dolore,                             |
+                                                    ~~~~~~~~~~~~~~~~~~~~~~~                             |
+                                                    magna, aliqua));                                    |
+                                                    ~~~~~~~~~~~~~~                                      |
+{ dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/g++.dg/diagnostic/multiline-rich-location-03.C b/gcc/testsuite/g++.dg/diagnostic/multiline-rich-location-03.C
new file mode 100644
index 0000000..57f8c2e7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/multiline-rich-location-03.C
@@ -0,0 +1,34 @@
+/* Verify -fdump-location-details, with multiple ranges spanning multiple lines, with captions */
+
+// { dg-options "-fdump-location-details" }
+
+struct s {};
+extern int first_function_with_a_very_long_name
+  (int lorem, int ipsum, int dolor, int sit, int amet, int consectetur,
+   int adipiscing, int elit, int sed, int eiusmod, int tempor,
+   int incididunt, int ut, int labore, int et, int dolore, int magna,
+   int aliqua);
+extern s second_function_with_a_very_long_name
+  (int lorem, int ipsum, int dolor, int sit, int amet, int consectetur,
+   int adipiscing, int elit, int sed, int eiusmod, int tempor,
+   int incididunt, int ut, int labore, int et, int dolore, int magna,
+   int aliqua);
+
+int test (int lorem, int ipsum, int dolor, int sit, int amet, int consectetur,
+          int adipiscing, int elit, int sed, int eiusmod, int tempor,
+          int incididunt, int ut, int labore, int et, int dolore, int magna,
+          int aliqua)
+{
+  /* The next line deliberately contains trailing whitespace.  */
+  return (first_function_with_a_very_long_name (lorem, ipsum, dolor, sit, amet,
+                                                consectetur, adipiscing, elit,
+                                                sed, eiusmod, tempor,
+                                                incididunt, ut, labore, et,
+                                                dolore, magna, aliqua)
+          + second_function_with_a_very_long_name (lorem, ipsum, dolor, sit, // { dg-error "11:type 'int'@r23c11-r27c70:type 's'@r28c13-r33c65: no match " }
+                                                   amet, consectetur,
+                                                   adipiscing, elit, sed,
+                                                   eiusmod, tempor, incididunt,
+                                                   ut, labore, et, dolore,
+                                                   magna, aliqua));
+}
diff --git a/gcc/testsuite/g++.dg/diagnostic/pr52952-mismatching-argument-type-ucn-4.C b/gcc/testsuite/g++.dg/diagnostic/pr52952-mismatching-argument-type-ucn-4.C
new file mode 100644
index 0000000..3aadd51
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/pr52952-mismatching-argument-type-ucn-4.C
@@ -0,0 +1,17 @@
+/* { dg-options "-Wformat -fdiagnostics-show-caret" } */
+
+#include <stdio.h>
+
+void foo (const char *msg)
+{
+  /* "%" is U+0025
+     "i" is U+0069 */
+  printf("hello \u0025\u0069", msg);  /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'const char\\*' " } */
+}
+
+/*
+{ dg-begin-multiline-output "" }
+   printf("hello \u0025\u0069", msg);
+                 ^~~~~~~~~~~~
+{ dg-end-multiline-output "" }
+*/
diff --git a/gcc/testsuite/g++.dg/diagnostic/pr52952-mismatching-argument-type-ucn-8.C b/gcc/testsuite/g++.dg/diagnostic/pr52952-mismatching-argument-type-ucn-8.C
new file mode 100644
index 0000000..df903be
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/pr52952-mismatching-argument-type-ucn-8.C
@@ -0,0 +1,17 @@
+/* { dg-options "-Wformat -fdiagnostics-show-caret" } */
+
+#include <stdio.h>
+
+void foo (const char *msg)
+{
+  /* "%" is U+0025
+     "i" is U+0069 */
+  printf("hello \U00000025\U00000069", msg);  /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'const char\\*' " } */
+}
+
+/*
+{ dg-begin-multiline-output "" }
+   printf("hello \U00000025\U00000069", msg);
+                 ^~~~~~~~~~~~~~~~~~~~
+{ dg-end-multiline-output "" }
+*/
diff --git a/gcc/testsuite/gcc.dg/20150303-01.c b/gcc/testsuite/gcc.dg/20150303-01.c
new file mode 100644
index 0000000..a286ebf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/20150303-01.c
@@ -0,0 +1,24 @@
+/* Adapted from https://gcc.gnu.org/wiki/ClangDiagnosticsComparison */
+/* { dg-options "-fdiagnostics-show-caret" } */
+
+void foo(char **argP, char **argQ)
+{
+  (argP - argQ)(); /* { dg-error "called object is not a function or function pointer" } */
+  argP();       /* { dg-error "called object 'argP' is not a function or function pointer" } */
+}
+
+/*
+{ dg-begin-multiline-output "" }
+   (argP - argQ)();
+   ^~~~~~~~~~~~~
+{ dg-end-multiline-output "" }
+
+{ dg-begin-multiline-output "" }
+   argP();
+   ^~~~
+{ dg-end-multiline-output "" }
+
+{ dg-begin-multiline-output "" }
+ void foo(char **argP, char **argQ)
+                 ^~~~
+{ dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/gcc.dg/20150303-04.c b/gcc/testsuite/gcc.dg/20150303-04.c
new file mode 100644
index 0000000..75f3a35
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/20150303-04.c
@@ -0,0 +1,16 @@
+/* Adapted from https://gcc.gnu.org/wiki/ClangDiagnosticsComparison */
+/* { dg-options "-fdiagnostics-show-caret" } */
+
+typedef float __m128 __attribute__ ((vector_size (32)));
+void f()
+{
+  __m128 myvec[2];
+  int const *P;
+  myvec[1]/P; /* { dg-error "invalid operands to binary /" } */
+}
+
+/*
+{ dg-begin-multiline-output "" }
+   myvec[1]/P;
+   ~~~~~~~~^~
+{ dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/gcc.dg/20150304-01.c b/gcc/testsuite/gcc.dg/20150304-01.c
new file mode 100644
index 0000000..755d284
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/20150304-01.c
@@ -0,0 +1,24 @@
+/* Adapted from https://gcc.gnu.org/wiki/ClangDiagnosticsComparison */
+/* { dg-options "-fdiagnostics-show-caret" } */
+
+#define MYMAX(A,B)    __extension__ ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; }) /* { dg-error "invalid operands to binary < \\(have 'struct mystruct' and 'float'\\)" } */
+
+struct mystruct { int i; };
+void f() {
+  int X;
+  float F;
+  struct mystruct P;
+  X = MYMAX(P, F);  /* { dg-message "in expansion of macro 'MYMAX'" } */
+}
+
+/*
+{ dg-begin-multiline-output "" }
+ #define MYMAX(A,B)    __extension__ ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
+                                                                                          ~~~ ^ ~~~
+{ dg-end-multiline-output "" }
+
+{ dg-begin-multiline-output "" }
+   X = MYMAX(P, F);
+       ^~~~~~~~~~~
+{ dg-end-multiline-output "" }
+*/
diff --git a/gcc/testsuite/gcc.dg/cpp-divbyzero.c b/gcc/testsuite/gcc.dg/cpp-divbyzero.c
new file mode 100644
index 0000000..ef3b01e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp-divbyzero.c
@@ -0,0 +1,18 @@
+#if 1 / 0  /* { dg-error "division by zero in #if" } */
+#endif
+
+
+#if 2 / (2 - 2) /* { dg-error "division by zero in #if" } */
+#endif
+
+
+#define ZERO 0
+#if 3 / ZERO /* { dg-error "division by zero in #if" } */
+#endif
+
+#undef ZERO
+#define ZERO (4 - 4) /* { dg-error "division by zero in #if" } */
+#if 4 / ZERO  /* { dg-message "note: in expansion of macro 'ZERO'" } */
+#endif
+
+int make_tu_non_empty;
-- 
1.8.5.3

