[v3,04/11] Add tests for validating future C permerrors

Message ID 39c669e5eb8d904ce59ad18f3cd0368959ec067b.1700473918.git.fweimer@redhat.com
State Accepted
Headers
Series : More warnings as errors by default |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Florian Weimer Nov. 20, 2023, 9:56 a.m. UTC
  The dg-error directives for gcc.dg/permerror-system.c can be generated
using (for the most part at least):

perl -ne 'print if s,.*(/\* \{ dg-error .*) } \*/$,$1 "" { target *-*-* } $. } */,' \
  < gcc/testsuite/gcc.dg/permerror-default.c

gcc/testsuite/

	* gcc.dg/permerror-default.c: New test.
	* gcc.dg/permerror-fpermissive.c: Likewise.
	* gcc.dg/permerror-fpermissive-nowarning.c: Likewise.
	* gcc.dg/permerror-gnu89-nopermissive.c: Likewise.
	No permerrors yet, so this matches gcc.dg/permerror-gnu89.c
	for now.
	* gcc.dg/permerror-gnu89-pedantic.c: New test.
	* gcc.dg/permerror-gnu89.c: Likewise.
	* gcc.dg/permerror-noerror.c: Likewise.
	* gcc.dg/permerror-nowarning.c: Likewise.
	* gcc.dg/permerror-pedantic.c: Likewise.
	* gcc.dg/permerror-system.c: Likewise.
---
 gcc/testsuite/gcc.dg/permerror-default.c      | 85 +++++++++++++++++++
 .../gcc.dg/permerror-fpermissive-nowarning.c  | 11 +++
 gcc/testsuite/gcc.dg/permerror-fpermissive.c  | 85 +++++++++++++++++++
 .../gcc.dg/permerror-gnu89-nopermissive.c     | 85 +++++++++++++++++++
 .../gcc.dg/permerror-gnu89-pedantic.c         | 85 +++++++++++++++++++
 gcc/testsuite/gcc.dg/permerror-gnu89.c        | 85 +++++++++++++++++++
 gcc/testsuite/gcc.dg/permerror-noerror.c      | 85 +++++++++++++++++++
 gcc/testsuite/gcc.dg/permerror-nowarning.c    | 10 +++
 gcc/testsuite/gcc.dg/permerror-pedantic.c     | 85 +++++++++++++++++++
 gcc/testsuite/gcc.dg/permerror-system.c       |  9 ++
 10 files changed, 625 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/permerror-default.c
 create mode 100644 gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c
 create mode 100644 gcc/testsuite/gcc.dg/permerror-fpermissive.c
 create mode 100644 gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c
 create mode 100644 gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c
 create mode 100644 gcc/testsuite/gcc.dg/permerror-gnu89.c
 create mode 100644 gcc/testsuite/gcc.dg/permerror-noerror.c
 create mode 100644 gcc/testsuite/gcc.dg/permerror-nowarning.c
 create mode 100644 gcc/testsuite/gcc.dg/permerror-pedantic.c
 create mode 100644 gcc/testsuite/gcc.dg/permerror-system.c
  

Comments

Marek Polacek Nov. 30, 2023, 5:31 p.m. UTC | #1
On Mon, Nov 20, 2023 at 10:56:03AM +0100, Florian Weimer wrote:
> The dg-error directives for gcc.dg/permerror-system.c can be generated
> using (for the most part at least):
> 
> perl -ne 'print if s,.*(/\* \{ dg-error .*) } \*/$,$1 "" { target *-*-* } $. } */,' \
>   < gcc/testsuite/gcc.dg/permerror-default.c
> 
> gcc/testsuite/
> 
> 	* gcc.dg/permerror-default.c: New test.
> 	* gcc.dg/permerror-fpermissive.c: Likewise.
> 	* gcc.dg/permerror-fpermissive-nowarning.c: Likewise.
> 	* gcc.dg/permerror-gnu89-nopermissive.c: Likewise.
> 	No permerrors yet, so this matches gcc.dg/permerror-gnu89.c
> 	for now.
> 	* gcc.dg/permerror-gnu89-pedantic.c: New test.
> 	* gcc.dg/permerror-gnu89.c: Likewise.
> 	* gcc.dg/permerror-noerror.c: Likewise.
> 	* gcc.dg/permerror-nowarning.c: Likewise.
> 	* gcc.dg/permerror-pedantic.c: Likewise.
> 	* gcc.dg/permerror-system.c: Likewise.
> ---
>  gcc/testsuite/gcc.dg/permerror-default.c      | 85 +++++++++++++++++++
>  .../gcc.dg/permerror-fpermissive-nowarning.c  | 11 +++
>  gcc/testsuite/gcc.dg/permerror-fpermissive.c  | 85 +++++++++++++++++++
>  .../gcc.dg/permerror-gnu89-nopermissive.c     | 85 +++++++++++++++++++
>  .../gcc.dg/permerror-gnu89-pedantic.c         | 85 +++++++++++++++++++
>  gcc/testsuite/gcc.dg/permerror-gnu89.c        | 85 +++++++++++++++++++
>  gcc/testsuite/gcc.dg/permerror-noerror.c      | 85 +++++++++++++++++++
>  gcc/testsuite/gcc.dg/permerror-nowarning.c    | 10 +++
>  gcc/testsuite/gcc.dg/permerror-pedantic.c     | 85 +++++++++++++++++++
>  gcc/testsuite/gcc.dg/permerror-system.c       |  9 ++
>  10 files changed, 625 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/permerror-default.c
>  create mode 100644 gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c
>  create mode 100644 gcc/testsuite/gcc.dg/permerror-fpermissive.c
>  create mode 100644 gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c
>  create mode 100644 gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c
>  create mode 100644 gcc/testsuite/gcc.dg/permerror-gnu89.c
>  create mode 100644 gcc/testsuite/gcc.dg/permerror-noerror.c
>  create mode 100644 gcc/testsuite/gcc.dg/permerror-nowarning.c
>  create mode 100644 gcc/testsuite/gcc.dg/permerror-pedantic.c
>  create mode 100644 gcc/testsuite/gcc.dg/permerror-system.c
> 
> diff --git a/gcc/testsuite/gcc.dg/permerror-default.c b/gcc/testsuite/gcc.dg/permerror-default.c
> new file mode 100644
> index 00000000000..ea0be1dc89f
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/permerror-default.c
> @@ -0,0 +1,85 @@
> +/* { dg-options "" } */
> +
> +/* Overview test for C permerrors.  This test should be kept in sync with the
> +   other permerror-* tests.  If new permerrors are added, test cases should be
> +   added to this and the other files.  */
> +
> +void
> +implicit_function_declaration (void)
> +{
> +  f1 (); /* { dg-warning "'f1' \\\[-Wimplicit-function-declaration\\\]" } */
> +}
> +
> +extern implicit_int_1; /* { dg-warning "'implicit_int_1' \\\[-Wimplicit-int\\\]" } */

