public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Do not use lang_hooks.types.type_for_size in signed_or_unsigned_type_for
@ 2012-03-07 12:23 Richard Guenther
  2012-03-07 14:24 ` Michael Matz
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Guenther @ 2012-03-07 12:23 UTC (permalink / raw)
  To: gcc-patches


This makes us use build_nonstandard_integer_type in 
signed_or_unsigned_type_for and adjusts the function to return
NULL_TREE for non-sensical inputs (only allowing pointer and
integeral types).  This way we make sure that the precision of
the result type matches that of the input - something which
fold-const.c definitely expects for example (it uses type_for_size
itself if it doesn't).

In the long run type_for_size should go - or it should be a
wrapper that calls type_for_mode (int_mode_for_size ()) instead.
I'm working towards that.

Bootstrapped and tested on x86_64-unknown-linux-gnu for all languages.

I get

FAIL: gcc.dg/tree-ssa/pr31261.c scan-tree-dump-times original "return 
\\(char\\)
 -\\(unsigned char\\) c & 31;" 1
FAIL: gcc.dg/tree-ssa/pr31261.c scan-tree-dump-times original "return 
\\(int\\) 
\\(12 - \\(unsigned int\\) d\\) & 7;" 1

because we dump the unsigned type variant differently now.  What do
people think - adjust the testcase?  Adjust how we pretty-print
these non-standard integer types?

Thanks,
Richard.

2012-03-07  Richard Guenther  <rguenther@suse.de>

	* tree.c (signed_or_unsigned_type_for): Use
	build_nonstandard_integer_type.
	(signed_type_for): Adjust documentation.
	(unsigned_type_for): Likewise.

Index: gcc/tree.c
===================================================================
*** gcc/tree.c	(revision 185029)
--- gcc/tree.c	(working copy)
*************** widest_int_cst_value (const_tree x)
*** 10197,10228 ****
    return val;
  }
  
! /* If TYPE is an integral type, return an equivalent type which is
!     unsigned iff UNSIGNEDP is true.  If TYPE is not an integral type,
!     return TYPE itself.  */
  
  tree
  signed_or_unsigned_type_for (int unsignedp, tree type)
  {
!   tree t = type;
!   if (POINTER_TYPE_P (type))
!     {
!       /* If the pointer points to the normal address space, use the
! 	 size_type_node.  Otherwise use an appropriate size for the pointer
! 	 based on the named address space it points to.  */
!       if (!TYPE_ADDR_SPACE (TREE_TYPE (t)))
! 	t = size_type_node;
!       else
! 	return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp);
!     }
  
!   if (!INTEGRAL_TYPE_P (t) || TYPE_UNSIGNED (t) == unsignedp)
!     return t;
  
!   return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp);
  }
  
! /* Returns unsigned variant of TYPE.  */
  
  tree
  unsigned_type_for (tree type)
--- 10197,10222 ----
    return val;
  }
  
! /* If TYPE is an integral or pointer type, return an integer type with
!    the same precision which is unsigned iff UNSIGNEDP is true, or itself
!    if TYPE is already an integer type of signedness UNSIGNEDP.  */
  
  tree
  signed_or_unsigned_type_for (int unsignedp, tree type)
  {
!   if (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type) == unsignedp)
!     return type;
  
!   if (!INTEGRAL_TYPE_P (type)
!       && !POINTER_TYPE_P (type))
!     return NULL_TREE;
  
!   return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
  }
  
! /* If TYPE is an integral or pointer type, return an integer type with
!    the same precision which is unsigned, or itself if TYPE is already an
!    unsigned integer type.  */
  
  tree
  unsigned_type_for (tree type)
*************** unsigned_type_for (tree type)
*** 10230,10236 ****
    return signed_or_unsigned_type_for (1, type);
  }
  
! /* Returns signed variant of TYPE.  */
  
  tree
  signed_type_for (tree type)
--- 10224,10232 ----
    return signed_or_unsigned_type_for (1, type);
  }
  
! /* If TYPE is an integral or pointer type, return an integer type with
!    the same precision which is signed, or itself if TYPE is already a
!    signed integer type.  */
  
  tree
  signed_type_for (tree type)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Do not use lang_hooks.types.type_for_size in signed_or_unsigned_type_for
  2012-03-07 12:23 [PATCH] Do not use lang_hooks.types.type_for_size in signed_or_unsigned_type_for Richard Guenther
@ 2012-03-07 14:24 ` Michael Matz
  2012-03-07 14:26   ` Richard Guenther
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Matz @ 2012-03-07 14:24 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches

Hi,

On Wed, 7 Mar 2012, Richard Guenther wrote:

> FAIL: gcc.dg/tree-ssa/pr31261.c scan-tree-dump-times original "return 
> \\(char\\)
>  -\\(unsigned char\\) c & 31;" 1
> FAIL: gcc.dg/tree-ssa/pr31261.c scan-tree-dump-times original "return 
> \\(int\\) 
> \\(12 - \\(unsigned int\\) d\\) & 7;" 1
> 
> because we dump the unsigned type variant differently now.  What do
> people think - adjust the testcase?  Adjust how we pretty-print
> these non-standard integer types?

Adjusting the pretty printer would be nice anyway.  Those <unnamed>:35 
thingies hurt my eyes.  Just printing int17 or uint18 would be perfectly 
fine, with special casing of sizes that match the normal C types for 
the target in question (so that input 'unsigned char' isn't converted to 
'uint8' on one and 'uint16' on another target).


Ciao,
Michael.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Do not use lang_hooks.types.type_for_size in signed_or_unsigned_type_for
  2012-03-07 14:24 ` Michael Matz
