Fix ICE with -Wduplicated-branches (PR c/79199)
Richard Biener
richard.guenther@gmail.com
Thu Jan 26 12:20:00 GMT 2017
On Thu, Jan 26, 2017 at 12:21 PM, Marek Polacek <polacek@redhat.com> wrote:
> This testcase was breaking because we found ourselves in operand_equal_p
> with a COND_EXPR whose operand 2 was null -- i.e., missing else branch,
> which won't happen for ? : but can happen here via -Wduplicated-branches.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
I think NULL isn't really allowed, it has to be sth of void type instead.
Richard.
> 2017-01-26 Marek Polacek <polacek@redhat.com>
>
> PR c/79199
> * fold-const.c (operand_equal_p) [COND_EXPR]: Use OP_SAME_WITH_NULL
> for the third operand.
>
> * c-c++-common/Wduplicated-branches-13.c: New test.
>
> diff --git gcc/fold-const.c gcc/fold-const.c
> index 5576d59..a8bb8af 100644
> --- gcc/fold-const.c
> +++ gcc/fold-const.c
> @@ -3147,7 +3147,7 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
> TREE_OPERAND (arg1, 0), flags));
>
> case COND_EXPR:
> - if (! OP_SAME (1) || ! OP_SAME (2))
> + if (! OP_SAME (1) || ! OP_SAME_WITH_NULL (2))
> return 0;
> flags &= ~OEP_ADDRESS_OF;
> return OP_SAME (0);
> diff --git gcc/testsuite/c-c++-common/Wduplicated-branches-13.c gcc/testsuite/c-c++-common/Wduplicated-branches-13.c
> index e69de29..7aa5b37 100644
> --- gcc/testsuite/c-c++-common/Wduplicated-branches-13.c
> +++ gcc/testsuite/c-c++-common/Wduplicated-branches-13.c
> @@ -0,0 +1,23 @@
> +/* PR c/79199 */
> +/* { dg-do compile } */
> +/* { dg-options "-Wduplicated-branches" } */
> +
> +unsigned int a, b, c, d, e;
> +void
> +fn1 (void)
> +{
> + if (0) /* { dg-warning "this condition has identical branches" } */
> + {
> + if (d > 4294967293)
> + (void) 5;
> + c = d;
> + b = e | a;
> + }
> + else
> + {
> + if (d > 4294967293)
> + (void) 5;
> + c = d;
> + b = e | a;
> + }
> +}
>
> Marek
More information about the Gcc-patches
mailing list