Patchwork Add support for FP bit fields in varasm.c

login
register
mail settings
Submitter Eric Botcazou
Date April 2, 2012, 10:57 a.m.
Message ID <201204021257.47162.ebotcazou@adacore.com>
Download mbox | patch
Permalink /patch/150109/
State New
Headers show

Comments

Eric Botcazou - April 2, 2012, 10:57 a.m.
> You should be able to use fold_unary instead of fold_build1. 
> make_signed_type should also not be used, but
> build_nonstandard_integer_type (or even better, get an integer mode of the
> same size of the float mode and then use type_for_mode).

Using the mode size wouldn't work directly for XFmode on x86.  Moreover the 
precision seems to be the right property in this bit-field context.

Adjusted patch attached, tested on i586-suse-linux, OK for mainline?
Richard Guenther - April 2, 2012, 11:40 a.m.
On Mon, Apr 2, 2012 at 12:57 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
>> You should be able to use fold_unary instead of fold_build1.
>> make_signed_type should also not be used, but
>> build_nonstandard_integer_type (or even better, get an integer mode of the
>> same size of the float mode and then use type_for_mode).
>
> Using the mode size wouldn't work directly for XFmode on x86.  Moreover the
> precision seems to be the right property in this bit-field context.
>
> Adjusted patch attached, tested on i586-suse-linux, OK for mainline?

Ok.

Thanks,
Richard.

> --
> Eric Botcazou

Patch

Index: varasm.c
===================================================================
--- varasm.c	(revision 186054)
+++ varasm.c	(working copy)
@@ -4420,6 +4420,7 @@  initializer_constant_valid_for_bitfield_
       }
 
     case INTEGER_CST:
+    case REAL_CST:
       return true;
 
     case VIEW_CONVERT_EXPR:
@@ -5075,10 +5076,7 @@  output_constructor (tree exp, unsigned H
 
       /* The element in a union constructor specifies the proper field
 	 or index.  */
-      if ((TREE_CODE (local.type) == RECORD_TYPE
-	   || TREE_CODE (local.type) == UNION_TYPE
-	   || TREE_CODE (local.type) == QUAL_UNION_TYPE)
-	  && ce->index != NULL_TREE)
+      if (RECORD_OR_UNION_TYPE_P (local.type) && ce->index != NULL_TREE)
 	local.field = ce->index;
 
       else if (TREE_CODE (local.type) == ARRAY_TYPE)
@@ -5110,9 +5108,18 @@  output_constructor (tree exp, unsigned H
 		   || !CONSTRUCTOR_BITFIELD_P (local.field)))
 	output_constructor_regular_field (&local);
 
-      /* For a true bitfield or part of an outer one.  */
+      /* For a true bitfield or part of an outer one.  Only INTEGER_CSTs are
+	 supported for scalar fields, so we may need to convert first.  */
       else
-	output_constructor_bitfield (&local, outer);
+        {
+	  if (TREE_CODE (local.val) == REAL_CST)
+	    local.val
+	      = fold_unary (VIEW_CONVERT_EXPR,
+			    build_nonstandard_integer_type
+			    (TYPE_PRECISION (TREE_TYPE (local.val)), 0),
+			    local.val);
+	  output_constructor_bitfield (&local, outer);
+	}
     }
 
   /* If we are not at toplevel, save the pending data for our caller.