change initialization of ptrdiff_type_node

Message ID CAAgBjMkp2_qq5Ton3KVAQMPFqTKmZVjMrO365Ki3JX=0qhMcMQ@mail.gmail.com
State New
Headers show

Commit Message

Prathamesh Kulkarni Nov. 25, 2016, 7:58 a.m.
Hi,
This patch changes initialization of ptrdiff_type_node in lto-lang.c, based on
Jakub's suggestion in PR78501 comment 12:
"The other uses of ptrdiff_type_node in the middle-end, which need
fixing anyway, would need something like your patch, but not sure if
it is not a waste of time to compute it if the C/C++ FE will
immediately override it anyway.

So perhaps just compute it that way in the LTO FE?
I mean, for the *printf warning/length stuff, those calls shouldn't
appear in Ada/Go/Fortran code, they can in LTO or C-family."

For unsigned_ptrdiff_type_node, I removed it's definition from
c-common.h and moved
it to tree.h.
Is that OK ?

Thanks,
Prathamesh
2016-11-25  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

	* tree-core.h (TI_UNSIGNED_PTRDIFF_TYPE): New enum value.
	* tree.h (unsigned_ptrdiff_type_node): New macro.
c-family/
	* c-common.h (CTI_UNSIGNED_PTRDIFF_TYPE): Remove.
	(unsigned_ptrdiff_type_node): Likewise.
lto/
	* lto-lang.c (lto_init): Change initialization of ptrdiff_type_node.
	Initialize unsigned_ptrdiff_type_node.

Comments

Jakub Jelinek Nov. 25, 2016, 8:05 a.m. | #1
On Fri, Nov 25, 2016 at 01:28:06PM +0530, Prathamesh Kulkarni wrote:
> --- a/gcc/lto/lto-lang.c

> +++ b/gcc/lto/lto-lang.c

> @@ -1271,8 +1271,30 @@ lto_init (void)

>    gcc_assert (TYPE_MAIN_VARIANT (const_tm_ptr_type_node)

>  	      == const_ptr_type_node);

>  

> -  ptrdiff_type_node = integer_type_node;

> +  if (strcmp (PTRDIFF_TYPE, "int") == 0)

> +    ptrdiff_type_node = integer_type_node;

> +  else if (strcmp (PTRDIFF_TYPE, "long int") == 0)

> +    ptrdiff_type_node = long_integer_type_node;

> +  else if (strcmp (PTRDIFF_TYPE, "long long int") == 0)

> +    ptrdiff_type_node = long_long_integer_type_node;

> +  else if (strcmp (PTRDIFF_TYPE, "short int") == 0)

> +    ptrdiff_type_node = short_integer_type_node;

> +  else

> +    {

> +      ptrdiff_type_node = NULL_TREE;

> +      for (int i = 0; i < NUM_INT_N_ENTS; i++)

> +	if (int_n_enabled_p[i])

> +	  {

> +	    char name[50];

> +	    sprintf (name, "__int%d", int_n_data[i].bitsize);

> +	    if (strcmp (name, PTRDIFF_TYPE) == 0)

> +	      ptrdiff_type_node = int_n_trees[i].signed_type;

> +	  }

> +      if (ptrdiff_type_node == NULL_TREE)

> +	gcc_unreachable ();

> +    }


This looks ok to me.

>  

> +  unsigned_ptrdiff_type_node = unsigned_type_for (ptrdiff_type_node);

>    lto_build_c_type_nodes ();

>    gcc_assert (va_list_type_node);


But why this and the remaining hunks?  Nothing in the middle-end
needs it, IMHO it should be kept in c-family/.

> diff --git a/gcc/tree-core.h b/gcc/tree-core.h

> index eec2d4f..6c52387 100644

> --- a/gcc/tree-core.h

> +++ b/gcc/tree-core.h

