This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] handle zero-sized constructor component if side effects


Daniel wrote:
> I don't believe it will get called, though the logic is a bit wonky to
> follow. If it gets called, i'm happy to withdraw my objection.

 It actually is called, at least in the case at hand, because
 "gimplify_init_ctor_eval" gimplifies the MODIFY_EXPR it makes:

       ...
       else
	{
	  init = build (MODIFY_EXPR, TREE_TYPE (cref), cref, value);
	  gimplify_and_add (init, pre_p);

 and there is indeed no assignment in the t03.gimple output:

   Empty_Record ()
   {
     ...
     struct empty_record__ea___PAD ea;

     empty_record__one_empty_record ();
     return;
   }

 A breakpoint in the special modify_expr case exhibits the path :

 gimplify_modify_expr (...) at .../gcc/gimplify.c:3168
(gdb) l
3163	  
3164	 /* For zero sized types only gimplify the left hand side and right
3165	    hand side as statements and throw away the assignment.  */
3166	  if (zero_sized_type (TREE_TYPE (*from_p)))
3167	    {
3168	      gimplify_stmt (from_p);
3169	      gimplify_stmt (to_p);
3170	      append_to_statement_list (*from_p, pre_p);
3171	      append_to_statement_list (*to_p, pre_p);
3172	      *expr_p = NULL_TREE;

(gdb) pt *from_p
 <call_expr 0x401a01e0
    type <record_type empty_record__empty_record_t sizes-gimplified BLK
        size <integer_cst 0x401947c8 constant invariant 0>

(gdb) bt 10
#0  gimplify_modify_expr (...) at .../gimplify.c:3168

#1  in gimplify_expr (...) at .../gimplify.c:4058
#2  0x08331091 in gimplify_stmt (stmt_p=0xbfffe0a0) at .../gimplify.c:3886
#3  0x0831dff9 in gimplify_and_add (...) at .../gimplify.c:263

#4  0x0832b7ee in gimplify_init_ctor_eval (...) at .../gimplify.c:2622

#5  0x0832c410 in gimplify_init_constructor (...) at .../gimplify.c:2806
#6  0x0832d5d4 in gimplify_modify_expr_rhs (...) at .../gimplify.c:3030

#7  0x0832df23 in gimplify_modify_expr (...) at .../gimplify.c:3177
 
 Certainly not obvious to see in the first place. I can add a comment
 explaining that.

 How about something like:

      /* Skip zero-sized fields, unless value has side-effects.  This can
	 happen with calls to functions returning a zero-sized type, which we
	 shouldn't discard.  As a number of downstream passes don't expect
	 sets of zero-sized fields, we rely on the gimplification of the
	 MODIFY_EXPR we make below to drop the assignment statement.  */
      if (! TREE_SIDE_EFFECTS (value) && zero_sized_field_decl (purpose))
	continue;

 ?

 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]