@ 2012-03-07 14:26   ` Richard Guenther
  2012-03-12 12:44     ` Richard Guenther
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Guenther @ 2012-03-07 14:26 UTC (permalink / raw)
  To: Michael Matz; +Cc: gcc-patches

On Wed, 7 Mar 2012, Michael Matz wrote:

> Hi,
> 
> On Wed, 7 Mar 2012, Richard Guenther wrote:
> 
> > FAIL: gcc.dg/tree-ssa/pr31261.c scan-tree-dump-times original "return 
> > \\(char\\)
> >  -\\(unsigned char\\) c & 31;" 1
> > FAIL: gcc.dg/tree-ssa/pr31261.c scan-tree-dump-times original "return 
> > \\(int\\) 
> > \\(12 - \\(unsigned int\\) d\\) & 7;" 1
> > 
> > because we dump the unsigned type variant differently now.  What do
> > people think - adjust the testcase?  Adjust how we pretty-print
> > these non-standard integer types?
> 
> Adjusting the pretty printer would be nice anyway.  Those <unnamed>:35 
> thingies hurt my eyes.  Just printing int17 or uint18 would be perfectly 
> fine, with special casing of sizes that match the normal C types for 
> the target in question (so that input 'unsigned char' isn't converted to 
> 'uint8' on one and 'uint16' on another target).

Ok, I'll do that (special-casing some precisions via *_TYPE_SIZE).
I won't touch the <unnamed-unsigned-type:35> stuff, for now.

Richard.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Do not use lang_hooks.types.type_for_size in signed_or_unsigned_type_for
  2012-03-07 14:26   ` Richard Guenther
@ 2012-03-12 12:44     ` Richard Guenther
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Guenther @ 2012-03-12 12:44 UTC (permalink / raw)
  To: Michael Matz; +Cc: gcc-patches

On Wed, 7 Mar 2012, Richard Guenther wrote:

> On Wed, 7 Mar 2012, Michael Matz wrote:
> 
> > Hi,
> > 
> > On Wed, 7 Mar 2012, Richard Guenther wrote:
> > 
> > > FAIL: gcc.dg/tree-ssa/pr31261.c scan-tree-dump-times original "return 
> > > \\(char\\)
> > >  -\\(unsigned char\\) c & 31;" 1
> > > FAIL: gcc.dg/tree-ssa/pr31261.c scan-tree-dump-times original "return 
> > > \\(int\\) 
> > > \\(12 - \\(unsigned int\\) d\\) & 7;" 1
> > > 
> > > because we dump the unsigned type variant differently now.  What do
> > > people think - adjust the testcase?  Adjust how we pretty-print
> > > these non-standard integer types?
> > 
> > Adjusting the pretty printer would be nice anyway.  Those <unnamed>:35 
> > thingies hurt my eyes.  Just printing int17 or uint18 would be perfectly 
> > fine, with special casing of sizes that match the normal C types for 
> > the target in question (so that input 'unsigned char' isn't converted to 
> > 'uint8' on one and 'uint16' on another target).
> 
> Ok, I'll do that (special-casing some precisions via *_TYPE_SIZE).
> I won't touch the <unnamed-unsigned-type:35> stuff, for now.

Like so.

Richard.

2012-03-12  Richard Guenther  <rguenther@suse.de>

	* tree.c (signed_or_unsigned_type_for): Use
	build_nonstandard_integer_type.
	(signed_type_for): Adjust documentation.
	(unsigned_type_for): Likewise.
	* tree-pretty-print.c (dump_generic_node): Use standard names
	for non-standard integer types if available.

Index: gcc/tree.c
===================================================================
*** gcc/tree.c.orig	2012-03-12 11:11:36.000000000 +0100
--- gcc/tree.c	2012-03-12 12:25:37.000000000 +0100
*************** widest_int_cst_value (const_tree x)
*** 10197,10228 ****
    return val;
  }
  
! /* If TYPE is an integral type, return an equivalent type which is
!     unsigned iff UNSIGNEDP is true.  If TYPE is not an integral type,
!     return TYPE itself.  */
  
  tree
  signed_or_unsigned_type_for (int unsignedp, tree type)
  {
!   tree t = type;
!   if (POINTER_TYPE_P (type))
!     {
!       /* If the pointer points to the normal address space, use the
! 	 size_type_node.  Otherwise use an appropriate size for the pointer
! 	 based on the named address space it points to.  */
!       if (!TYPE_ADDR_SPACE (TREE_TYPE (t)))
! 	t = size_type_node;
!       else
! 	return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp);
!     }
  
