public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "ed at catmur dot uk" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106074] New: Spurious Wstringop-overflow for int-to-string with SSE4 Date: Fri, 24 Jun 2022 08:59:40 +0000 [thread overview] Message-ID: <bug-106074-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106074 Bug ID: 106074 Summary: Spurious Wstringop-overflow for int-to-string with SSE4 Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ed at catmur dot uk Target Milestone: --- Code adapted from https://github.com/capnproto/capnproto/blob/be7a80b4add706ddaeb41689221146b86c3e0f5f/c%2B%2B/src/kj/string.c%2B%2B#L157-L203 : auto f(short i) { struct R { char data[6]; } result; bool negative = i < 0; unsigned u = i; if (negative) u = -u; unsigned char reverse[5]; unsigned char* p = reverse; if (u == 0) *p++ = 0; else for (; u > 0; u /= 10) *p++ = u % 10; char* p2 = result.data; if (negative) *p2++ = '-'; while (p > reverse) { #ifdef ASSUME if (p2 >= (&result.data)[1]) __builtin_unreachable(); #endif *p2++ = '0' + *--p; } if (p2 < (&result.data)[1]) *p2 = '\0'; return result; } When compiled with -O3 -msse4, from 12.1.0 through 13.0.0 20220619: <source>: In function 'auto f(short int)': <source>:21:11: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] 21 | *p2++ = '0' + *--p; | ~~~~~~^~~~~~~~~~~~ <source>:2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 2 | struct R { char data[6]; } result; | ^~~~ <source>:2:30: note: at offset 7 into destination object 'result' of size 6 2 | struct R { char data[6]; } result; | ^~~~~~ <source>:2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 2 | struct R { char data[6]; } result; | ^~~~ <source>:2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 <source>:2:30: note: at offset 7 into destination object 'result' of size 6 2 | struct R { char data[6]; } result; | ^~~~~~ <source>:2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 2 | struct R { char data[6]; } result; | ^~~~ <source>:2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 <source>:2:30: note: at offset 7 into destination object 'result' of size 6 2 | struct R { char data[6]; } result; | ^~~~~~ <source>:2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 2 | struct R { char data[6]; } result; | ^~~~ <source>:2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 <source>:2:30: note: at offset 7 into destination object 'result' of size 6 2 | struct R { char data[6]; } result; | ^~~~~~ <source>:2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 2 | struct R { char data[6]; } result; | ^~~~ Adding the assumption at line 19 (-DASSUME) works around this.
next reply other threads:[~2022-06-24 8:59 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-06-24 8:59 ed at catmur dot uk [this message] 2022-07-07 12:16 ` [Bug c++/106074] " ed at catmur dot uk 2023-05-18 3:58 ` [Bug tree-optimization/106074] " pinskia 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-106074-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).