public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/92486] Wrong optimization: padding in structs is not copied even with memcpy
       [not found] <bug-92486-4@http.gcc.gnu.org/bugzilla/>
@ 2020-03-20 11:23 ` ch3root at openwall dot com
  0 siblings, 0 replies; only message in thread
From: ch3root at openwall dot com @ 2020-03-20 11:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #18 from Alexander Cherepanov <ch3root at openwall dot com> ---
Adding a `memset` makes trunk fail too:

----------------------------------------------------------------------
#include <string.h>
#include <stdio.h>

struct s {
    char c;
    int i;
};

__attribute__((noinline,noclone))
void f(struct s *p, struct s *q)
{
    struct s w;

    memset(&w, 0, sizeof(struct s));
    w = *q;
    memcpy(&w, q, sizeof(struct s));

    *p = w;
    memcpy(p, &w, sizeof(struct s));
}

int main()
{
    struct s x;
    memset(&x, 1, sizeof(struct s));

    struct s y;
    memset(&y, 2, sizeof(struct s));

    f(&y, &x);

    for (unsigned char *p = (unsigned char *)&y; p < (unsigned char *)&y +
sizeof(struct s); p++)
        printf("%d", *p);
    printf("\n");
}
----------------------------------------------------------------------
$ gcc -std=c11 -pedantic -Wall -Wextra test.c && ./a.out
11111111
$ gcc -std=c11 -pedantic -Wall -Wextra -O3 test.c && ./a.out
12221111
----------------------------------------------------------------------
gcc x86-64 version: gcc (GCC) 10.0.1 20200320 (experimental)
----------------------------------------------------------------------

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-03-20 11:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-92486-4@http.gcc.gnu.org/bugzilla/>
2020-03-20 11:23 ` [Bug tree-optimization/92486] Wrong optimization: padding in structs is not copied even with memcpy ch3root at openwall dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).