diff mbox

Fix ICE with -Wduplicated-branches (PR objc/80949)

Message ID 20170613170110.GC3413@redhat.com
State New
Headers show

Commit Message

Marek Polacek June 13, 2017, 5:01 p.m. UTC
-Wduplicated-branches can crash on a weird ObjC testcase that we haven't
managed to reduce, so no testcase attached.  On that testcase, we end up
calling do_warn_duplicated_branches with null COND_EXPR_THEN, and the code
wasn't prepared to handle that.  The fix is trivial.  Eric G. verified that
this indeed fixes the ICE (thanks).

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2017-06-13  Marek Polacek  <polacek@redhat.com>

	PR objc/80949
	* c-warn.c (do_warn_duplicated_branches): Return if any of the
	branches is null.


	Marek

Comments

Jakub Jelinek June 13, 2017, 5:11 p.m. UTC | #1
On Tue, Jun 13, 2017 at 07:01:11PM +0200, Marek Polacek wrote:
> -Wduplicated-branches can crash on a weird ObjC testcase that we haven't
> managed to reduce, so no testcase attached.  On that testcase, we end up
> calling do_warn_duplicated_branches with null COND_EXPR_THEN, and the code
> wasn't prepared to handle that.  The fix is trivial.  Eric G. verified that
> this indeed fixes the ICE (thanks).
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> 2017-06-13  Marek Polacek  <polacek@redhat.com>
> 
> 	PR objc/80949
> 	* c-warn.c (do_warn_duplicated_branches): Return if any of the
> 	branches is null.

Ok, thanks.

> --- gcc/c-family/c-warn.c
> +++ gcc/c-family/c-warn.c
> @@ -2354,8 +2354,8 @@ do_warn_duplicated_branches (tree expr)
>    tree thenb = COND_EXPR_THEN (expr);
>    tree elseb = COND_EXPR_ELSE (expr);
>  
> -  /* Don't bother if there's no else branch.  */
> -  if (elseb == NULL_TREE)
> +  /* Don't bother if any of the branches is missing.  */
> +  if (thenb == NULL_TREE || elseb == NULL_TREE)
>      return;
>  
>    /* And don't warn for empty statements.  */
> 
> 	Marek

	Jakub
diff mbox

Patch

--- gcc/c-family/c-warn.c
+++ gcc/c-family/c-warn.c
@@ -2354,8 +2354,8 @@  do_warn_duplicated_branches (tree expr)
   tree thenb = COND_EXPR_THEN (expr);
   tree elseb = COND_EXPR_ELSE (expr);
 
-  /* Don't bother if there's no else branch.  */
-  if (elseb == NULL_TREE)
+  /* Don't bother if any of the branches is missing.  */
+  if (thenb == NULL_TREE || elseb == NULL_TREE)
     return;
 
   /* And don't warn for empty statements.  */