This is the mail archive of the gcc@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: zero sized initializers with side effects discarded


Daniel Berlin wrote:
> Even if you "fixed" init_ctor_eval (modify_expr gimplifies the lhs and rhs 
> and throws away the assignment), you're going to run into problems in 
> the subvar machinery if you really have 0 sized field accesses with side 
> effects.
> 
> I'm not sure what the heck a "0 sized field access with side effects" 
> does.
> 
> After all, a 0 sized field has no space, etc (in fact, it is nothing), so 
> how could you side-effect by accessing one, since any such access must do 
> nothing?

 You may have side effect from an initializer when setting a zero
 sized field.

 For instance (variant of gcc.c-torture/compile/zero-strct-4.c), compiled
 with GCC 3.4, the code below prints "returning raw_lock" as I would
 expect. It doesn't print anything when compiled with mainline because
 one_raw_spinlock is not called.

   #include <stdio.h>

   typedef struct {} raw_spinlock_t;

   typedef struct {
     raw_spinlock_t raw_lock;
   } spinlock_t;


   raw_spinlock_t one_raw_spinlock (void)
   {
       raw_spinlock_t raw_lock;
       printf ("returning raw_lock\n");
       return raw_lock;
   }

   int main(void)
   {
     spinlock_t lock = (spinlock_t) { .raw_lock = one_raw_spinlock() };
     return 0;
   }


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