This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Undefined behavior due to 6.5.16.1p3
- From: Martin Sebor <msebor at redhat dot com>
- To: Robbert Krebbers <mailinglists at robbertkrebbers dot nl>, gcc at gcc dot gnu dot org
- Date: Tue, 10 Mar 2015 10:18:35 -0600
- Subject: Re: Undefined behavior due to 6.5.16.1p3
- Authentication-results: sourceware.org; auth=none
- References: <54FDF3CE dot 6030507 at robbertkrebbers dot nl>
On 03/09/2015 01:26 PM, Robbert Krebbers wrote:
I was wondering whether GCC uses 6.5.16.1p3 of the C11 standard as a
license to perform certain optimizations. If so, could anyone provide me
an example program.
In particular, I am interested about the "then the overlap shall be
exact" part of 6.5.16.1p3:
If the value being stored in an object is read from another
object that overlaps in any way the storage of the first
object, then the overlap shall be exact and the two objects
shall have qualified or unqualified versions of a compatible
type; otherwise, the behavior is undefined.
I suspect every compiler relies on this requirement in certain
cases otherwise copying would require making use of temporary
storage. Here's an example:
struct A {
int a [32];
};
union {
struct A a;
struct {
char b1;
struct A b2;
} b;
} u;
void foo (void) {
u.b.b2 = u.a;
}
Martin