public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] also test for null in addition to error_mark_node (PR c/97131)
@ 2020-09-23 21:18 Martin Sebor
  0 siblings, 0 replies; only message in thread
From: Martin Sebor @ 2020-09-23 21:18 UTC (permalink / raw)
  To: gcc-patches

The new warn_parm_ptrarray_mismatch() function can be called even
for invalid source code.  It tries to handle some of it by checking
for error_mark_node but that's not enough since some invalid input
can apparently result in nodes being null.  I have committed
the patch below to avoid the ICE that it causes.

Martin

commit e92779db3304bc96a6b861f87c5edde8dd4d4030
Author: Martin Sebor <msebor@redhat.com>
Date:   Wed Sep 23 15:02:01 2020 -0600

     Avoid assuming input corresponds to valid source code (PR c/97131).

     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.

diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index d6db85b6de5..ebd011d1a42 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -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
index 00000000000..609dac96bb6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Warray-parameter-6.c
@@ -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'" }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-23 21:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-23 21:18 [committed] also test for null in addition to error_mark_node (PR c/97131) Martin Sebor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).