]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Avoid assuming input corresponds to valid source code (PR c/97131).
authorMartin Sebor <msebor@redhat.com>
Wed, 23 Sep 2020 21:02:01 +0000 (15:02 -0600)
committerMartin Sebor <msebor@redhat.com>
Wed, 23 Sep 2020 21:02:01 +0000 (15:02 -0600)
gcc/c-family/ChangeLog:

PR c/97131
* c-warn.c (warn_parm_ptrarray_mismatch): Handle more invalid input.

gcc/testsuite/ChangeLog:

PR c/97131
* gcc.dg/Warray-parameter-6.c: New test.

gcc/c-family/c-warn.c
gcc/testsuite/gcc.dg/Warray-parameter-6.c [new file with mode: 0644]

index d6db85b6de551a041dc0b3772df5c5dd83de6db8..ebd011d1a4228deae469b4c7adc254d89f180b88 100644 (file)
@@ -3181,11 +3181,16 @@ warn_parm_ptrarray_mismatch (location_t origloc, tree curparms, tree newparms)
       while (TREE_CODE (curtyp) == POINTER_TYPE
             && TREE_CODE (newtyp) == POINTER_TYPE);
 
+      if (!newtyp)
+       /* Bail on error.  */
+       return;
+
       if (TREE_CODE (curtyp) != ARRAY_TYPE
          || TREE_CODE (newtyp) != ARRAY_TYPE)
        {
          if (curtyp == error_mark_node
              || newtyp == error_mark_node)
+           /* Bail on error.  */
            return;
 
          continue;
diff --git a/gcc/testsuite/gcc.dg/Warray-parameter-6.c b/gcc/testsuite/gcc.dg/Warray-parameter-6.c
new file mode 100644 (file)
index 0000000..609dac9
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR c/97131 - ICE: Segmentation fault in warn_parm_ptrarray_mismatch
+   { dg-do compile }
+   { dg-options "-Wall" } */
+
+struct bm { };
+
+void ms (struct bm (*at)[1]) { }
+
+void ms (int f1) { }          // { dg-error "conflicting types for 'ms'" }