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]

[Ada] Fix ACATS cd92001 & cxh1001


This is the famous interaction between 'Valid and VRP (PR ada/32407 & 26797).

Thanks to the rewrite of useless_type_conversion_p by Richard G., we now can
generate more robust counter-measures in Gigi.

Bootstrapped/regtested on i586-suse-linux, applied to mainline.


2007-09-12  Eric Botcazou  <ebotcazou@adacore.com>

	PR ada/26797
	PR ada/32407
	* utils.c (unchecked_convert): Use a subtype as the intermediate type
	in the special VIEW_CONVERT_EXPR case.


-- 
Eric Botcazou
Index: utils.c
===================================================================
--- utils.c	(revision 128432)
+++ utils.c	(working copy)
@@ -3808,7 +3808,7 @@ unchecked_convert (tree type, tree expr,
 	  TYPE_MAIN_VARIANT (rtype) = rtype;
 	}
 
-      /* We have another special case.  If we are unchecked converting subtype
+      /* We have another special case: if we are unchecked converting subtype
 	 into a base type, we need to ensure that VRP doesn't propagate range
 	 information since this conversion may be done precisely to validate
 	 that the object is within the range it is supposed to have.  */
@@ -3818,21 +3818,18 @@ unchecked_convert (tree type, tree expr,
 		   || TREE_CODE (etype) == ENUMERAL_TYPE
 		   || TREE_CODE (etype) == BOOLEAN_TYPE))
 	{
-	  /* ??? The pattern to be "preserved" by the middle-end and the
-	     optimizers is a VIEW_CONVERT_EXPR between a pair of different
-	     "base" types (integer types without TREE_TYPE).  But this may
-	     raise addressability/aliasing issues because VIEW_CONVERT_EXPR
-	     gets gimplified as an lvalue, thus causing the address of its
-	     operand to be taken if it is deemed addressable and not already
-	     in GIMPLE form.  */
+	  /* The optimization barrier is a VIEW_CONVERT_EXPR node; moreover,
+	     in order not to be deemed an useless type conversion, it must
+	     be from subtype to base type.
+
+	     ??? This may raise addressability and/or aliasing issues because
+	     VIEW_CONVERT_EXPR gets gimplified as an lvalue, thus causing the
+	     address of its operand to be taken if it is deemed addressable
+	     and not already in GIMPLE form.  */
 	  rtype = gnat_type_for_mode (TYPE_MODE (type), TYPE_UNSIGNED (type));
-
-	  if (rtype == type)
-	    {
-	      rtype = copy_type (rtype);
-	      TYPE_MAIN_VARIANT (rtype) = rtype;
-	    }
-
+	  rtype = copy_type (rtype);
+	  TYPE_MAIN_VARIANT (rtype) = rtype;
+	  TREE_TYPE (rtype) = type;
 	  final_unchecked = true;
 	}
 

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