Oy, these \ tend to get unwieldy.  You could probably just say
{ dg-warning {-Wimplicit-int} }

> +    return incompatible_pointer_types; /* { dg-error "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */

And here maybe
{ dg-error {returning 'int \* \(\*\)\(int\)' from a function with incompatible return type 'int \*' \[-Wincompatible-pointer-types\]} }
could work the same.  But you don't have to go and change it; I don't
want to make more work for you.

> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/permerror-system.c
> @@ -0,0 +1,9 @@
> +/* { dg-options "-isystem ${srcdir}" } */
> +
> +/* Test that permerrors appear in system headers.  */
> +
> +/* The dg-* directives in the header file are ignored.  No warnings are
> +   expected.  */
> +#include <gcc.dg/permerror-default.c>

Why not just #include "permerror-default.c"?

I think this patch is OK.

Marek
  
Florian Weimer Nov. 30, 2023, 5:37 p.m. UTC | #2
* Marek Polacek:

>> +void
>> +implicit_function_declaration (void)
>> +{
>> +  f1 (); /* { dg-warning "'f1' \\\[-Wimplicit-function-declaration\\\]" } */
>> +}
>> +
>> +extern implicit_int_1; /* { dg-warning "'implicit_int_1' \\\[-Wimplicit-int\\\]" } */
>
> Oy, these \ tend to get unwieldy.  You could probably just say
> { dg-warning {-Wimplicit-int} }

I wanted to have some more context for the other files that might get
the explict line number wrong.

>> +    return incompatible_pointer_types; /* { dg-error "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
>
> And here maybe
> { dg-error {returning 'int \* \(\*\)\(int\)' from a function with incompatible return type 'int \*' \[-Wincompatible-pointer-types\]} }
> could work the same.  But you don't have to go and change it; I don't
> want to make more work for you.

Oh, I'm not too familiar with Tcl.  I haven't seen single quotes being
used elsewhere.  I prefer not to change it unless there is another
reason to rework all this.  So … let's wait?

>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.dg/permerror-system.c
>> @@ -0,0 +1,9 @@
>> +/* { dg-options "-isystem ${srcdir}" } */
>> +
>> +/* Test that permerrors appear in system headers.  */
>> +
>> +/* The dg-* directives in the header file are ignored.  No warnings are
>> +   expected.  */
>> +#include <gcc.dg/permerror-default.c>
>
> Why not just #include "permerror-default.c"?

I wanted to make sure that the file is found through the -isystem path.

Thanks,
Florian
  
