public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/108127] New: FP due to combination of -Warray-bounds and UBSAN
@ 2022-12-15 12:02 frolov.da at phystech dot edu
  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
  0 siblings, 2 replies; 3+ messages in thread
From: frolov.da at phystech dot edu @ 2022-12-15 12:02 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/108127] FP due to combination of -Warray-bounds and UBSAN
  2022-12-15 12:02 [Bug c/108127] New: FP due to combination of -Warray-bounds and UBSAN frolov.da at phystech dot edu
@ 2022-12-15 17:49 ` pinskia at gcc dot gnu.org
  2022-12-16 14:14 ` marxin at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-15 17:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
From the new documentation:
https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003dundefined

"Note that sanitizers tend to increase the rate of false positive warnings,
most notably those around -Wmaybe-uninitialized. We recommend against combining
-Werror and [the use of] sanitizers.

"

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/108127] FP due to combination of -Warray-bounds and UBSAN
  2022-12-15 12:02 [Bug c/108127] New: FP due to combination of -Warray-bounds and UBSAN frolov.da at phystech dot edu
  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
  1 sibling, 0 replies; 3+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-12-16 14:14 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marxin at gcc dot gnu.org
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
It's expected behavior.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-16 14:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-15 12:02 [Bug c/108127] New: FP due to combination of -Warray-bounds and UBSAN frolov.da at phystech dot edu
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

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).