public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/63806] New: #UBSAN ignores signed char possible overflow
@ 2014-11-10 13:14 m.zakirov at samsung dot com
  2014-11-10 13:24 ` [Bug sanitizer/63806] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: m.zakirov at samsung dot com @ 2014-11-10 13:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 63806
           Summary: #UBSAN ignores signed char possible overflow
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: m.zakirov at samsung dot com
                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

For the following example GCC with ubsan do not constructs UBSAN_ADD_CHECK for
signed char return value.

signed char a;
signed char b;

signed char foo ()
{
   return a + b;
}

Dump after ubsan

foo ()
{
  signed char a.0_2;
  unsigned char a.1_3;
  signed char b.2_4;
  unsigned char b.3_5;
  unsigned char _6;
  signed char _7;

  <bb 2>:
  a.0_2 = a;
  a.1_3 = (unsigned char) a.0_2;
  b.2_4 = b;
  b.3_5 = (unsigned char) b.2_4;
  _6 = a.1_3 + b.3_5;
  _7 = (signed char) _6;
  return _7;

}

Command line to reproduce

gcc -O3 t.c -fsanitize=signed-integer-overflow -fdump-tree-ubsan -S


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

* [Bug sanitizer/63806] #UBSAN ignores signed char possible overflow
  2014-11-10 13:14 [Bug sanitizer/63806] New: #UBSAN ignores signed char possible overflow m.zakirov at samsung dot com
@ 2014-11-10 13:24 ` jakub at gcc dot gnu.org
  2014-11-10 13:33 ` y.gribov at samsung dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-11-10 13:24 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
?  That is the correct thing to do, there is no undefined behavior in C/C++ in
that testcase, for any a/b values.
a + b in C is computed on promoted arguments, so (signed char) ((int) a + (int)
b) in this case, so as long as signed char is narrower than int, it is fine.


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

* [Bug sanitizer/63806] #UBSAN ignores signed char possible overflow
  2014-11-10 13:14 [Bug sanitizer/63806] New: #UBSAN ignores signed char possible overflow m.zakirov at samsung dot com
  2014-11-10 13:24 ` [Bug sanitizer/63806] " jakub at gcc dot gnu.org
@ 2014-11-10 13:33 ` y.gribov at samsung dot com
  2014-11-10 13:41 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: y.gribov at samsung dot com @ 2014-11-10 13:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Yury Gribov <y.gribov at samsung dot com> ---
I think Marat meant that narrowing cast from int to char can be undefined and
it makes sense to emit some check for it as well.


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

* [Bug sanitizer/63806] #UBSAN ignores signed char possible overflow
  2014-11-10 13:14 [Bug sanitizer/63806] New: #UBSAN ignores signed char possible overflow m.zakirov at samsung dot com
  2014-11-10 13:24 ` [Bug sanitizer/63806] " jakub at gcc dot gnu.org
  2014-11-10 13:33 ` y.gribov at samsung dot com
@ 2014-11-10 13:41 ` jakub at gcc dot gnu.org
  2014-11-10 14:28 ` y.gribov at samsung dot com
  2014-11-13 11:19 ` y.gribov at samsung dot com
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-11-10 13:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
No, narrowing conversion is implementation defined, and gcc defines that to the
modulo 2^N wrapping, so this is not undefined behavior, and furthermore,
something you'd complain about in pretty much all the code (there is no
difference between implicit and explicit narrowing cast).


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

* [Bug sanitizer/63806] #UBSAN ignores signed char possible overflow
  2014-11-10 13:14 [Bug sanitizer/63806] New: #UBSAN ignores signed char possible overflow m.zakirov at samsung dot com
                   ` (2 preceding siblings ...)
  2014-11-10 13:41 ` jakub at gcc dot gnu.org
@ 2014-11-10 14:28 ` y.gribov at samsung dot com
  2014-11-13 11:19 ` y.gribov at samsung dot com
  4 siblings, 0 replies; 6+ messages in thread
From: y.gribov at samsung dot com @ 2014-11-10 14:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Yury Gribov <y.gribov at samsung dot com> ---
Looks like some compilers check integer demotions (e.g. MS checks with their
/RTCc flag).  I wonder if it makes sense to add an optional flag for this
(obviously not enabled under normal -fsanitize=undefined).


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

* [Bug sanitizer/63806] #UBSAN ignores signed char possible overflow
  2014-11-10 13:14 [Bug sanitizer/63806] New: #UBSAN ignores signed char possible overflow m.zakirov at samsung dot com
                   ` (3 preceding siblings ...)
  2014-11-10 14:28 ` y.gribov at samsung dot com
@ 2014-11-13 11:19 ` y.gribov at samsung dot com
  4 siblings, 0 replies; 6+ messages in thread
From: y.gribov at samsung dot com @ 2014-11-13 11:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Yury Gribov <y.gribov at samsung dot com> ---
I've posted feature request upstream:
http://llvm.org/bugs/show_bug.cgi?id=21530


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

end of thread, other threads:[~2014-11-13 11:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-10 13:14 [Bug sanitizer/63806] New: #UBSAN ignores signed char possible overflow m.zakirov at samsung dot com
2014-11-10 13:24 ` [Bug sanitizer/63806] " jakub at gcc dot gnu.org
2014-11-10 13:33 ` y.gribov at samsung dot com
2014-11-10 13:41 ` jakub at gcc dot gnu.org
2014-11-10 14:28 ` y.gribov at samsung dot com
2014-11-13 11:19 ` 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).