Commit 1a8c909e by Eric Botcazou Committed by Eric Botcazou

varasm.c (initializer_constant_valid_p): Forbid view-conversions from aggregate…

varasm.c (initializer_constant_valid_p): Forbid view-conversions from aggregate to non-aggregate type if...

	* varasm.c (initializer_constant_valid_p): Forbid view-conversions
	from aggregate to non-aggregate type if the bit pattern is not fully
	preserved afterwards.

From-SVN: r140432
parent 9f509004
2008-09-17 Eric Botcazou <ebotcazou@adacore.com>
* varasm.c (initializer_constant_valid_p): Forbid view-conversions
from aggregate to non-aggregate type if the bit pattern is not fully
preserved afterwards.
2008-09-17 Richard Guenther <rguenther@suse.de>
* tree-cfg.c (verify_types_in_gimple_assign): Rename to ...
......
2008-09-17 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/specs/static_initializer3.ads: New test.
2008-09-17 Jakub Jelinek <jakub@redhat.com>
PR c++/37552
......
with Unchecked_Conversion;
package Static_Initializer3 is
type Byte is range 0 .. 16#FF#;
for Byte'Size use 8;
type Word is range 0 .. 16#FFFF# ;
for Word'Size use 16;
type R is record
b1 : Boolean;
b2 : Boolean;
end record;
for R use record
b1 at 0 range 0..3;
b2 at 0 range 4..7;
end record;
for R'Size use 8;
function Conv is new Unchecked_Conversion (R, Byte);
C1 : constant Byte := Conv ((true, false));
C2 : constant Word := Word(C1);
end Static_Initializer3;
......@@ -4205,19 +4205,36 @@ initializer_constant_valid_p (tree value, tree endtype)
return op0;
}
case VIEW_CONVERT_EXPR:
case NON_LVALUE_EXPR:
return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
CASE_CONVERT:
case VIEW_CONVERT_EXPR:
{
tree src;
tree src_type;
tree dest_type;
tree src = TREE_OPERAND (value, 0);
tree src_type = TREE_TYPE (src);
tree dest_type = TREE_TYPE (value);
/* Allow view-conversions from aggregate to non-aggregate type only
if the bit pattern is fully preserved afterwards; otherwise, the
RTL expander won't be able to apply a subsequent transformation
to the underlying constructor. */
if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
{
if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
return initializer_constant_valid_p (src, endtype);
else
return NULL_TREE;
}
/* Allow all other kinds of view-conversion. */
return initializer_constant_valid_p (src, endtype);
}
src = TREE_OPERAND (value, 0);
src_type = TREE_TYPE (src);
dest_type = TREE_TYPE (value);
CASE_CONVERT:
{
tree src = TREE_OPERAND (value, 0);
tree src_type = TREE_TYPE (src);
tree dest_type = TREE_TYPE (value);
/* Allow conversions between pointer types, floating-point
types, and offset types. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment