We crash here because since r11-3302 the C FE uses codes like SWITCH_STMT
in the else branches in the attached test, and inchash::add_expr in
do_warn_duplicated_branches doesn't handle these front-end codes. In
the C++ FE this works because by the time we get to do_warn_duplicated_branches
we've already cp_genericize'd the SWITCH_STMT tree into a SWITCH_EXPR.
The fix is to call do_warn_duplicated_branches_r only after loops and other
structured control constructs have been lowered.
gcc/c-family/ChangeLog:
PR c/97125
* c-gimplify.c (c_genericize): Only call do_warn_duplicated_branches_r
after loops and other structured control constructs have been lowered.
gcc/testsuite/ChangeLog:
PR c/97125
* c-c++-common/Wduplicated-branches-15.c: New test.
&pset);
}
- if (warn_duplicated_branches)
- walk_tree_without_duplicates (&DECL_SAVED_TREE (fndecl),
- do_warn_duplicated_branches_r, NULL);
-
/* Genericize loops and other structured control constructs. The C++
front end has already done this in lang-specific code. */
if (!c_dialect_cxx ())
pop_cfun ();
}
+ if (warn_duplicated_branches)
+ walk_tree_without_duplicates (&DECL_SAVED_TREE (fndecl),
+ do_warn_duplicated_branches_r, NULL);
+
/* Dump the C-specific tree IR. */
dump_orig = get_dump_info (TDI_original, &local_dump_flags);
if (dump_orig)
--- /dev/null
+/* PR c/97125 */
+/* { dg-do compile } */
+/* { dg-options "-Wduplicated-branches" } */
+
+void foo (void);
+
+void
+fn1 (void)
+{
+ if (0)
+ foo ();
+ else
+ switch (0);
+}
+
+void
+fn2 (void)
+{
+ if (0)
+ foo ();
+ else
+ while (0);
+}
+
+void
+fn3 (void)
+{
+ if (0)
+ foo ();
+ else
+ for (;;);
+}