summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>2012-04-03 07:11:25 +0000
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>2012-04-03 07:11:25 +0000
commit766b6590b051392781bb0b54cd681881e0f52979 (patch)
tree04901eeaa9d8ac54f5ff6b1fa3f4f9265e4ff0a4
parent6fa78bde865ab12cfbd085f4db86af7c4a75c301 (diff)
downloadgcc-766b6590b051392781bb0b54cd681881e0f52979.tar.gz
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@186100 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gnat.dg/specs/aggr5.ads19
-rw-r--r--gcc/varasm.c19
4 files changed, 44 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5c4e04e87c5..96bcc5c6398 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2012-04-03 Eric Botcazou <ebotcazou@adacore.com>
+
+ * 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-04-02 H.J. Lu <hongjiu.lu@intel.com>
* config.gcc: Use i386/biarchx32.h instead of i386/biarch64.h
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a10bea7efce..5a5ee575a44 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2012-04-03 Eric Botcazou <ebotcazou@adacore.com>
+
+ * gnat.dg/specs/aggr5.ads: New test.
+
2012-04-02 Richard Guenther <rguenther@suse.de>
PR tree-optimization/52756
diff --git a/gcc/testsuite/gnat.dg/specs/aggr5.ads b/gcc/testsuite/gnat.dg/specs/aggr5.ads
new file mode 100644
index 00000000000..ba1e695bca2
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/aggr5.ads
@@ -0,0 +1,19 @@
+-- { dg-do compile }
+
+pragma Restrictions (No_Elaboration_Code);
+
+package Aggr5 is
+
+ type R is record
+ C : Character;
+ F : Float;
+ end record;
+
+ for R use record
+ C at 0 range 0 .. 7;
+ F at 1 range 0 .. 31;
+ end record;
+
+ My_R : R := (C => 'A', F => 1.0);
+
+end Aggr5;
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 0c04de47974..34ed948cade 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -4420,6 +4420,7 @@ initializer_constant_valid_for_bitfield_p (tree value)
}
case INTEGER_CST:
+ case REAL_CST:
return true;
case VIEW_CONVERT_EXPR:
@@ -5075,10 +5076,7 @@ output_constructor (tree exp, unsigned HOST_WIDE_INT size,
/* 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 HOST_WIDE_INT size,
|| !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.