public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "frolov.da at phystech dot edu" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/108127] New: FP due to combination of -Warray-bounds and UBSAN Date: Thu, 15 Dec 2022 12:02:28 +0000 [thread overview] Message-ID: <bug-108127-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108127 Bug ID: 108127 Summary: FP due to combination of -Warray-bounds and UBSAN Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: frolov.da at phystech dot edu Target Milestone: --- I've tried to build the next example (which is a reduced example of one of the functions from firefox): static const unsigned DECPOWERS[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}; unsigned foo(int discard, unsigned char *lsu, unsigned char *up) { int count; unsigned cut, quot; count = discard; cut = discard - (count - 1) - 1; if (cut == 1 - 1) { return 8; } else { quot = *up >> cut; cut++; return DECPOWERS[1 - cut]; } } $ gcc -O2 -fsanitize-undefined-trap-on-error -Werror=array-bounds -fsanitize=shift,signed-integer-overflow and got an error: <source>: In function 'foo': <source>:16:21: error: array subscript 4294967265 is above array bounds of 'const unsigned int[10]' [-Werror=array-bounds=] 16 | return DECPOWERS[1 - cut]; | ~~~~~~~~~^~~~~~~~~ <source>:1:23: note: while referencing 'DECPOWERS' 1 | static const unsigned DECPOWERS[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000} Looks like the builtin functions of the ubsan (such as UBSAN_CHECK_SUB) does not allow optimizations and cause these false positives. If I remove the sanitizer flags then there will be no warning.
next reply other threads:[~2022-12-15 12:02 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-12-15 12:02 frolov.da at phystech dot edu [this message] 2022-12-15 17:49 ` [Bug middle-end/108127] " pinskia at gcc dot gnu.org 2022-12-16 14:14 ` marxin 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-108127-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).