This is the mail archive of the gcc-bugs@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]

[Bug c/70143] [6 Regression] false strict-aliasing warning


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70143

--- Comment #10 from rguenther at suse dot de <rguenther at suse dot de> ---
On Wed, 9 Mar 2016, palves at redhat dot com wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70143
> 
> --- Comment #4 from Pedro Alves <palves at redhat dot com> ---
> > The warning is "correct".  You are accessing object *ap (a struct a) via a
> > pointer to struct b.  
> 
> I'd think that instead, we are accessing object "*&ap->i", an int, via a
> pointer 
> to struct b, and I'd imagine that the problem is that the frontend doesn't know 
> that struct *b and int * can alias, because the first field of 'struct a',
> which 
> in turn is the first field of 'struct b', is an int.
> 
> So I don't see how you can call this correct?
> 
> Is this really just a warning problem, or does the compiler really think that
> struct *b and int * cannot alias?

They can alias.  But 'struct *b' and an 'int' object can't.  Well.  At
least if the dynamic type of the 'int' object is still 'int'.  See
tree-ssa-alias.c:indirect_ref_may_alias_decl_p

  /* When we are trying to disambiguate an access with a pointer 
dereference
     as base versus one with a decl as base we can use both the size
     of the decl and its dynamic type for extra disambiguation.
     ???  We do not know anything about the dynamic type of the decl
     other than that its alias-set contains base2_alias_set as a subset
     which does not help us here.  */
  /* As we know nothing useful about the dynamic type of the decl just
     use the usual conflict check rather than a subset test.
     ???  We could introduce -fvery-strict-aliasing when the language
     does not allow decls to have a dynamic type that differs from their
     static type.  Then we can check
     !alias_set_subset_of (base1_alias_set, base2_alias_set) instead.  */
  if (base1_alias_set != base2_alias_set
      && !alias_sets_conflict_p (base1_alias_set, base2_alias_set))
    return false;

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