public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/108060] New: UBsan missed an out-of-bound bug at -O0
@ 2022-12-11 14:32 shaohua.li at inf dot ethz.ch
  2022-12-12 12:45 ` [Bug sanitizer/108060] UBsan missed an out-of-bound bug at -O0 since r7-1900-g8a1b7b7fd75a3847 marxin at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2022-12-11 14:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108060
           Summary: UBsan missed an out-of-bound bug at -O0
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org
  Target Milestone: ---

For the following code, UBsan at -O0 missed reporting the out-of-bound access,
while -O1 and above caught it. 

Clang could detect it at all optimization levels.

Compiler explorer: https://godbolt.org/z/Tb9Mern7M

% cat a.c
int a[8];
short b;
char c;
int main() {
  b = -32768;
  a[b] |= c;
}
%
% gcc-tk -O0 -fsanitize=undefined -fno-sanitize-recover=all a.c && ./a.out
Segmentation fault
% gcc-tk -O1 -fsanitize=undefined -fno-sanitize-recover=all a.c && ./a.out
a.c:6:4: runtime error: index -32768 out of bounds for type 'int [8]'
%

Interestingly, if you don't use `-fno-sanitize-recover=all`, none of opt levels
could detect it:
% gcc-tk -O1 -fsanitize=undefined a.c && ./a.out
Segmentation fault
%

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

end of thread, other threads:[~2024-02-01  9:53 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-11 14:32 [Bug sanitizer/108060] New: UBsan missed an out-of-bound bug at -O0 shaohua.li at inf dot ethz.ch
2022-12-12 12:45 ` [Bug sanitizer/108060] UBsan missed an out-of-bound bug at -O0 since r7-1900-g8a1b7b7fd75a3847 marxin at gcc dot gnu.org
2022-12-12 16:29 ` [Bug sanitizer/108060] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
2022-12-21 11:52 ` [Bug c/108060] " rguenth at gcc dot gnu.org
2022-12-22 12:06 ` marxin at gcc dot gnu.org
2023-03-07 14:29 ` marxin at gcc dot gnu.org
2023-03-07 14:30 ` marxin at gcc dot gnu.org
2023-03-07 14:44 ` mpolacek at gcc dot gnu.org
2023-03-07 23:19 ` mpolacek at gcc dot gnu.org
2023-03-10 18:25 ` [Bug sanitizer/108060] " cvs-commit at gcc dot gnu.org
2023-03-10 18:32 ` [Bug sanitizer/108060] [10/11/12 " mpolacek at gcc dot gnu.org
2023-03-15 18:35 ` cvs-commit at gcc dot gnu.org
2023-03-15 18:35 ` [Bug sanitizer/108060] [10/11 " mpolacek at gcc dot gnu.org
2024-02-01  9:53 ` pinskia 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).