[01/10] Expand COMPLETE_TYPE_P in obvious checks for null

Message ID 878t2zjn7s.fsf@arm.com
State New
Headers show
Series
  • Splitting the C and C++ concept of "complete type"
Related show

Commit Message

Richard Sandiford Oct. 15, 2018, 2:31 p.m.
Some tests for COMPLETE_TYPE_P are just protecting against a null
TYPE_SIZE or TYPE_SIZE_UNIT.  Rather than replace them with a new
macro, it seemed clearer to write out the underlying test.

2018-10-15  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	* calls.c (initialize_argument_information): Replace COMPLETE_TYPE_P
	with checks for null.
	* config/aarch64/aarch64.c (aapcs_vfp_sub_candidate): Likewise.
	* config/arm/arm.c (aapcs_vfp_sub_candidate): Likewise.
	* config/powerpcspe/powerpcspe.c (rs6000_aggregate_candidate):
	Likewise.
	* config/riscv/riscv.c (riscv_flatten_aggregate_field): Likewise.
	* config/rs6000/rs6000.c (rs6000_aggregate_candidate): Likewise.
	* expr.c (expand_assignment, safe_from_p): Likewise.
	(expand_expr_real_1): Likewise.
	* tree-data-ref.c (initialize_data_dependence_relation): Likewise.
	* tree-sra.c (maybe_add_sra_candidate): Likewise.
	(find_param_candidates): Likewise.
	* tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Likewise.
	* tree-vrp.c (vrp_prop::check_mem_ref): Likewise.

gcc/lto/
	* lto-symtab.c (warn_type_compatibility_p): Likewise.

Comments

Jeff Law Oct. 18, 2018, 5:22 p.m. | #1
On 10/15/18 8:31 AM, Richard Sandiford wrote:
> Some tests for COMPLETE_TYPE_P are just protecting against a null

> TYPE_SIZE or TYPE_SIZE_UNIT.  Rather than replace them with a new

> macro, it seemed clearer to write out the underlying test.

> 

> 2018-10-15  Richard Sandiford  <richard.sandiford@arm.com>

> 

> gcc/

> 	* calls.c (initialize_argument_information): Replace COMPLETE_TYPE_P

> 	with checks for null.

> 	* config/aarch64/aarch64.c (aapcs_vfp_sub_candidate): Likewise.

> 	* config/arm/arm.c (aapcs_vfp_sub_candidate): Likewise.

> 	* config/powerpcspe/powerpcspe.c (rs6000_aggregate_candidate):

> 	Likewise.

> 	* config/riscv/riscv.c (riscv_flatten_aggregate_field): Likewise.

> 	* config/rs6000/rs6000.c (rs6000_aggregate_candidate): Likewise.

> 	* expr.c (expand_assignment, safe_from_p): Likewise.

> 	(expand_expr_real_1): Likewise.

> 	* tree-data-ref.c (initialize_data_dependence_relation): Likewise.

> 	* tree-sra.c (maybe_add_sra_candidate): Likewise.

> 	(find_param_candidates): Likewise.

> 	* tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Likewise.

> 	* tree-vrp.c (vrp_prop::check_mem_ref): Likewise.

> 

> gcc/lto/

> 	* lto-symtab.c (warn_type_compatibility_p): Likewise.

This seems largely independent of the larger changes you're trying to
make and could stand on its own.

I'm going to assume that you evaluated these instances of
COMPLETE_TYPE_P and determined that type completeness isn't really a
factor in the affected code.

OK if nobody objects by Monday.

jeff

Patch