Marek Polacek Nov. 30, 2023, 5:39 p.m. UTC | #3
On Thu, Nov 30, 2023 at 06:37:21PM +0100, Florian Weimer wrote:
> * Marek Polacek:
> 
> >> +void
> >> +implicit_function_declaration (void)
> >> +{
> >> +  f1 (); /* { dg-warning "'f1' \\\[-Wimplicit-function-declaration\\\]" } */
> >> +}
> >> +
> >> +extern implicit_int_1; /* { dg-warning "'implicit_int_1' \\\[-Wimplicit-int\\\]" } */
> >
> > Oy, these \ tend to get unwieldy.  You could probably just say
> > { dg-warning {-Wimplicit-int} }
> 
> I wanted to have some more context for the other files that might get
> the explict line number wrong.
> 
> >> +    return incompatible_pointer_types; /* { dg-error "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
> >
> > And here maybe
> > { dg-error {returning 'int \* \(\*\)\(int\)' from a function with incompatible return type 'int \*' \[-Wincompatible-pointer-types\]} }
> > could work the same.  But you don't have to go and change it; I don't
> > want to make more work for you.
> 
> Oh, I'm not too familiar with Tcl.  I haven't seen single quotes being
> used elsewhere.  I prefer not to change it unless there is another
> reason to rework all this.  So … let's wait?

Sure.
 
> >> --- /dev/null
> >> +++ b/gcc/testsuite/gcc.dg/permerror-system.c
> >> @@ -0,0 +1,9 @@
> >> +/* { dg-options "-isystem ${srcdir}" } */
> >> +
> >> +/* Test that permerrors appear in system headers.  */
> >> +
> >> +/* The dg-* directives in the header file are ignored.  No warnings are
> >> +   expected.  */
> >> +#include <gcc.dg/permerror-default.c>
> >
> > Why not just #include "permerror-default.c"?
> 
> I wanted to make sure that the file is found through the -isystem path.

Aha, okay then.

Marek
  