!   if (!INTEGRAL_TYPE_P (t) || TYPE_UNSIGNED (t) == unsignedp)
!     return t;
  
!   return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp);
  }
  
! /* Returns unsigned variant of TYPE.  */
  
  tree
  unsigned_type_for (tree type)
--- 10197,10222 ----
    return val;
  }
  
! /* If TYPE is an integral or pointer type, return an integer type with
!    the same precision which is unsigned iff UNSIGNEDP is true, or itself
!    if TYPE is already an integer type of signedness UNSIGNEDP.  */
  
  tree
  signed_or_unsigned_type_for (int unsignedp, tree type)
  {
!   if (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type) == unsignedp)
!     return type;
  
!   if (!INTEGRAL_TYPE_P (type)
!       && !POINTER_TYPE_P (type))
!     return NULL_TREE;
  
!   return build_nonstandard_integer_type (TYPE_PRECISION (type), unsignedp);
  }
  
! /* If TYPE is an integral or pointer type, return an integer type with
!    the same precision which is unsigned, or itself if TYPE is already an
!    unsigned integer type.  */
  
  tree
  unsigned_type_for (tree type)
*************** unsigned_type_for (tree type)
*** 10230,10236 ****
    return signed_or_unsigned_type_for (1, type);
  }
  
! /* Returns signed variant of TYPE.  */
  
  tree
  signed_type_for (tree type)
--- 10224,10232 ----
    return signed_or_unsigned_type_for (1, type);
  }
  
! /* If TYPE is an integral or pointer type, return an integer type with
!    the same precision which is signed, or itself if TYPE is already a
!    signed integer type.  */
  
  tree
  signed_type_for (tree type)
Index: gcc/tree-pretty-print.c
===================================================================
*** gcc/tree-pretty-print.c.orig	2012-01-30 14:44:40.000000000 +0100
--- gcc/tree-pretty-print.c	2012-03-12 12:34:01.000000000 +0100
*************** dump_generic_node (pretty_printer *buffe
*** 723,733 ****
  	      }
  	    else if (TREE_CODE (node) == INTEGER_TYPE)
  	      {
! 		pp_string (buffer, (TYPE_UNSIGNED (node)
! 				    ? "<unnamed-unsigned:"
! 				    : "<unnamed-signed:"));
! 		pp_decimal_int (buffer, TYPE_PRECISION (node));
! 		pp_string (buffer, ">");
  	      }
  	    else if (TREE_CODE (node) == COMPLEX_TYPE)
  	      {
--- 723,763 ----
  	      }
  	    else if (TREE_CODE (node) == INTEGER_TYPE)
  	      {
! 		if (TYPE_PRECISION (node) == CHAR_TYPE_SIZE)
! 		  pp_string (buffer, (TYPE_UNSIGNED (node)
! 				      ? "unsigned char"
! 				      : "signed char"));
! 		else if (TYPE_PRECISION (node) == SHORT_TYPE_SIZE)
! 		  pp_string (buffer, (TYPE_UNSIGNED (node)
! 				      ? "unsigned short"
! 				      : "signed short"));
! 		else if (TYPE_PRECISION (node) == INT_TYPE_SIZE)
! 		  pp_string (buffer, (TYPE_UNSIGNED (node)
! 				      ? "unsigned int"
! 				      : "signed int"));
! 		else if (TYPE_PRECISION (node) == LONG_TYPE_SIZE)
! 		  pp_string (buffer, (TYPE_UNSIGNED (node)
! 				      ? "unsigned long"
! 				      : "signed long"));
! 		else if (TYPE_PRECISION (node) == LONG_LONG_TYPE_SIZE)
! 		  pp_string (buffer, (TYPE_UNSIGNED (node)
! 				      ? "unsigned long long"
! 				      : "signed long long"));
! 		else if (TYPE_PRECISION (node) >= CHAR_TYPE_SIZE
! 			 && exact_log2 (TYPE_PRECISION (node)))
! 		  {
! 		    pp_string (buffer, (TYPE_UNSIGNED (node) ? "uint" : "int"));
! 		    pp_decimal_int (buffer, TYPE_PRECISION (node));
! 		    pp_string (buffer, "_t");
! 		  }
! 		else
! 		  {
! 		    pp_string (buffer, (TYPE_UNSIGNED (node)
! 					? "<unnamed-unsigned:"
! 					: "<unnamed-signed:"));
! 		    pp_decimal_int (buffer, TYPE_PRECISION (node));
! 		    pp_string (buffer, ">");
! 		  }
  	      }
  	    else if (TREE_CODE (node) == COMPLEX_TYPE)
  	      {

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-03-12 12:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-07 12:23 [PATCH] Do not use lang_hooks.types.type_for_size in signed_or_unsigned_type_for Richard Guenther
2012-03-07 14:24 ` Michael Matz
2012-03-07 14:26   ` Richard Guenther
2012-03-12 12:44     ` Richard Guenther

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).