public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/64996] New: UBsan check optimized out by -O
@ 2015-02-10  9:25 sami.liedes at iki dot fi
  2015-02-10  9:50 ` [Bug sanitizer/64996] " mpolacek at gcc dot gnu.org
  2015-03-10  9:10 ` y.gribov at samsung dot com
  0 siblings, 2 replies; 3+ messages in thread
From: sami.liedes at iki dot fi @ 2015-02-10  9:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 64996
           Summary: UBsan check optimized out by -O
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sami.liedes at iki dot fi
                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

Consider this program:

#include "limits.h"
int main() {
        int i=INT_MIN;
        i--;
}

When compiled with -fsanitize=undefined -O0, ub is correctly detected:

$ gcc -fsanitize=undefined ub.c -o ub && ./ub
ub.c:4:10: runtime error: signed integer overflow: -2147483648 + -1 cannot be
represented in type 'int'

When compiled with -O, the entire check is optimized out, even if the program
still clearly exhibits ub:

$ gcc -fsanitize=undefined ub.c -o ub -O && ./ub
$ gcc -fsanitize=undefined ub.c -o ub.s -O -S
$ cat ub.s
        .file   "ub.c"
        .text
        .globl  main
        .type   main, @function
main:
.LFB0:
        .cfi_startproc
        rep ret
        .cfi_endproc
.LFE0:
        .size   main, .-main
        .ident  "GCC: (Debian 4.9.2-10) 4.9.2"
        .section        .note.GNU-stack,"",@progbits
$


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

* [Bug sanitizer/64996] UBsan check optimized out by -O
  2015-02-10  9:25 [Bug sanitizer/64996] New: UBsan check optimized out by -O sami.liedes at iki dot fi
@ 2015-02-10  9:50 ` mpolacek at gcc dot gnu.org
  2015-03-10  9:10 ` y.gribov at samsung dot com
  1 sibling, 0 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-02-10  9:50 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

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

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Since the variable is unused, we get rid of it, and then DCE removes the ubsan
check.  I don't think it is a bug.  Adding asm ("" : "+g" (i)); after the
decrement makes the runtime error appear again.


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

* [Bug sanitizer/64996] UBsan check optimized out by -O
  2015-02-10  9:25 [Bug sanitizer/64996] New: UBsan check optimized out by -O sami.liedes at iki dot fi
  2015-02-10  9:50 ` [Bug sanitizer/64996] " mpolacek at gcc dot gnu.org
@ 2015-03-10  9:10 ` y.gribov at samsung dot com
  1 sibling, 0 replies; 3+ messages in thread
From: y.gribov at samsung dot com @ 2015-03-10  9:10 UTC (permalink / raw)
  To: gcc-bugs

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

Yury Gribov <y.gribov at samsung dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |y.gribov at samsung dot com

--- Comment #2 from Yury Gribov <y.gribov at samsung dot com> ---
Also take a look at second FAQ question at
https://code.google.com/p/address-sanitizer/wiki/AddressSanitizer#FAQ (it's for
ASan but same logic applies).


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

end of thread, other threads:[~2015-03-10  9:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-10  9:25 [Bug sanitizer/64996] New: UBsan check optimized out by -O sami.liedes at iki dot fi
2015-02-10  9:50 ` [Bug sanitizer/64996] " mpolacek at gcc dot gnu.org
2015-03-10  9:10 ` y.gribov at samsung dot com

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