Patchwork Do not allow non-top-level BIT_FIELD_REFs, IMAGPART_EXPRs or REALPART_EXPRs

login
register
mail settings
Submitter Martin Jambor
Date May 29, 2013, 10:34 a.m.
Message ID <20130529103428.GF27165@virgil.suse>
Download mbox | patch
Permalink /patch/247231/
State New
Headers show

Comments

Martin Jambor - May 29, 2013, 10:34 a.m.
Hi,

On Tue, May 28, 2013 at 03:40:25PM +0200, Richard Biener wrote:
> On Tue, 28 May 2013, Martin Jambor wrote:
> > I've committed it s revision 199379, thanks.  As far as the
> > non-top-levelness is concerned, the following (on top of the previous
> > patch) also survives bootstrap and testsuite on x86_64 (all languages
> > including Ada and Obj-C++).  Do you think it would be acceptable as
> > well?
> 
> With the following minor adjustment:
> 
> > Thanks,
> > 
> > Martin
> > 
> >  
> > 2013-05-27  Martin Jambor  <mjambor@suse.cz>
> > 
> > 	* tree-cfg.c (verify_expr): Verify that BIT_FIELD_REF, REALPART_EXPR
> > 	and IMAGPART_EXPR do not occur within other handled_components.
> > 
> > Index: src/gcc/tree-cfg.c
> > ===================================================================
> > --- src.orig/gcc/tree-cfg.c
> > +++ src/gcc/tree-cfg.c
> > @@ -2675,6 +2675,33 @@ verify_expr (tree *tp, int *walk_subtree
> >  	  return t;
> >  	}
> >  
> > +      if (TREE_CODE (t) == BIT_FIELD_REF)
> > +	{
> > +	  if (!host_integerp (TREE_OPERAND (t, 1), 1)
> > +	      || !host_integerp (TREE_OPERAND (t, 2), 1))
> > +	    {
> > +	      error ("invalid position or size operand to BIT_FIELD_REF");
> > +	      return t;
> > +	    }
> > +	  if (INTEGRAL_TYPE_P (TREE_TYPE (t))
> > +	      && (TYPE_PRECISION (TREE_TYPE (t))
> > +		  != TREE_INT_CST_LOW (TREE_OPERAND (t, 1))))
> > +	    {
> > +	      error ("integral result type precision does not match "
> > +		     "field size of BIT_FIELD_REF");
> > +	      return t;
> > +	    }
> > +	  else if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
> > +		   && TYPE_MODE (TREE_TYPE (t)) != BLKmode
> > +		   && (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (t)))
> > +		       != TREE_INT_CST_LOW (TREE_OPERAND (t, 1))))
> > +	    {
> > +	      error ("mode precision of non-integral result does not "
> > +		     "match field size of BIT_FIELD_REF");
> > +	      return t;
> > +	    }
> > +	}
> > +
> 
>       t = TREE_OPERAND (t, 0);
> 
> here instead of ...
> 
> >        /* Fall-through.  */
> >      case COMPONENT_REF:
> >      case ARRAY_REF:
> > @@ -2697,35 +2724,16 @@ verify_expr (tree *tp, int *walk_subtree
> >  	      if (TREE_OPERAND (t, 3))
> >  		CHECK_OP (3, "invalid array stride");
> >  	    }
> > -	  else if (TREE_CODE (t) == BIT_FIELD_REF)
> > -	    {
> > -	      if (!host_integerp (TREE_OPERAND (t, 1), 1)
> > -		  || !host_integerp (TREE_OPERAND (t, 2), 1))
> > -		{
> > -		  error ("invalid position or size operand to BIT_FIELD_REF");
> > -		  return t;
> > -		}
> > -	      if (INTEGRAL_TYPE_P (TREE_TYPE (t))
> > -		  && (TYPE_PRECISION (TREE_TYPE (t))
> > -		      != TREE_INT_CST_LOW (TREE_OPERAND (t, 1))))
> > -		{
> > -		  error ("integral result type precision does not match "
> > -			 "field size of BIT_FIELD_REF");
> > -		  return t;
> > -		}
> > -	      else if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
> > -		       && !AGGREGATE_TYPE_P (TREE_TYPE (t))
> > -		       && TYPE_MODE (TREE_TYPE (t)) != BLKmode
> > -		       && (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (t)))
> > -			   != TREE_INT_CST_LOW (TREE_OPERAND (t, 1))))
> > -		{
> > -		  error ("mode precision of non-integral result does not "
> > -			 "match field size of BIT_FIELD_REF");
> > -		  return t;
> > -		}
> > -	    }
> >  
> >  	  t = TREE_OPERAND (t, 0);
> > +	  if (TREE_CODE (t) == BIT_FIELD_REF
> > +	      || TREE_CODE (t) == REALPART_EXPR
> > +	      || TREE_CODE (t) == IMAGPART_EXPR)
> > +	    {
> > +	      error ("non-top-level BIT_FIELD_REF, IMAGPART_EXPR or "
> > +		     "REALPART_EXPR");
> > +	      return t;
> > +	    }
> 
> ... doing this after t = TREE_OPERAND (t, 0) (so, do it before).
> 