Jakub Jelinek Nov. 30, 2023, 6:25 p.m. UTC | #4
On Thu, Nov 30, 2023 at 12:39:22PM -0500, Marek Polacek wrote:
> On Thu, Nov 30, 2023 at 06:37:21PM +0100, Florian Weimer wrote:
> > * Marek Polacek:
> > 
> > >> +void
> > >> +implicit_function_declaration (void)
> > >> +{
> > >> +  f1 (); /* { dg-warning "'f1' \\\[-Wimplicit-function-declaration\\\]" } */
> > >> +}
> > >> +
> > >> +extern implicit_int_1; /* { dg-warning "'implicit_int_1' \\\[-Wimplicit-int\\\]" } */
> > >
> > > Oy, these \ tend to get unwieldy.  You could probably just say
> > > { dg-warning {-Wimplicit-int} }
> > 
> > I wanted to have some more context for the other files that might get
> > the explict line number wrong.
> > 
> > >> +    return incompatible_pointer_types; /* { dg-error "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
> > >
> > > And here maybe
> > > { dg-error {returning 'int \* \(\*\)\(int\)' from a function with incompatible return type 'int \*' \[-Wincompatible-pointer-types\]} }
> > > could work the same.  But you don't have to go and change it; I don't
> > > want to make more work for you.
> > 
> > Oh, I'm not too familiar with Tcl.  I haven't seen single quotes being
> > used elsewhere.  I prefer not to change it unless there is another
> > reason to rework all this.  So … let's wait?
> 
> Sure.

Note, I think \\\s are used in thousands of dg-error/dg-warning etc.
in other tests already, I think it isn't a big deal.
find testsuite -type f | xargs grep 'dg-\(warning\|error\|message\).*".*\\\\\\' | wc -l
4782
Sure, with using {} instead of "" one can get rid of some of the \s.

	Jakub
  

Patch

diff --git a/gcc/testsuite/gcc.dg/permerror-default.c b/gcc/testsuite/gcc.dg/permerror-default.c
new file mode 100644
index 00000000000..ea0be1dc89f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/permerror-default.c
@@ -0,0 +1,85 @@ 
+/* { dg-options "" } */
+
+/* Overview test for C permerrors.  This test should be kept in sync with the
+   other permerror-* tests.  If new permerrors are added, test cases should be
+   added to this and the other files.  */
+
+void
+implicit_function_declaration (void)
+{
+  f1 (); /* { dg-warning "'f1' \\\[-Wimplicit-function-declaration\\\]" } */
+}
+
+extern implicit_int_1; /* { dg-warning "'implicit_int_1' \\\[-Wimplicit-int\\\]" } */
+typedef implicit_int_2; /* { dg-warning "'implicit_int_2' \\\[-Wimplicit-int\\\]" } */
+extern implicit_int_3 (void); /* { dg-warning "'implicit_int_3' \\\[-Wimplicit-int\\]" } */
+implicit_int_4 (i) /* { dg-warning "return type defaults to 'int' \\\[-Wimplicit-int\\\]" } */
+/* { dg-warning "type of 'i' defaults to 'int' \\\[-Wimplicit-int\\\]" "" { target *-*-*} .-1 } */
+{
+  (const) 0; /* { dg-warning "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
+}
+
+extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
+
+
+int *
+int_conversion_1 (int flag)
+{
+  void f2 (int *);
+  flag ? "1" : 1; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */
+  flag ? 1 : "1"; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */
+  f2 (flag); /* { dg-warning "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+  {
+    int i1 = &flag; /* { dg-warning "initialization of 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+    i1 = &flag; /* { dg-warning "assignment to 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+  }
+  return flag; /* { dg-warning "returning 'int' from a function with return type 'int \\\*' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+}
+
+int
+int_conversion_2 (int flag)
+{
+  void f3 (int);
+  f3 (&flag); /* { dg-warning "passing argument 1 of 'f3' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+  {
+    int *i1 = flag; /* { dg-warning "initialization of 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+    i1 = flag; /* { dg-warning "assignment to 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+  }
+  return &flag; /* { dg-warning "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+}
+
+int *
+incompatible_pointer_types (int flag)
+{
+  void f4 (int *);
+  flag ? __builtin_abs : __builtin_labs; /* { dg-warning "pointer type mismatch in conditional expression \\\[-Wincompatible-pointer-types\\\]" } */
+  {
+    int *p1 = __builtin_abs; /* { dg-warning "initialization of 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    p1 = __builtin_abs; /* { dg-warning "assignment to 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+  }
+  {
+    int *p2 = incompatible_pointer_types; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    p2 = incompatible_pointer_types; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    {
+      int *p3 = &p2; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+      p3 = &p2; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+    }
+    f4 (&p2); /* { dg-warning "passing argument 1 of 'f4' from incompatible pointer type \\\[-Wincompatible-pointer-types\\\]" } */
+  }
+  if (flag)
+    return __builtin_abs; /* { dg-warning "returning pointer to '__builtin_abs' of type 'int \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+  else
+    return incompatible_pointer_types; /* { dg-warning "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+}
+
+void
+return_mismatch_1 (void)
+{
+  return 0; /* { dg-warning "'return' with a value, in function returning void \\\[-Wreturn-mismatch\\\]" } */
+}
+
+int
+return_mismatch_2 (void)
+{
+  return; /* { dg-warning "return' with no value, in function returning non-void \\\[-Wreturn-mismatch\\\]" } */
+}
diff --git a/gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c b/gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c
new file mode 100644
index 00000000000..f15b21ef43d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/permerror-fpermissive-nowarning.c
@@ -0,0 +1,11 @@ 
+/* { dg-options "-fpermissive -Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch" } */
+
+/* This test checks that permerrors can be disabled using -Wno-* options even
+   if -fpermissive is used.  */
+
+#include "permerror-default.c"
+
+/* Ideally, we do not want to see any warnings here, but this warning is not
+   yet controlled by its own option.  */
+
+/* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" "" { target *-*-* } 22 } */
diff --git a/gcc/testsuite/gcc.dg/permerror-fpermissive.c b/gcc/testsuite/gcc.dg/permerror-fpermissive.c
new file mode 100644
index 00000000000..139f35ad1c0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/permerror-fpermissive.c
@@ -0,0 +1,85 @@ 
+/* { dg-options "-fpermissive" } */
+
+/* Overview test for C permerrors.  This test should be kept in sync with the
+   other permerror-* tests.  If new permerrors are added, test cases should be
+   added to this and the other files.  */
+
+void
+implicit_function_declaration (void)
+{
+  f1 (); /* { dg-warning "'f1' \\\[-Wimplicit-function-declaration\\\]" } */
+}
+
+extern implicit_int_1; /* { dg-warning "'implicit_int_1' \\\[-Wimplicit-int\\\]" } */
+typedef implicit_int_2; /* { dg-warning "'implicit_int_2' \\\[-Wimplicit-int\\\]" } */
+extern implicit_int_3 (void); /* { dg-warning "'implicit_int_3' \\\[-Wimplicit-int\\]" } */
+implicit_int_4 (i) /* { dg-warning "return type defaults to 'int' \\\[-Wimplicit-int\\\]" } */
+/* { dg-warning "type of 'i' defaults to 'int' \\\[-Wimplicit-int\\\]" "" { target *-*-*} .-1 } */
+{
+  (const) 0; /* { dg-warning "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
+}
+
+extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
+
+
+int *
+int_conversion_1 (int flag)
+{
+  void f2 (int *);
+  flag ? "1" : 1; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */
+  flag ? 1 : "1"; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */
+  f2 (flag); /* { dg-warning "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+  {
+    int i1 = &flag; /* { dg-warning "initialization of 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+    i1 = &flag; /* { dg-warning "assignment to 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+  }
+  return flag; /* { dg-warning "returning 'int' from a function with return type 'int \\\*' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+}
+
+int
+int_conversion_2 (int flag)
+{
+  void f3 (int);
+  f3 (&flag); /* { dg-warning "passing argument 1 of 'f3' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+  {
+    int *i1 = flag; /* { dg-warning "initialization of 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+    i1 = flag; /* { dg-warning "assignment to 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+  }
+  return &flag; /* { dg-warning "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+}
+
+int *
+incompatible_pointer_types (int flag)
+{
+  void f4 (int *);
+  flag ? __builtin_abs : __builtin_labs; /* { dg-warning "pointer type mismatch in conditional expression \\\[-Wincompatible-pointer-types\\\]" } */
+  {
+    int *p1 = __builtin_abs; /* { dg-warning "initialization of 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    p1 = __builtin_abs; /* { dg-warning "assignment to 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+  }
+  {
+    int *p2 = incompatible_pointer_types; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    p2 = incompatible_pointer_types; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    {
+      int *p3 = &p2; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+      p3 = &p2; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+    }
+    f4 (&p2); /* { dg-warning "passing argument 1 of 'f4' from incompatible pointer type \\\[-Wincompatible-pointer-types\\\]" } */
+  }
+  if (flag)
+    return __builtin_abs; /* { dg-warning "returning pointer to '__builtin_abs' of type 'int \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+  else
+    return incompatible_pointer_types; /* { dg-warning "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+}
+
+void
+return_mismatch_1 (void)
+{
+  return 0; /* { dg-warning "'return' with a value, in function returning void \\\[-Wreturn-mismatch\\\]" } */
+}
+
+int
+return_mismatch_2 (void)
+{
+  return; /* { dg-warning "return' with no value, in function returning non-void \\\[-Wreturn-mismatch\\\]" } */
+}
diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c b/gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c
new file mode 100644
index 00000000000..6d42bc61d5c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/permerror-gnu89-nopermissive.c
@@ -0,0 +1,85 @@ 
+/* { dg-options "-std=gnu89 -fno-permissive" } */
+
+/* Test for C89 dialect mode, with new permerrors enabled.  In most
+   cases where the compiler warnings in C89 mode, it should issue a
+   permerror with -fno-permissive.  */
+
+void
+implicit_function_declaration (void)
+{
+  f1 (); /* { dg-bogus "-Wimplicit-function-declaration" } */
+}
+
+extern implicit_int_1; /* { dg-bogus "-Wimplicit-int" } */
+typedef implicit_int_2; /* { dg-bogus "-Wimplicit-int" } */
+extern implicit_int_3 (void); /* { dg-bogus "-Wimplicit-int" } */
+implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */
+/* Directive here in the other files.  */
+{
+  (const) 0; /* { dg-bogus "-Wimplicit-int" } */
+}
+
+extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
+
+
+int *
+int_conversion_1 (int flag)
+{
+  void f2 (int *);
+  flag ? "1" : 1; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */
+  flag ? 1 : "1"; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */
+  f2 (flag); /* { dg-warning "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+  {
+    int i1 = &flag; /* { dg-warning "initialization of 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+    i1 = &flag; /* { dg-warning "assignment to 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+  }
+  return flag; /* { dg-warning "returning 'int' from a function with return type 'int \\\*' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+}
+
+int
+int_conversion_2 (int flag)
+{
+  void f3 (int);
+  f3 (&flag); /* { dg-warning "passing argument 1 of 'f3' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+  {
+    int *i1 = flag; /* { dg-warning "initialization of 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+    i1 = flag; /* { dg-warning "assignment to 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+  }
+  return &flag; /* { dg-warning "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+}
+
+int *
+incompatible_pointer_types (int flag)
+{
+  void f4 (int *);
+  flag ? __builtin_abs : __builtin_labs; /* { dg-warning "pointer type mismatch in conditional expression \\\[-Wincompatible-pointer-types\\\]" } */
+  {
+    int *p1 = __builtin_abs; /* { dg-warning "initialization of 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    p1 = __builtin_abs; /* { dg-warning "assignment to 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+  }
+  {
+    int *p2 = incompatible_pointer_types; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    p2 = incompatible_pointer_types; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    {
+      int *p3 = &p2; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+      p3 = &p2; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+    }
+    f4 (&p2); /* { dg-warning "passing argument 1 of 'f4' from incompatible pointer type \\\[-Wincompatible-pointer-types\\\]" } */
+  }
+  if (flag)
+    return __builtin_abs; /* { dg-warning "returning pointer to '__builtin_abs' of type 'int \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+  else
+    return incompatible_pointer_types; /* { dg-warning "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+}
+
+void
+return_mismatch_1 (void)
+{
+  return 0; /* { dg-warning "'return' with a value, in function returning void \\\[-Wreturn-mismatch\\\]" } */
+}
+
+int
+return_mismatch_2 (void)
+{
+  return; /* { dg-bogus "-Wreturn-mismatch" } */
+}
diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c b/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c
new file mode 100644
index 00000000000..465a16f5f9a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/permerror-gnu89-pedantic.c
@@ -0,0 +1,85 @@ 
+/* { dg-options "-std=gnu89 -pedantic-errors" } */
+
+/* Overview test for C permerrors.  This test should be kept in sync with the
+   other permerror-* tests.  If new permerrors are added, test cases should be
+   added to this and the other files.  */
+
+void
+implicit_function_declaration (void)
+{
+  f1 (); /* { dg-bogus "-Wimplicit-function-declaration" } */
+}
+
+extern implicit_int_1; /* { dg-bogus "-Wimplicit-int" } */
+typedef implicit_int_2; /* { dg-bogus "-Wimplicit-int" } */
+extern implicit_int_3 (void); /* { dg-bogus "-Wimplicit-int" } */
+implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */
+/* Directive here in the other files.  */
+{
+  (const) 0; /* { dg-bogus "-Wimplicit-int" } */
+}
+
+extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration\n" } */
+
+
+int *
+int_conversion_1 (int flag)
+{
+  void f2 (int *);
+  flag ? "1" : 1; /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */
+  flag ? 1 : "1"; /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */
+  f2 (flag); /* { dg-error "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+  {
+    int i1 = &flag; /* { dg-error "initialization of 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+    i1 = &flag; /* { dg-error "assignment to 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+  }
+  return flag; /* { dg-error "returning 'int' from a function with return type 'int \\\*' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+}
+
+int
+int_conversion_2 (int flag)
+{
+  void f3 (int);
+  f3 (&flag); /* { dg-error "passing argument 1 of 'f3' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+  {
+    int *i1 = flag; /* { dg-error "initialization of 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+    i1 = flag; /* { dg-error "assignment to 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+  }
+  return &flag; /* { dg-error "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+}
+
+int *
+incompatible_pointer_types (int flag)
+{
+  void f4 (int *);
+  flag ? __builtin_abs : __builtin_labs; /* { dg-warning "pointer type mismatch in conditional expression \\\[-Wincompatible-pointer-types\\\]" } */
+  {
+    int *p1 = __builtin_abs; /* { dg-error "initialization of 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    p1 = __builtin_abs; /* { dg-error "assignment to 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+  }
+  {
+    int *p2 = incompatible_pointer_types; /* { dg-error "initialization of 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    p2 = incompatible_pointer_types; /* { dg-error "assignment to 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    {
+      int *p3 = &p2; /* { dg-error "initialization of 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+      p3 = &p2; /* { dg-error "assignment to 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+    }
+    f4 (&p2); /* { dg-error "passing argument 1 of 'f4' from incompatible pointer type \\\[-Wincompatible-pointer-types\\\]" } */
+  }
+  if (flag)
+    return __builtin_abs; /* { dg-error "returning pointer to '__builtin_abs' of type 'int \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+  else
+    return incompatible_pointer_types; /* { dg-error "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+}
+
+void
+return_mismatch_1 (void)
+{
+  return 0; /* { dg-error "'return' with a value, in function returning void \\\[-Wreturn-mismatch\\\]" } */
+}
+
+int
+return_mismatch_2 (void)
+{
+  return; /* { dg-bogus "-Wreturn-mismatch" } */
+}
diff --git a/gcc/testsuite/gcc.dg/permerror-gnu89.c b/gcc/testsuite/gcc.dg/permerror-gnu89.c
new file mode 100644
index 00000000000..66f7789269f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/permerror-gnu89.c
@@ -0,0 +1,85 @@ 
+/* { dg-options "-std=gnu89" } */
+
+/* Overview test for C permerrors.  This test should be kept in sync with the
+   other permerror-* tests.  If new permerrors are added, test cases should be
+   added to this and the other files.  */
+
+void
+implicit_function_declaration (void)
+{
+  f1 (); /* { dg-bogus "-Wimplicit-function-declaration" } */
+}
+
+extern implicit_int_1; /* { dg-bogus "-Wimplicit-int" } */
+typedef implicit_int_2; /* { dg-bogus "-Wimplicit-int" } */
+extern implicit_int_3 (void); /* { dg-bogus "-Wimplicit-int" } */
+implicit_int_4 (i) /* { dg-bogus "-Wimplicit-int" } */
+/* Directive here in the other files.  */
+{
+  (const) 0; /* { dg-bogus "-Wimplicit-int" } */
+}
+
+extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
+
+
+int *
+int_conversion_1 (int flag)
+{
+  void f2 (int *);
+  flag ? "1" : 1; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */
+  flag ? 1 : "1"; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */
+  f2 (flag); /* { dg-warning "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+  {
+    int i1 = &flag; /* { dg-warning "initialization of 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+    i1 = &flag; /* { dg-warning "assignment to 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+  }
+  return flag; /* { dg-warning "returning 'int' from a function with return type 'int \\\*' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+}
+
+int
+int_conversion_2 (int flag)
+{
+  void f3 (int);
+  f3 (&flag); /* { dg-warning "passing argument 1 of 'f3' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+  {
+    int *i1 = flag; /* { dg-warning "initialization of 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+    i1 = flag; /* { dg-warning "assignment to 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+  }
+  return &flag; /* { dg-warning "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+}
+
+int *
+incompatible_pointer_types (int flag)
+{
+  void f4 (int *);
+  flag ? __builtin_abs : __builtin_labs; /* { dg-warning "pointer type mismatch in conditional expression \\\[-Wincompatible-pointer-types\\\]" } */
+  {
+    int *p1 = __builtin_abs; /* { dg-warning "initialization of 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    p1 = __builtin_abs; /* { dg-warning "assignment to 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+  }
+  {
+    int *p2 = incompatible_pointer_types; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    p2 = incompatible_pointer_types; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    {
+      int *p3 = &p2; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+      p3 = &p2; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+    }
+    f4 (&p2); /* { dg-warning "passing argument 1 of 'f4' from incompatible pointer type \\\[-Wincompatible-pointer-types\\\]" } */
+  }
+  if (flag)
+    return __builtin_abs; /* { dg-warning "returning pointer to '__builtin_abs' of type 'int \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+  else
+    return incompatible_pointer_types; /* { dg-warning "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+}
+
+void
+return_mismatch_1 (void)
+{
+  return 0; /* { dg-warning "'return' with a value, in function returning void \\\[-Wreturn-mismatch\\\]" } */
+}
+
+int
+return_mismatch_2 (void)
+{
+  return; /* { dg-bogus "-Wreturn-mismatch" } */
+}
diff --git a/gcc/testsuite/gcc.dg/permerror-noerror.c b/gcc/testsuite/gcc.dg/permerror-noerror.c
new file mode 100644
index 00000000000..cd1c2013cb5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/permerror-noerror.c
@@ -0,0 +1,85 @@ 
+/* { dg-options "-Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=int-conversion -Wno-error=incompatible-pointer-types -Wno-error=return-mismatch" } */
+
+/* This test should emulate the effect of -fpermissive by adding all the
+   -Wno-error= options that are implied by -fpermissive.  It needs to be
+   kept in sync with the other permerror-* tests.  */
+
+void
+implicit_function_declaration (void)
+{
+  f1 (); /* { dg-warning "'f1' \\\[-Wimplicit-function-declaration\\\]" } */
+}
+
+extern implicit_int_1; /* { dg-warning "'implicit_int_1' \\\[-Wimplicit-int\\\]" } */
+typedef implicit_int_2; /* { dg-warning "'implicit_int_2' \\\[-Wimplicit-int\\\]" } */
+extern implicit_int_3 (void); /* { dg-warning "'implicit_int_3' \\\[-Wimplicit-int\\]" } */
+implicit_int_4 (i) /* { dg-warning "return type defaults to 'int' \\\[-Wimplicit-int\\\]" } */
+/* { dg-warning "type of 'i' defaults to 'int' \\\[-Wimplicit-int\\\]" "" { target *-*-*} .-1 } */
+{
+  (const) 0; /* { dg-warning "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
+}
+
+extern int missing_parameter_type (i); /* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" } */
+
+
+int *
+int_conversion_1 (int flag)
+{
+  void f2 (int *);
+  flag ? "1" : 1; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */
+  flag ? 1 : "1"; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */
+  f2 (flag); /* { dg-warning "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+  {
+    int i1 = &flag; /* { dg-warning "initialization of 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+    i1 = &flag; /* { dg-warning "assignment to 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+  }
+  return flag; /* { dg-warning "returning 'int' from a function with return type 'int \\\*' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+}
+
+int
+int_conversion_2 (int flag)
+{
+  void f3 (int);
+  f3 (&flag); /* { dg-warning "passing argument 1 of 'f3' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+  {
+    int *i1 = flag; /* { dg-warning "initialization of 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+    i1 = flag; /* { dg-warning "assignment to 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+  }
+  return &flag; /* { dg-warning "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+}
+
+int *
+incompatible_pointer_types (int flag)
+{
+  void f4 (int *);
+  flag ? __builtin_abs : __builtin_labs; /* { dg-warning "pointer type mismatch in conditional expression \\\[-Wincompatible-pointer-types\\\]" } */
+  {
+    int *p1 = __builtin_abs; /* { dg-warning "initialization of 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    p1 = __builtin_abs; /* { dg-warning "assignment to 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+  }
+  {
+    int *p2 = incompatible_pointer_types; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    p2 = incompatible_pointer_types; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    {
+      int *p3 = &p2; /* { dg-warning "initialization of 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+      p3 = &p2; /* { dg-warning "assignment to 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+    }
+    f4 (&p2); /* { dg-warning "passing argument 1 of 'f4' from incompatible pointer type \\\[-Wincompatible-pointer-types\\\]" } */
+  }
+  if (flag)
+    return __builtin_abs; /* { dg-warning "returning pointer to '__builtin_abs' of type 'int \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+  else
+    return incompatible_pointer_types; /* { dg-warning "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+}
+
+void
+return_mismatch_1 (void)
+{
+  return 0; /* { dg-warning "'return' with a value, in function returning void \\\[-Wreturn-mismatch\\\]" } */
+}
+
+int
+return_mismatch_2 (void)
+{
+  return; /* { dg-warning "return' with no value, in function returning non-void \\\[-Wreturn-mismatch\\\]" } */
+}
diff --git a/gcc/testsuite/gcc.dg/permerror-nowarning.c b/gcc/testsuite/gcc.dg/permerror-nowarning.c
new file mode 100644
index 00000000000..da6bd08245d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/permerror-nowarning.c
@@ -0,0 +1,10 @@ 
+/* { dg-options "-Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-return-mismatch" } */
+
+/* This test checks that permerrors can be disabled using -Wno-* options.  */
+
+#include "permerror-default.c"
+
+/* Ideally, we do not want to see any warnings here, but this warning is not
+   yet controlled by its own option.  */
+
+/* { dg-warning "parameter names \\\(without types\\\) in function declaration\n" "" { target *-*-* } 22 } */
diff --git a/gcc/testsuite/gcc.dg/permerror-pedantic.c b/gcc/testsuite/gcc.dg/permerror-pedantic.c
new file mode 100644
index 00000000000..852e7daa38d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/permerror-pedantic.c
@@ -0,0 +1,85 @@ 
+/* { dg-options "-pedantic-errors" } */
+
+/* Overview test for C permerrors.  This test should be kept in sync with the
+   other permerror-* tests.  If new permerrors are added, test cases should be
+   added to this and the other files.  */
+
+void
+implicit_function_declaration (void)
+{
+  f1 (); /* { dg-error "'f1' \\\[-Wimplicit-function-declaration\\\]" } */
+}
+
+extern implicit_int_1; /* { dg-error "'implicit_int_1' \\\[-Wimplicit-int\\\]" } */
+typedef implicit_int_2; /* { dg-error "'implicit_int_2' \\\[-Wimplicit-int\\\]" } */
+extern implicit_int_3 (void); /* { dg-error "'implicit_int_3' \\\[-Wimplicit-int\\]" } */
+implicit_int_4 (i) /* { dg-error "return type defaults to 'int' \\\[-Wimplicit-int\\\]" } */
+/* { dg-error "type of 'i' defaults to 'int' \\\[-Wimplicit-int\\\]" "" { target *-*-*} .-1 } */
+{
+  (const) 0; /* { dg-error "type defaults to 'int' in type name \\\[-Wimplicit-int\\\]" } */
+}
+
+extern int missing_parameter_type (i); /* { dg-error "parameter names \\\(without types\\\) in function declaration\n" } */
+
+
+int *
+int_conversion_1 (int flag)
+{
+  void f2 (int *);
+  flag ? "1" : 1; /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */
+  flag ? 1 : "1"; /* { dg-error "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */
+  f2 (flag); /* { dg-error "passing argument 1 of 'f2' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+  {
+    int i1 = &flag; /* { dg-error "initialization of 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+    i1 = &flag; /* { dg-error "assignment to 'int' from 'int \\\*' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+  }
+  return flag; /* { dg-error "returning 'int' from a function with return type 'int \\\*' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+}
+
+int
+int_conversion_2 (int flag)
+{
+  void f3 (int);
+  f3 (&flag); /* { dg-error "passing argument 1 of 'f3' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+  {
+    int *i1 = flag; /* { dg-error "initialization of 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+    i1 = flag; /* { dg-error "assignment to 'int \\\*' from 'int' makes pointer from integer without a cast \\\[-Wint-conversion\\\]" } */
+  }
+  return &flag; /* { dg-error "returning 'int \\\*' from a function with return type 'int' makes integer from pointer without a cast \\\[-Wint-conversion\\\]" } */
+}
+
+int *
+incompatible_pointer_types (int flag)
+{
+  void f4 (int *);
+  flag ? __builtin_abs : __builtin_labs; /* { dg-warning "pointer type mismatch in conditional expression \\\[-Wincompatible-pointer-types\\\]" } */
+  {
+    int *p1 = __builtin_abs; /* { dg-error "initialization of 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    p1 = __builtin_abs; /* { dg-error "assignment to 'int \\\*' from pointer to '__builtin_abs' with incompatible type 'int \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+  }
+  {
+    int *p2 = incompatible_pointer_types; /* { dg-error "initialization of 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    p2 = incompatible_pointer_types; /* { dg-error "assignment to 'int \\\*' from incompatible pointer type 'int \\\* \\\(\\\*\\\)\\\(int\\\)' \\\[-Wincompatible-pointer-types\\\]" } */
+    {
+      int *p3 = &p2; /* { dg-error "initialization of 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+      p3 = &p2; /* { dg-error "assignment to 'int \\\*' from incompatible pointer type 'int \\\*\\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+    }
+    f4 (&p2); /* { dg-error "passing argument 1 of 'f4' from incompatible pointer type \\\[-Wincompatible-pointer-types\\\]" } */
+  }
+  if (flag)
+    return __builtin_abs; /* { dg-error "returning pointer to '__builtin_abs' of type 'int \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+  else
+    return incompatible_pointer_types; /* { dg-error "returning 'int \\\* \\\(\\\*\\\)\\\(int\\\)' from a function with incompatible return type 'int \\\*' \\\[-Wincompatible-pointer-types\\\]" } */
+}
+
+void
+return_mismatch_1 (void)
+{
+  return 0; /* { dg-error "'return' with a value, in function returning void \\\[-Wreturn-mismatch\\\]" } */
+}
+
+int
+return_mismatch_2 (void)
+{
+  return; /* { dg-error "return' with no value, in function returning non-void \\\[-Wreturn-mismatch\\\]" } */
+}
diff --git a/gcc/testsuite/gcc.dg/permerror-system.c b/gcc/testsuite/gcc.dg/permerror-system.c
new file mode 100644
index 00000000000..e6a978e494d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/permerror-system.c
@@ -0,0 +1,9 @@ 
+/* { dg-options "-isystem ${srcdir}" } */
+
+/* Test that permerrors appear in system headers.  */
+
+/* The dg-* directives in the header file are ignored.  No warnings are
+   expected.  */
+#include <gcc.dg/permerror-default.c>
+
+/* These errors come from permerror-default.c.  No errors yet.  */