This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] handle zero-sized constructor component if side effects
- From: Olivier Hainque <hainque at adacore dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: hainque at adacore dot com
- Date: Mon, 12 Sep 2005 15:56:48 +0200
- Subject: [PATCH] handle zero-sized constructor component if side effects
This is a followup on the discussion at
http://gcc.gnu.org/ml/gcc/2005-09/msg00257.html
The basic issue is that "gimplify_init_ctor_eval" simply skips
zero-sized constructor components, potentially discarding side
effects like a function call.
Typically, compiled with mainline, the following program runs silently
while it is expected to print out "Returning one empty record...":
with Text_Io; use Text_Io;
procedure Empty_Record is
type Empty_Record_T is null record;
function One_Empty_Record return Empty_Record_T is
A : Empty_Record_T := (null record);
begin
Put_Line ("Returning one empty record...");
return A;
end;
EA : Empty_Record_T;
begin
EA := One_Empty_Record;
end;
Even if there is nothing to assign, the subprogram call is still expected
to take place. It just completely disappears from the t03.gimple output of
the current mainline compiler.
The code discarding zero-sized components in "gimplify_init_ctor_eval" is:
FOR_EACH_CONSTRUCTOR_ELT (elts, ix, purpose, value)
...
if (zero_sized_field_decl (purpose))
continue;
The patch below addresses the problem by checking in addition that "value"
has no side effects at this point. This fixes the testcase above as well as
a couple of ACATS along the way.
Bootstrapped and regression tested on i686-pc-linux-gnu with
languages=all,ada.
Thanks in advance,
Olivier
-------------------
2005-09-12 Olivier Hainque <hainque@adacore.com>
* gimplify.c (gimplify_init_ctor_eval): Don't discard a zero-sized
value if it has side-effects.
*** gimplify.c.ori Wed Sep 7 14:52:25 2005
--- gimplify.c Thu Sep 8 14:28:40 2005
*************** gimplify_init_ctor_eval (tree object, VE
*** 2576,2582 ****
so we don't have to figure out what's missing ourselves. */
gcc_assert (purpose);
! if (zero_sized_field_decl (purpose))
continue;
/* If we have a RANGE_EXPR, we have to build a loop to assign the
--- 2576,2584 ----
so we don't have to figure out what's missing ourselves. */
gcc_assert (purpose);
! /* Skip empty fields unless value has side effects. A possible
! case is a call to function returning a zero sized type. */
! if (! TREE_SIDE_EFFECTS (value) && zero_sized_field_decl (purpose))
continue;
/* If we have a RANGE_EXPR, we have to build a loop to assign the