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

--- Comment #14 from uecker at gcc dot gnu.org ---
(In reply to Richard Biener from comment #13)
> (In reply to uecker from comment #3)
> > Ah, your are right. The declared type rules makes it valid. I forgot about
> > it because it is never explicitly used for anything, but here it makes a
> > difference.
> 
> I'll note that the middle-end doesn't have a declared-type rule and instead
> a store alters the effective type used.  So for
> 
> void *p = malloc (sizeof (s3));
> f2 (p, p);
> 
> f2() invokes UB according to the standard but
> 
> s3 x;
> f2(&x, &x);
> 
> does not?  That seems silly.

The weird thing is to have different type compatibility rules across TUs
compared to inside TUs.  This example  shows that even inside one TU we need to
optimize according to the across-TU compatibility. If we do this, then
everything works correctly. The special cases the C standard then has by making
some types incompatible inside a TU which are compatible across TU and the
"declared type" then only make more programs have UB and can safely be ignored
for purposes of optimization.

Reply via email to