> @@ -617,6 +617,7 @@ enum tree_index {

>    TI_SIZE_TYPE,

>    TI_PID_TYPE,

>    TI_PTRDIFF_TYPE,

> +  TI_UNSIGNED_PTRDIFF_TYPE,

>    TI_VA_LIST_TYPE,

>    TI_VA_LIST_GPR_COUNTER_FIELD,

>    TI_VA_LIST_FPR_COUNTER_FIELD,

> diff --git a/gcc/tree.h b/gcc/tree.h

> index 62cd7bb..ae69d0d 100644

> --- a/gcc/tree.h

> +++ b/gcc/tree.h

> @@ -3667,6 +3667,7 @@ tree_operand_check_code (const_tree __t, enum tree_code __code, int __i,

>  #define size_type_node                  global_trees[TI_SIZE_TYPE]

>  #define pid_type_node                   global_trees[TI_PID_TYPE]

>  #define ptrdiff_type_node		global_trees[TI_PTRDIFF_TYPE]

> +#define unsigned_ptrdiff_type_node	global_trees[TI_UNSIGNED_PTRDIFF_TYPE]

>  #define va_list_type_node		global_trees[TI_VA_LIST_TYPE]

>  #define va_list_gpr_counter_field	global_trees[TI_VA_LIST_GPR_COUNTER_FIELD]

>  #define va_list_fpr_counter_field	global_trees[TI_VA_LIST_FPR_COUNTER_FIELD]



	Jakub
Richard Biener Nov. 25, 2016, 8:13 a.m. | #2
On Fri, 25 Nov 2016, Jakub Jelinek wrote:

> On Fri, Nov 25, 2016 at 01:28:06PM +0530, Prathamesh Kulkarni wrote:

> > --- a/gcc/lto/lto-lang.c

> > +++ b/gcc/lto/lto-lang.c

> > @@ -1271,8 +1271,30 @@ lto_init (void)

> >    gcc_assert (TYPE_MAIN_VARIANT (const_tm_ptr_type_node)

> >  	      == const_ptr_type_node);

> >  

> > -  ptrdiff_type_node = integer_type_node;

> > +  if (strcmp (PTRDIFF_TYPE, "int") == 0)

> > +    ptrdiff_type_node = integer_type_node;

> > +  else if (strcmp (PTRDIFF_TYPE, "long int") == 0)

> > +    ptrdiff_type_node = long_integer_type_node;

> > +  else if (strcmp (PTRDIFF_TYPE, "long long int") == 0)

> > +    ptrdiff_type_node = long_long_integer_type_node;

> > +  else if (strcmp (PTRDIFF_TYPE, "short int") == 0)

> > +    ptrdiff_type_node = short_integer_type_node;

> > +  else

> > +    {

> > +      ptrdiff_type_node = NULL_TREE;

> > +      for (int i = 0; i < NUM_INT_N_ENTS; i++)

> > +	if (int_n_enabled_p[i])

> > +	  {

> > +	    char name[50];

> > +	    sprintf (name, "__int%d", int_n_data[i].bitsize);

> > +	    if (strcmp (name, PTRDIFF_TYPE) == 0)

> > +	      ptrdiff_type_node = int_n_trees[i].signed_type;

> > +	  }

> > +      if (ptrdiff_type_node == NULL_TREE)

> > +	gcc_unreachable ();

> > +    }

> 

> This looks ok to me.


But I'd like to see this in build_common_tree_nodes alongside
the initialization of size_type_node (and thus removed from
c_common_nodes_and_builtins).  This way you can simply remove
the lto-lang.c code as well.

Please then also remove the ptrdiff_type_node re-set from
free_lang_data ().

> >  

> > +  unsigned_ptrdiff_type_node = unsigned_type_for (ptrdiff_type_node);

> >    lto_build_c_type_nodes ();

> >    gcc_assert (va_list_type_node);

> 

> But why this and the remaining hunks?  Nothing in the middle-end

> needs it, IMHO it should be kept in c-family/.


Yeah, this change looks unnecessary to me.

> > diff --git a/gcc/tree-core.h b/gcc/tree-core.h

> > index eec2d4f..6c52387 100644

> > --- a/gcc/tree-core.h

> > +++ b/gcc/tree-core.h

> > @@ -617,6 +617,7 @@ enum tree_index {

> >    TI_SIZE_TYPE,

> >    TI_PID_TYPE,

> >    TI_PTRDIFF_TYPE,

> > +  TI_UNSIGNED_PTRDIFF_TYPE,

> >    TI_VA_LIST_TYPE,

> >    TI_VA_LIST_GPR_COUNTER_FIELD,

> >    TI_VA_LIST_FPR_COUNTER_FIELD,

> > diff --git a/gcc/tree.h b/gcc/tree.h

> > index 62cd7bb..ae69d0d 100644

> > --- a/gcc/tree.h

> > +++ b/gcc/tree.h

> > @@ -3667,6 +3667,7 @@ tree_operand_check_code (const_tree __t, enum tree_code __code, int __i,

> >  #define size_type_node                  global_trees[TI_SIZE_TYPE]

> >  #define pid_type_node                   global_trees[TI_PID_TYPE]

> >  #define ptrdiff_type_node		global_trees[TI_PTRDIFF_TYPE]

> > +#define unsigned_ptrdiff_type_node	global_trees[TI_UNSIGNED_PTRDIFF_TYPE]

> >  #define va_list_type_node		global_trees[TI_VA_LIST_TYPE]

> >  #define va_list_gpr_counter_field	global_trees[TI_VA_LIST_GPR_COUNTER_FIELD]

> >  #define va_list_fpr_counter_field	global_trees[TI_VA_LIST_FPR_COUNTER_FIELD]

> 

> 

> 	Jakub

> 

> 


-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)

Patch hide | download patch | download mbox

diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index a23193e..e93a65a 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -289,7 +289,6 @@  enum c_tree_index
     CTI_UNDERLYING_WCHAR_TYPE,
     CTI_WINT_TYPE,
     CTI_SIGNED_SIZE_TYPE, /* For format checking only.  */
-    CTI_UNSIGNED_PTRDIFF_TYPE, /* For format checking only.  */
     CTI_INTMAX_TYPE,
     CTI_UINTMAX_TYPE,
     CTI_WIDEST_INT_LIT_TYPE,
@@ -432,7 +431,6 @@  extern const unsigned int num_c_common_reswords;
 #define underlying_wchar_type_node	c_global_trees[CTI_UNDERLYING_WCHAR_TYPE]
 #define wint_type_node			c_global_trees[CTI_WINT_TYPE]
 #define signed_size_type_node		c_global_trees[CTI_SIGNED_SIZE_TYPE]
-#define unsigned_ptrdiff_type_node	c_global_trees[CTI_UNSIGNED_PTRDIFF_TYPE]
 #define intmax_type_node		c_global_trees[CTI_INTMAX_TYPE]
 #define uintmax_type_node		c_global_trees[CTI_UINTMAX_TYPE]
 #define widest_integer_literal_type_node c_global_trees[CTI_WIDEST_INT_LIT_TYPE]
diff --git a/gcc/lto/lto-lang.c b/gcc/lto/lto-lang.c
index a5f04ba..09b6d18 100644
--- a/gcc/lto/lto-lang.c
+++ b/gcc/lto/lto-lang.c
@@ -1271,8 +1271,30 @@  lto_init (void)
   gcc_assert (TYPE_MAIN_VARIANT (const_tm_ptr_type_node)
 	      == const_ptr_type_node);
 
-  ptrdiff_type_node = integer_type_node;
+  if (strcmp (PTRDIFF_TYPE, "int") == 0)
+    ptrdiff_type_node = integer_type_node;
+  else if (strcmp (PTRDIFF_TYPE, "long int") == 0)
+    ptrdiff_type_node = long_integer_type_node;
+  else if (strcmp (PTRDIFF_TYPE, "long long int") == 0)
+    ptrdiff_type_node = long_long_integer_type_node;
+  else if (strcmp (PTRDIFF_TYPE, "short int") == 0)
+    ptrdiff_type_node = short_integer_type_node;
+  else
+    {
+      ptrdiff_type_node = NULL_TREE;
+      for (int i = 0; i < NUM_INT_N_ENTS; i++)
+	if (int_n_enabled_p[i])
+	  {
+	    char name[50];
+	    sprintf (name, "__int%d", int_n_data[i].bitsize);
+	    if (strcmp (name, PTRDIFF_TYPE) == 0)
+	      ptrdiff_type_node = int_n_trees[i].signed_type;
+	  }
+      if (ptrdiff_type_node == NULL_TREE)
+	gcc_unreachable ();
+    }
 
+  unsigned_ptrdiff_type_node = unsigned_type_for (ptrdiff_type_node);
   lto_build_c_type_nodes ();
   gcc_assert (va_list_type_node);
 
diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index eec2d4f..6c52387 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -617,6 +617,7 @@  enum tree_index {
   TI_SIZE_TYPE,
   TI_PID_TYPE,
   TI_PTRDIFF_TYPE,
+  TI_UNSIGNED_PTRDIFF_TYPE,
   TI_VA_LIST_TYPE,
   TI_VA_LIST_GPR_COUNTER_FIELD,
   TI_VA_LIST_FPR_COUNTER_FIELD,
diff --git a/gcc/tree.h b/gcc/tree.h
index 62cd7bb..ae69d0d 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3667,6 +3667,7 @@  tree_operand_check_code (const_tree __t, enum tree_code __code, int __i,
 #define size_type_node                  global_trees[TI_SIZE_TYPE]
 #define pid_type_node                   global_trees[TI_PID_TYPE]
 #define ptrdiff_type_node		global_trees[TI_PTRDIFF_TYPE]
+#define unsigned_ptrdiff_type_node	global_trees[TI_UNSIGNED_PTRDIFF_TYPE]
 #define va_list_type_node		global_trees[TI_VA_LIST_TYPE]
 #define va_list_gpr_counter_field	global_trees[TI_VA_LIST_GPR_COUNTER_FIELD]
 #define va_list_fpr_counter_field	global_trees[TI_VA_LIST_FPR_COUNTER_FIELD]