diff mbox

[c] Remove unnecessary host_integerp check

Message ID 874n7er9sq.fsf@sandifor-thinkpad.stglab.manchester.uk.ibm.com
State New
Headers show

Commit Message

Richard Sandiford Nov. 14, 2013, 8:46 p.m. UTC
pp_c_character_constant only calls pp_p_char for values that fit into
a HWI of the constant's signedness (i.e. an unsigned HWI if TYPE_UNSIGNED
and a signed HWI otherwise).  But pp_c_character_constant is only called by:

    case INTEGER_CST:
      {
	tree type = TREE_TYPE (e);
        ...
	else if (type == char_type_node)
	  pp_c_character_constant (this, e);

and in practice a character constant is always going to fit into a HWI.
The current !host_integerp case simply truncates the constant to an
unsigned int anyway.

Maybe the type == wchar_type_node test is dead too, I'm not sure.
I'm happy to remove it at the same time if that seems like the right
thing to do.

Tested on x86_64-linux-gnu.  OK to install?

Thanks,
Richard


gcc/c-family/
	* c-pretty-print.c (pp_c_character_constant): Remove unnecessary
	host_integerp check.

Comments

Jeff Law Nov. 14, 2013, 9:37 p.m. UTC | #1
On 11/14/13 13:46, Richard Sandiford wrote:
> pp_c_character_constant only calls pp_p_char for values that fit into
> a HWI of the constant's signedness (i.e. an unsigned HWI if TYPE_UNSIGNED
> and a signed HWI otherwise).  But pp_c_character_constant is only called by:
>
>      case INTEGER_CST:
>        {
> 	tree type = TREE_TYPE (e);
>          ...
> 	else if (type == char_type_node)
> 	  pp_c_character_constant (this, e);
>
> and in practice a character constant is always going to fit into a HWI.
> The current !host_integerp case simply truncates the constant to an
> unsigned int anyway.
>
> Maybe the type == wchar_type_node test is dead too, I'm not sure.
> I'm happy to remove it at the same time if that seems like the right
> thing to do.
>
> Tested on x86_64-linux-gnu.  OK to install?
>
> Thanks,
> Richard
>
>
> gcc/c-family/
> 	* c-pretty-print.c (pp_c_character_constant): Remove unnecessary
> 	host_integerp check.
Fine by me.  Your call on the type == wchar_type_code.

jeff
diff mbox

Patch

Index: gcc/c-family/c-pretty-print.c
===================================================================
--- gcc/c-family/c-pretty-print.c	2013-11-14 20:21:27.183058648 +0000
+++ gcc/c-family/c-pretty-print.c	2013-11-14 20:22:20.664818284 +0000
@@ -954,10 +954,7 @@  pp_c_character_constant (c_pretty_printe
   if (type == wchar_type_node)
     pp_character (pp, 'L');
   pp_quote (pp);
-  if (host_integerp (c, TYPE_UNSIGNED (type)))
-    pp_c_char (pp, tree_low_cst (c, TYPE_UNSIGNED (type)));
-  else
-    pp_scalar (pp, "\\x%x", (unsigned) TREE_INT_CST_LOW (c));
+  pp_c_char (pp, (unsigned) TREE_INT_CST_LOW (c));
   pp_quote (pp);
 }