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
This commit is contained in:
parent
9f509004fc
commit
1a8c909ebd
4 changed files with 62 additions and 8 deletions
|
@ -1,3 +1,9 @@
|
|||
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 ...
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
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
|
||||
|
|
27
gcc/testsuite/gnat.dg/specs/static_initializer3.ads
Normal file
27
gcc/testsuite/gnat.dg/specs/static_initializer3.ads
Normal file
|
@ -0,0 +1,27 @@
|
|||
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;
|
33
gcc/varasm.c
33
gcc/varasm.c
|
@ -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 VIEW_CONVERT_EXPR:
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
CASE_CONVERT:
|
||||
{
|
||||
tree src;
|
||||
tree src_type;
|
||||
tree dest_type;
|
||||
|
||||
src = TREE_OPERAND (value, 0);
|
||||
src_type = TREE_TYPE (src);
|
||||
dest_type = TREE_TYPE (value);
|
||||
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. */
|
||||
|
|
Loading…
Add table
Reference in a new issue