All right, I have committed the following as revision 199405.

Thanks,

Martin


2013-05-29  Martin Jambor  <mjambor@suse.cz>

	* tree-cfg.c (verify_expr): Verify that BIT_FIELD_REF, REALPART_EXPR
	and IMAGPART_EXPR do not occur within other handled_components.

Patch

Index: src/gcc/tree-cfg.c
===================================================================
--- src.orig/gcc/tree-cfg.c
+++ src/gcc/tree-cfg.c
@@ -2675,6 +2675,34 @@  verify_expr (tree *tp, int *walk_subtree
 	  return t;
 	}
 
+      if (TREE_CODE (t) == BIT_FIELD_REF)
+	{
+	  if (!host_integerp (TREE_OPERAND (t, 1), 1)
+	      || !host_integerp (TREE_OPERAND (t, 2), 1))
+	    {
+	      error ("invalid position or size operand to BIT_FIELD_REF");
+	      return t;
+	    }
+	  if (INTEGRAL_TYPE_P (TREE_TYPE (t))
+	      && (TYPE_PRECISION (TREE_TYPE (t))
+		  != TREE_INT_CST_LOW (TREE_OPERAND (t, 1))))
+	    {
+	      error ("integral result type precision does not match "
+		     "field size of BIT_FIELD_REF");
+	      return t;
+	    }
+	  else if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
+		   && TYPE_MODE (TREE_TYPE (t)) != BLKmode
+		   && (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (t)))
+		       != TREE_INT_CST_LOW (TREE_OPERAND (t, 1))))
+	    {
+	      error ("mode precision of non-integral result does not "
+		     "match field size of BIT_FIELD_REF");
+	      return t;
+	    }
+	}
+      t = TREE_OPERAND (t, 0);
+
       /* Fall-through.  */
     case COMPONENT_REF:
     case ARRAY_REF:
@@ -2697,32 +2725,13 @@  verify_expr (tree *tp, int *walk_subtree
 	      if (TREE_OPERAND (t, 3))
 		CHECK_OP (3, "invalid array stride");
 	    }
-	  else if (TREE_CODE (t) == BIT_FIELD_REF)
+	  else if (TREE_CODE (t) == BIT_FIELD_REF
+		   || TREE_CODE (t) == REALPART_EXPR
+		   || TREE_CODE (t) == IMAGPART_EXPR)
 	    {
-	      if (!host_integerp (TREE_OPERAND (t, 1), 1)
-		  || !host_integerp (TREE_OPERAND (t, 2), 1))
-		{
-		  error ("invalid position or size operand to BIT_FIELD_REF");
-		  return t;
-		}
-	      if (INTEGRAL_TYPE_P (TREE_TYPE (t))
-		  && (TYPE_PRECISION (TREE_TYPE (t))
-		      != TREE_INT_CST_LOW (TREE_OPERAND (t, 1))))
-		{
-		  error ("integral result type precision does not match "
-			 "field size of BIT_FIELD_REF");
-		  return t;
-		}
-	      else if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
-		       && !AGGREGATE_TYPE_P (TREE_TYPE (t))
-		       && TYPE_MODE (TREE_TYPE (t)) != BLKmode
-		       && (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (t)))
-			   != TREE_INT_CST_LOW (TREE_OPERAND (t, 1))))
-		{
-		  error ("mode precision of non-integral result does not "
-			 "match field size of BIT_FIELD_REF");
-		  return t;
-		}
+	      error ("non-top-level BIT_FIELD_REF, IMAGPART_EXPR or "
+		     "REALPART_EXPR");
+	      return t;
 	    }
 
 	  t = TREE_OPERAND (t, 0);