From patchwork Wed Mar 28 14:53:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Add support for FP bit fields in varasm.c Date: Wed, 28 Mar 2012 04:53:25 -0000 From: Eric Botcazou X-Patchwork-Id: 149255 Message-Id: <201203281653.25712.ebotcazou@adacore.com> To: gcc-patches@gcc.gnu.org Hi, another kind of bit fields supported in Ada are floating-point bit fields. They work fine, except that varasm.c rejects static constants (CONSTRUCTORs) containing them. The attached patch plugs this hole. Tested on x86_64-suse-linux, OK for mainline? 2012-03-28 Eric Botcazou * varasm.c (initializer_constant_valid_for_bitfield_p): Return true for REAL_CST as well. (output_constructor): Use RECORD_OR_UNION_TYPE_P predicate. In the bitfield case, if the value is a REAL_CST, convert it first to an INTEGER_CST. 2012-03-28 Eric Botcazou * gnat.dg/specs/aggr5.ads: New test. Index: varasm.c =================================================================== --- varasm.c (revision 185857) +++ 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,17 @@ 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_build1 (VIEW_CONVERT_EXPR, + make_signed_type + (TYPE_PRECISION (TREE_TYPE (local.val))), + local.val); + output_constructor_bitfield (&local, outer); + } } /* If we are not at toplevel, save the pending data for our caller.