]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c/100783 - ICE on -Wnonnull and erroneous type
authorMartin Sebor <msebor@redhat.com>
Thu, 17 Jun 2021 18:17:02 +0000 (12:17 -0600)
committerMartin Sebor <msebor@redhat.com>
Thu, 17 Jun 2021 20:07:15 +0000 (14:07 -0600)
gcc/c-family/ChangeLog:

PR c/100783
* c-attribs.c (positional_argument): Bail on erroneous types.

gcc/c/ChangeLog:

PR c/100783
* c-objc-common.c (print_type): Handle erroneous types.

gcc/testsuite/ChangeLog:

PR c/100783
* gcc.dg/nonnull-6.c: New test.

gcc/c-family/c-attribs.c
gcc/c/c-objc-common.c
gcc/testsuite/gcc.dg/nonnull-6.c [new file with mode: 0644]

index 1413f5e9b391ea5bf7600b4250370d97b70d562a..cdf89d66fe14281cffb2dc1c8c0bae9547afb2a5 100644 (file)
@@ -694,6 +694,9 @@ positional_argument (const_tree fntype, const_tree atname, tree pos,
 
   if (tree argtype = type_argument_type (fntype, ipos))
     {
+      if (argtype == error_mark_node)
+       return NULL_TREE;
+
       if (flags & POSARG_ELLIPSIS)
        {
          if (argno < 1)
index a68249d70118bbed064c9915b0780003f6c66551..b945de15ab84edcda3bb60b8cfd9033b4c9cd8d8 100644 (file)
@@ -185,6 +185,12 @@ get_aka_type (tree type)
 static void
 print_type (c_pretty_printer *cpp, tree t, bool *quoted)
 {
+  if (t == error_mark_node)
+    {
+      pp_string (cpp, _("{erroneous}"));
+      return;
+    }
+
   gcc_assert (TYPE_P (t));
   struct obstack *ob = pp_buffer (cpp)->obstack;
   char *p = (char *) obstack_base (ob);
diff --git a/gcc/testsuite/gcc.dg/nonnull-6.c b/gcc/testsuite/gcc.dg/nonnull-6.c
new file mode 100644 (file)
index 0000000..8f36870
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR c/100783 - ICE on -Wnonnull and erroneous type
+   { dg-do compile }
+   { dg-options "-Wall" } */
+
+__attribute__((nonnull (1))) void
+f1 (char[][n]);                         // { dg-error "undeclared" }
+
+__attribute__((nonnull (2))) void
+f2 (int n, char[n][m]);                 // { dg-error "undeclared" }
+
+__attribute__((nonnull (1))) void
+f3 (char[*][n]);                        // { dg-error "undeclared" }
+
+__attribute__((nonnull (1))) void
+f4 (char[f1]);                          // { dg-error "size" }