RFA: Fix PR c++/46634
diff mbox

Message ID 20101124043940.y5q6ojjoaoooo44w-nzlynne@webmail.spamcop.net
State New
Headers show

Commit Message

Joern Rennecke Nov. 24, 2010, 9:39 a.m. UTC
Bootstrapped and regression tested on i686-pc-linux.gnu.
2010-11-22  Joern Rennecke  <amylaar@spamcop.net>

	PR c++/46634
	* typeck2.c (digest_init_r):
	Use TYPE_PRECISION (char_type_node) as the size of char.

Comments

Joseph Myers Nov. 24, 2010, 3:51 p.m. UTC | #1
I can't approve this, but:

On Wed, 24 Nov 2010, Joern Rennecke wrote:

> @@ -881,7 +881,7 @@ digest_init_r (tree type, tree init, boo
>  	{
>  	  tree char_type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (init)));
>  
> -	  if (TYPE_PRECISION (typ1) == BITS_PER_UNIT)
> +	  if (TYPE_PRECISION (typ1) == TYPE_PRECISION (char_type_node))
>  	    {
>  	      if (char_type != char_type_node)
>  		{

I think this is correct.

> @@ -907,7 +907,9 @@ digest_init_r (tree type, tree init, boo
>  	  if (TYPE_DOMAIN (type) != 0 && TREE_CONSTANT (TYPE_SIZE (type)))
>  	    {
>  	      int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
> -	      size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
> +	      unsigned char_size = TYPE_PRECISION (char_type_node);
> +
> +	      size = (size + char_size - 1) / char_size;

I think this is wrong, as I think TREE_STRING_LENGTH does count in 
BITS_PER_UNIT.

Patch
diff mbox

Index: gcc/gcc/cp/typeck2.c
===================================================================
--- gcc/gcc/cp/typeck2.c	(revision 167107)
+++ gcc/gcc/cp/typeck2.c	(working copy)
@@ -881,7 +881,7 @@  digest_init_r (tree type, tree init, boo
 	{
 	  tree char_type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (init)));
 
-	  if (TYPE_PRECISION (typ1) == BITS_PER_UNIT)
+	  if (TYPE_PRECISION (typ1) == TYPE_PRECISION (char_type_node))
 	    {
 	      if (char_type != char_type_node)
 		{
@@ -907,7 +907,9 @@  digest_init_r (tree type, tree init, boo
 	  if (TYPE_DOMAIN (type) != 0 && TREE_CONSTANT (TYPE_SIZE (type)))
 	    {
 	      int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
-	      size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
+	      unsigned char_size = TYPE_PRECISION (char_type_node);
+
+	      size = (size + char_size - 1) / char_size;
 	      /* In C it is ok to subtract 1 from the length of the string
 		 because it's ok to ignore the terminating null char that is
 		 counted in the length of the constant, but in C++ this would