Index: gcc/calls.c
===================================================================
--- gcc/calls.c	2018-10-05 13:46:11.115788209 +0100
+++ gcc/calls.c	2018-10-15 14:12:54.016553288 +0100
@@ -2039,7 +2039,7 @@  initialize_argument_information (int num
 		 function being called.  */
 	      rtx copy;
 
-	      if (!COMPLETE_TYPE_P (type)
+	      if (!TYPE_SIZE_UNIT (type)
 		  || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST
 		  || (flag_stack_check == GENERIC_STACK_CHECK
 		      && compare_tree_int (TYPE_SIZE_UNIT (type),
Index: gcc/config/aarch64/aarch64.c
===================================================================
--- gcc/config/aarch64/aarch64.c	2018-10-15 14:08:45.970608817 +0100
+++ gcc/config/aarch64/aarch64.c	2018-10-15 14:12:54.020553256 +0100
@@ -13000,7 +13000,7 @@  aapcs_vfp_sub_candidate (const_tree type
 
 	/* Can't handle incomplete types nor sizes that are not
 	   fixed.  */
-	if (!COMPLETE_TYPE_P (type)
+	if (!TYPE_SIZE (type)
 	    || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
 	  return -1;
 
@@ -13033,7 +13033,7 @@  aapcs_vfp_sub_candidate (const_tree type
 
 	/* Can't handle incomplete types nor sizes that are not
 	   fixed.  */
-	if (!COMPLETE_TYPE_P (type)
+	if (!TYPE_SIZE (type)
 	    || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
 	  return -1;
 
@@ -13066,7 +13066,7 @@  aapcs_vfp_sub_candidate (const_tree type
 
 	/* Can't handle incomplete types nor sizes that are not
 	   fixed.  */
-	if (!COMPLETE_TYPE_P (type)
+	if (!TYPE_SIZE (type)
 	    || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
 	  return -1;
 
Index: gcc/config/arm/arm.c
===================================================================
--- gcc/config/arm/arm.c	2018-10-05 13:46:14.375761802 +0100
+++ gcc/config/arm/arm.c	2018-10-15 14:12:54.024553222 +0100
@@ -5927,7 +5927,7 @@  aapcs_vfp_sub_candidate (const_tree type
 
 	/* Can't handle incomplete types nor sizes that are not
 	   fixed.  */
-	if (!COMPLETE_TYPE_P (type)
+	if (!TYPE_SIZE (type)
 	    || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
 	  return -1;
 
@@ -5960,7 +5960,7 @@  aapcs_vfp_sub_candidate (const_tree type
 
 	/* Can't handle incomplete types nor sizes that are not
 	   fixed.  */
-	if (!COMPLETE_TYPE_P (type)
+	if (!TYPE_SIZE (type)
 	    || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
 	  return -1;
 
@@ -5993,7 +5993,7 @@  aapcs_vfp_sub_candidate (const_tree type
 
 	/* Can't handle incomplete types nor sizes that are not
 	   fixed.  */
-	if (!COMPLETE_TYPE_P (type)
+	if (!TYPE_SIZE (type)
 	    || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
 	  return -1;
 
Index: gcc/config/powerpcspe/powerpcspe.c
===================================================================
--- gcc/config/powerpcspe/powerpcspe.c	2018-10-05 13:46:13.855766014 +0100
+++ gcc/config/powerpcspe/powerpcspe.c	2018-10-15 14:12:54.032553156 +0100
@@ -11540,7 +11540,7 @@  rs6000_aggregate_candidate (const_tree t
 
 	/* Can't handle incomplete types nor sizes that are not
 	   fixed.  */
-	if (!COMPLETE_TYPE_P (type)
+	if (!TYPE_SIZE (type)
 	    || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
 	  return -1;
 
@@ -11573,7 +11573,7 @@  rs6000_aggregate_candidate (const_tree t
 
 	/* Can't handle incomplete types nor sizes that are not
 	   fixed.  */
-	if (!COMPLETE_TYPE_P (type)
+	if (!TYPE_SIZE (type)
 	    || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
 	  return -1;
 
@@ -11606,7 +11606,7 @@  rs6000_aggregate_candidate (const_tree t
 
 	/* Can't handle incomplete types nor sizes that are not
 	   fixed.  */
-	if (!COMPLETE_TYPE_P (type)
+	if (!TYPE_SIZE (type)
 	    || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
 	  return -1;
 
Index: gcc/config/riscv/riscv.c
===================================================================
--- gcc/config/riscv/riscv.c	2018-10-05 13:46:13.879765820 +0100
+++ gcc/config/riscv/riscv.c	2018-10-15 14:12:54.032553156 +0100
@@ -2290,7 +2290,7 @@  riscv_flatten_aggregate_field (const_tre
     {
     case RECORD_TYPE:
      /* Can't handle incomplete types nor sizes that are not fixed.  */
-     if (!COMPLETE_TYPE_P (type)
+     if (!TYPE_SIZE (type)
 	 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
 	 || !tree_fits_uhwi_p (TYPE_SIZE (type)))
        return -1;
@@ -2319,7 +2319,7 @@  riscv_flatten_aggregate_field (const_tre
 
 	/* Can't handle incomplete types nor sizes that are not fixed.  */
 	if (n_subfields <= 0
-	    || !COMPLETE_TYPE_P (type)
+	    || !TYPE_SIZE (type)
 	    || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
 	    || !index
 	    || !TYPE_MAX_VALUE (index)
Index: gcc/config/rs6000/rs6000.c
===================================================================
--- gcc/config/rs6000/rs6000.c	2018-10-15 14:08:45.994608617 +0100
+++ gcc/config/rs6000/rs6000.c	2018-10-15 14:12:54.040553089 +0100
@@ -10386,7 +10386,7 @@  rs6000_aggregate_candidate (const_tree t
 
 	/* Can't handle incomplete types nor sizes that are not
 	   fixed.  */
-	if (!COMPLETE_TYPE_P (type)
+	if (!TYPE_SIZE (type)
 	    || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
 	  return -1;
 
@@ -10419,7 +10419,7 @@  rs6000_aggregate_candidate (const_tree t
 
 	/* Can't handle incomplete types nor sizes that are not
 	   fixed.  */
-	if (!COMPLETE_TYPE_P (type)
+	if (!TYPE_SIZE (type)
 	    || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
 	  return -1;
 
@@ -10452,7 +10452,7 @@  rs6000_aggregate_candidate (const_tree t
 
 	/* Can't handle incomplete types nor sizes that are not
 	   fixed.  */
-	if (!COMPLETE_TYPE_P (type)
+	if (!TYPE_SIZE (type)
 	    || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
 	  return -1;
 
Index: gcc/expr.c
===================================================================
--- gcc/expr.c	2018-10-05 13:46:10.003797217 +0100
+++ gcc/expr.c	2018-10-15 14:12:54.040553089 +0100
@@ -5300,7 +5300,7 @@  expand_assignment (tree to, tree from, b
      needs to be done.  Handling this in the normal way is safe because no
      computation is done before the call.  The same is true for SSA names.  */
   if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from, from)
-      && COMPLETE_TYPE_P (TREE_TYPE (from))
+      && TYPE_SIZE (TREE_TYPE (from))
       && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
       && ! (((VAR_P (to)
 	      || TREE_CODE (to) == PARM_DECL
@@ -7518,7 +7518,9 @@  safe_from_p (const_rtx x, tree exp, int
 	 So we assume here that something at a higher level has prevented a
 	 clash.  This is somewhat bogus, but the best we can do.  Only
 	 do this when X is BLKmode and when we are at the top level.  */
-      || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
+      || (top_p
+	  && TREE_TYPE (exp) != 0
+	  && TYPE_SIZE (TREE_TYPE (exp))
 	  && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
 	  && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
 	      || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
@@ -10523,7 +10525,7 @@  expand_expr_real_1 (tree exp, rtx target
 	orig_op0 = op0
 	  = expand_expr_real (tem,
 			      (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
-			       && COMPLETE_TYPE_P (TREE_TYPE (tem))
+			       && TYPE_SIZE (TREE_TYPE (tem))
 			       && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
 				   != INTEGER_CST)
 			       && modifier != EXPAND_STACK_PARM
Index: gcc/tree-data-ref.c
===================================================================
--- gcc/tree-data-ref.c	2018-10-05 13:46:11.115788209 +0100
+++ gcc/tree-data-ref.c	2018-10-15 14:12:54.040553089 +0100
@@ -2487,8 +2487,8 @@  initialize_data_dependence_relation (str
 	}
 
       /* Try to approach equal type sizes.  */
-      if (!COMPLETE_TYPE_P (type_a)
-	  || !COMPLETE_TYPE_P (type_b)
+      if (!TYPE_SIZE_UNIT (type_a)
+	  || !TYPE_SIZE_UNIT (type_b)
 	  || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type_a))
 	  || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type_b)))
 	break;
Index: gcc/tree-sra.c
===================================================================
--- gcc/tree-sra.c	2018-08-28 11:25:46.034881666 +0100
+++ gcc/tree-sra.c	2018-10-15 14:12:54.040553089 +0100
@@ -1988,9 +1988,9 @@  maybe_add_sra_candidate (tree var)
       reject (var, "is volatile");
       return false;
     }
-  if (!COMPLETE_TYPE_P (type))
+  if (!TYPE_SIZE (type))
     {
-      reject (var, "has incomplete type");
+      reject (var, "type size unknown");
       return false;
     }
   if (!tree_fits_uhwi_p (TYPE_SIZE (type)))
@@ -4176,7 +4176,7 @@  find_param_candidates (void)
       else if (!AGGREGATE_TYPE_P (type))
 	continue;
 
-      if (!COMPLETE_TYPE_P (type)
+      if (!TYPE_SIZE (type)
 	  || !tree_fits_uhwi_p (TYPE_SIZE (type))
           || tree_to_uhwi (TYPE_SIZE (type)) == 0
 	  || (AGGREGATE_TYPE_P (type)
Index: gcc/tree-ssa-alias.c
===================================================================
--- gcc/tree-ssa-alias.c	2018-09-10 17:38:19.470814110 +0100
+++ gcc/tree-ssa-alias.c	2018-10-15 14:12:54.040553089 +0100
@@ -1182,7 +1182,8 @@  indirect_ref_may_alias_decl_p (tree ref1
   /* If the size of the access relevant for TBAA through the pointer
      is bigger than the size of the decl we can't possibly access the
      decl via that pointer.  */
-  if (DECL_SIZE (base2) && COMPLETE_TYPE_P (TREE_TYPE (ptrtype1))
+  if (DECL_SIZE (base2)
+      && TYPE_SIZE (TREE_TYPE (ptrtype1))
       && poly_int_tree_p (DECL_SIZE (base2))
       && poly_int_tree_p (TYPE_SIZE (TREE_TYPE (ptrtype1)))
       /* ???  This in turn may run afoul when a decl of type T which is
Index: gcc/tree-vrp.c
===================================================================
--- gcc/tree-vrp.c	2018-10-05 13:46:08.215811700 +0100
+++ gcc/tree-vrp.c	2018-10-15 14:12:54.044553056 +0100
@@ -4412,7 +4412,7 @@  vrp_prop::check_mem_ref (location_t loca
      not known.  */
   tree reftype = TREE_TYPE (arg);
   if (POINTER_TYPE_P (reftype)
-      || !COMPLETE_TYPE_P (reftype)
+      || !TYPE_SIZE_UNIT (reftype)
       || TREE_CODE (TYPE_SIZE_UNIT (reftype)) != INTEGER_CST
       || RECORD_OR_UNION_TYPE_P (reftype))
     return;
Index: gcc/lto/lto-symtab.c
===================================================================
--- gcc/lto/lto-symtab.c	2018-08-28 11:25:46.034881666 +0100
+++ gcc/lto/lto-symtab.c	2018-10-15 14:12:54.040553089 +0100
@@ -243,8 +243,8 @@  warn_type_compatibility_p (tree prevaili
   /* We can not use types_compatible_p because we permit some changes
      across types.  For example unsigned size_t and "signed size_t" may be
      compatible when merging C and Fortran types.  */
-  if (COMPLETE_TYPE_P (prevailing_type)
-      && COMPLETE_TYPE_P (type)
+  if (TYPE_SIZE (type)
+      && TYPE_SIZE (prevailing_type)
       /* While global declarations are never variadic, we can recurse here
 	 for function parameter types.  */
       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST