This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR37285, switch default label issues


This fixes PR37285 a case where we are confused with a switch stmt
without a default label.  Fortunately(?) after the tuples merge we
always have a default label again(!) - we just fail to mark it as
such properly.  This also addresses a missed-optimization during
expansion (I don't remember exactly, but HP does maybe ...).

That said, if we ever remove the default case during VRP we can
promote any remaining case to the default one.  Which is what this
patch does - simply chose the one we put in the location for the
default case.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

In theory we should be able to revert all the expander and middle-end
changes from the original patch now ...

Richard.

2008-10-01  Richard Guenther  <rguenther@suse.de>

        PR middle-end/37285
        * tree-vrp.c (execute_vrp): If we optimized away the default
        case make sure to promote the label that got in place of it
        to a default case label.

        * gcc.c-torture/compile/pr37285.c: New testcase.

Index: testsuite/gcc.c-torture/compile/pr37285.c
===================================================================
*** testsuite/gcc.c-torture/compile/pr37285.c	(revision 0)
--- testsuite/gcc.c-torture/compile/pr37285.c	(revision 0)
***************
*** 0 ****
--- 1,15 ----
+ _bfd_xcoff_canonicalize_dynamic_reloc (unsigned long long l_symndx)
+ {
+   if (l_symndx < 3)
+     {
+       switch (l_symndx)
+       {
+         case 0:
+         case 1:
+          break;
+         case 2:
+          _bfd_abort ("HI");
+     }
+   }
+ }
+ 
Index: tree-vrp.c
===================================================================
*** tree-vrp.c	(revision 140810)
--- tree-vrp.c	(working copy)
*************** execute_vrp (void)
*** 7149,7157 ****
--- 7149,7164 ----
      {
        size_t j;
        size_t n = TREE_VEC_LENGTH (su->vec);
+       tree label;
        gimple_switch_set_num_labels (su->stmt, n);
        for (j = 0; j < n; j++)
  	gimple_switch_set_label (su->stmt, j, TREE_VEC_ELT (su->vec, j));
+       /* As we may have replaced the default label with a regular one
+ 	 make sure to make it a real default label again.  This ensures
+ 	 optimal expansion.  */
+       label = gimple_switch_default_label (su->stmt);
+       CASE_LOW (label) = NULL_TREE;
+       CASE_HIGH (label) = NULL_TREE;
      }
  
    if (VEC_length (edge, to_remove_edges) > 0)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]