]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c/100783 - ICE on -Wnonnull and erroneous type
authorMartin Sebor <msebor@redhat.com>
Fri, 4 Jun 2021 17:21:51 +0000 (11:21 -0600)
committerMartin Sebor <msebor@redhat.com>
Fri, 4 Jun 2021 17:22:39 +0000 (11:22 -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 156f7b3e8e1b3ddcb16324b1e6c252374d7c5660..42026a811dd2e4469ed9811c75711347613d02d3 100644 (file)
@@ -698,6 +698,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" }