[PATCH, middle-end] Ping: Switch initializations conversion

Martin Jambor mjambor@suse.cz
Sun Jul 13 22:07:00 GMT 2008


Hi,

On Sun, Jul 13, 2008 at 10:38:41PM +0200, Richard Guenther wrote:
> > I believe the cleanest solution  is indeed to generate the arithmetics
> > in a  safe super-type.  Based on  comments in tree.def I  have come up
> > with  the following  four line  patch which  prevents the  assert from
> > being hit.  I was considering  replacing the if statement with a while
> > cycle but it does not seem to make any difference.
> >
> > I will bootstrap and test it soon.  Is it OK if it passes?
> 
> I think it's better to make sure to use the base-type already here:
> 
>   tree utype = unsigned_type_for (TREE_TYPE (info.index_expr));
> 
> Ok with using the base-type of TREE_TYPE (info.index_expr) to generate
> utype.
> 

You are right the order of TREE_TYPE and unsigned_type_for should be
the opposite.  Therefore I will test this patch instead. Is it OK?
Thanks.

Martin


2008-07-13  Martin Jambor  <mjambor@suse.cz>

       * tree-switch-conversion.c (gen_inbound_check): Make sure the type
       in which we generate arithmetics is not a subrange.

Index: gcc/tree-switch-conversion.c
===================================================================
--- gcc/tree-switch-conversion.c	(revision 137717)
+++ gcc/tree-switch-conversion.c	(working copy)
@@ -622,7 +622,7 @@
   tree label_decl3 = create_artificial_label ();
   tree label1, label2, label3;
 
-  tree utype = unsigned_type_for (TREE_TYPE (info.index_expr));
+  tree utype;
   tree tmp_u;
   tree cast, cast_assign;
   tree ulb, minus, minus_assign;
@@ -638,6 +638,12 @@
   gcc_assert (info.default_values);
   bb0 = bb_for_stmt (swtch);
 
+  /* Make sure we do not generate arithmetics in a subrange.  */
+  if (TREE_TYPE (TREE_TYPE (info.index_expr)))
+    utype = unsigned_type_for (TREE_TYPE (TREE_TYPE (info.index_expr)));
+  else
+    utype = unsigned_type_for (TREE_TYPE (info.index_expr));
+
   /* (end of) block 0 */
   bsi = bsi_for_stmt (info.arr_ref_first);
   tmp_u = make_rename_temp (utype, "csui");



More information about the Gcc-patches mailing list