This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Use proper type for temporary in expansion of COMPONENT_REF
- From: kenner at vlsi1 dot ultra dot nyu dot edu (Richard Kenner)
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 4 Mar 04 17:05:56 EST
- Subject: Use proper type for temporary in expansion of COMPONENT_REF
The details are in the comments for this patch.
Tested on x86-64.
The test case is the following Ada code:
package MX is
type Byte is range 0 .. 255;
for Byte'size use 8;
type Message_Data_T is record
X, Y : Integer;
end record;
type Message_T is record
M_Id : Byte;
M_Data : Message_Data_T;
end record;
for Message_T'Size use 8+64;
for Message_T use record
M_Id at 0 range 0..7;
M_Data at 1 range 0..63;
end record;
Global_Message_Data : Message_Data_T;
Data_Value : constant := 2;
procedure Initialize_Global_Message_Data;
end MX;
package body MX is
procedure Set_Global_Message_Data (M_Data : in Message_Data_T) is
begin
Global_Message_Data := M_Data;
end;
pragma Inline (Set_Global_Message_Data);
procedure Initialize_Global_Message_Data is
M : Message_T;
begin
M.M_Data.X := Data_Value;
M.M_Data.Y := Data_Value;
Set_Global_Message_Data (M.M_Data);
end;
end MX;
with MX;
procedure MX_Run is
begin
MX.Initialize_Global_Message_Data;
if MX.Global_Message_Data.X /= MX.Data_Value then
raise Program_Error;
end if;
if MX.Global_Message_Data.Y /= MX.Data_Value then
raise Constraint_Error;
end if;
end;
2004-03-04 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* expr.c (expand_expr_real, case COMPONENT_REF): Get proper type of
stack slot for temp used for result of BLKmode but in integral mode.
*** expr.c 3 Mar 2004 08:34:26 -0000 1.628
--- expr.c 3 Mar 2004 13:38:14 -0000
*************** expand_expr_real (tree exp, rtx target,
*** 7237,7246 ****
op0, 1);
if (mode == BLKmode)
{
! rtx new = assign_temp (build_qualified_type
! ((*lang_hooks.types.type_for_mode)
! (ext_mode, 0),
! TYPE_QUAL_CONST), 0, 1, 1);
emit_move_insn (new, op0);
--- 7237,7253 ----
op0, 1);
+ /* If the result type is BLKmode, store the data into a temporary
+ of the appropriate type, but with the mode corresponding to the
+ mode for the data we have (op0's mode). It's tempting to make
+ this a constant type, since we know it's only being stored once,
+ but that can cause problems if we are taking the address of this
+ COMPONENT_REF because the MEM of any reference via that address
+ will have flags corresponding to the type, which will not
+ necessarily be constant. */
if (mode == BLKmode)
{
! rtx new
! = assign_stack_temp_for_type
! (ext_mode, GET_MODE_BITSIZE (ext_mode), 0, type);
emit_move_insn (new, op0);