diff mbox series

[committed] handle invalid input even earlier (PR 97463)

Message ID b9b073ed-e8ba-da85-22b5-cdc8bc7283f7@gmail.com
State New
Headers show
Series [committed] handle invalid input even earlier (PR 97463) | expand

Commit Message

Martin Sebor Oct. 23, 2020, 6:53 p.m. UTC
To avoid yet another ICE caused by dereferencing a null tree due to
invalid input, the attached change moves the handling even earlier
in the affected function.  Tested on x86_64-linux and pushed as
obvious (at least until the next ICE shows up that necessitates to
move the test earlier still).

Martin
diff mbox series

Patch

commit 7991e963239160624b22a12caaacce95d3667e49
Author: Martin Sebor <msebor@redhat.com>
Date:   Fri Oct 23 12:30:20 2020 -0600

    PR c/97463 - ICE in warn_parm_ptrarray_mismatch on an incompatible function redeclaration
    
    gcc/c-family/ChangeLog:
    
            PR c/97463
            * c-warn.c (warn_parm_ptrarray_mismatch): Move null test earlier.
    
    gcc/testsuite/ChangeLog:
    
            PR c/97463
            * gcc.dg/pr97463.c: New test.

diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index ebd011d1a42..a1b945053e8 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -3177,14 +3177,14 @@  warn_parm_ptrarray_mismatch (location_t origloc, tree curparms, tree newparms)
 	{
 	  curtyp = TREE_TYPE (curtyp);
 	  newtyp = TREE_TYPE (newtyp);
+
+	  if (!newtyp)
+	    /* Bail on error.  */
+	    return;
 	}
       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)
 	{
diff --git a/gcc/testsuite/gcc.dg/pr97463.c b/gcc/testsuite/gcc.dg/pr97463.c
new file mode 100644
index 00000000000..f93b07ccb80
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr97463.c
@@ -0,0 +1,7 @@ 
+/* PR c/97463 - ICE in warn_parm_ptrarray_mismatch on an incompatible
+   function redeclaration
+   { dg-do compile }
+   { dg-options "-Wall" } */
+
+void f (void**);
+void f (int n) { }      // { dg-error "conflicting types" }