This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/86259] [8/9 Regression] min(4, strlen(s)) optimized to strlen(s) with -flto
- From: "glisse at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 25 Jun 2018 04:26:03 +0000
- Subject: [Bug tree-optimization/86259] [8/9 Regression] min(4, strlen(s)) optimized to strlen(s) with -flto
- Auto-submitted: auto-generated
- References: <bug-86259-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86259
--- Comment #15 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #14)
> > You say that
> >
> > struct { int a; int b; } s, s2;
> > memcpy (&s2.a, &s.a, sizeof (s));
> >
> > is invalid, aka not copying the whole structure since you pass in a
> > pointer to s2.a rather than s2?
>
> Yes.
Let's give the struct a name and introduce some casts
typedef struct { int a; int b; } S;
S s, s2;
memcpy ((S*)&s2.a, (S*)&s.a, sizeof(s));
The standard makes it valid to convert &s.a to S* and makes it equivalent to
&s. Because of the call to memcpy, it gets converted to void* afterwards. So
you are saying that (void*)&s.a is not the same as (void*)(S*)&s.a (note that
no arithmetic is involved at this point). This looks like it is going to cause
trouble...