[Bug tree-optimization/86259] [8/9 Regression] min(4, strlen(s)) optimized to strlen(s) with -flto

davmac at davmac dot org gcc-bugzilla@gcc.gnu.org
Wed Jul 11 10:25:00 GMT 2018


Davin McCall <davmac at davmac dot org> changed:

           What    |Removed                     |Added
                 CC|                            |davmac at davmac dot org

--- Comment #19 from Davin McCall <davmac at davmac dot org> ---
(In reply to rguenther@suse.de from comment #16)
> On Mon, 25 Jun 2018, glisse at gcc dot gnu.org wrote:
> As a general comment I find it disturbing that the user
> is required to write (char *)&s2 + offsetof(S, a) instead
> of plain &s2.a

Even worse, the proposal doesn't mention the provenance of "offsetof" at all.
If the result of offsetof has no provenance even the long form won't work. That
seems like a big oversight to me. Also, code doing something like the following
can't be terribly uncommon:

    type struct { int a; int b; } s;
    s s_o;
    // start with address of contained member:
    char *b_cp = &s_o.b;
    // subtract its offset:
    char *s_o_cp = b_cp - offsetof(s,b);
    s * s_o_p = (s *) s_o_cp;
    // access the containing object:
    s s2 = *s_o_p;

It would only work generally if an offsetof result is given wildcard

More information about the Gcc-bugs mailing list