public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "ch3root at openwall dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/94206] New: Wrong optimization: memset of n-bit integer types (from bit-fields) is truncated to n bits (instead of sizeof) Date: Tue, 17 Mar 2020 21:15:32 +0000 [thread overview] Message-ID: <bug-94206-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94206 Bug ID: 94206 Summary: Wrong optimization: memset of n-bit integer types (from bit-fields) is truncated to n bits (instead of sizeof) Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: ch3root at openwall dot com Target Milestone: --- Bit-fields of different widths have their own types in gcc. And `memset` seems to be optimized strangely for them. Even at `-O0`! This is not standard C due to the use of `typeof` but this topic is starting to be more interesting in light of N2472 "Adding Fundamental Type for N-bit Integers". ---------------------------------------------------------------------- #include <string.h> #include <stdio.h> struct { unsigned long x:33; } s; typedef __typeof__(s.x + 0) uint33; int main() { uint33 x; printf("sizeof = %zu\n", sizeof x); memset(&x, -1, sizeof x); unsigned long u; memcpy(&u, &x, sizeof u); printf("%lx\n", u); } ---------------------------------------------------------------------- $ gcc -std=c11 -pedantic -Wall -Wextra test.c && ./a.out sizeof = 8 1ffffffff $ gcc -std=c11 -pedantic -Wall -Wextra -O3 test.c && ./a.out sizeof = 8 1ffffffff ---------------------------------------------------------------------- gcc x86-64 version: gcc (GCC) 10.0.1 20200317 (experimental) ---------------------------------------------------------------------- The right result is `ffffffffffffffff`.
next reply other threads:[~2020-03-17 21:15 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-03-17 21:15 ch3root at openwall dot com [this message] 2020-03-17 21:22 ` [Bug middle-end/94206] " pinskia at gcc dot gnu.org 2020-03-18 8:12 ` rguenth at gcc dot gnu.org 2020-03-18 12:12 ` cvs-commit at gcc dot gnu.org 2020-03-18 12:13 ` rguenth at gcc dot gnu.org 2020-04-02 14:49 ` cvs-commit at gcc dot gnu.org 2020-04-15 9:59 ` rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-94206-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).