public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95326] New: UBsan can not detect signed-integer-overflow correctly
@ 2020-05-26  4:14 haoxintu at gmail dot com
  2020-05-26  5:23 ` [Bug c++/95326] GCC " haoxintu at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: haoxintu at gmail dot com @ 2020-05-26  4:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95326
           Summary: UBsan can not detect signed-integer-overflow correctly
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

This case example.cpp

#include <iostream>

volatile wchar_t g_volatile_wchar = 2082494266;
volatile unsigned short g_volatile_ushort = 31503U;

int main () {
    unsigned long l_var_ulong = 526562505494506029UL;
    const wchar_t l_const_wchar = 1188246531;
    g_volatile_ushort = l_var_ulong + l_const_wchar * g_volatile_wchar;
    std::cout << "hello" << std::endl;
    return 0;
}

can not detect signed-integer-overflow runtime error in gcc-trunk

$g++ -fsanitize=signed-integer-overflow example.cpp ; ./a.out
hello

But in clang-trunk
$clang++ -fsanitize=signed-integer-overflow test.cc ; ./a.out
example.cpp:9:53: runtime error: signed integer overflow: 1188246531 *
2082494266 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior example.cpp:9:53 in 
hello

godbolt clang-trunk : https://godbolt.org/z/s4-AqW
godbolt gcc-trunk : https://godbolt.org/z/k7NhG6

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

end of thread, other threads:[~2024-03-10  3:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-26  4:14 [Bug c++/95326] New: UBsan can not detect signed-integer-overflow correctly haoxintu at gmail dot com
2020-05-26  5:23 ` [Bug c++/95326] GCC " haoxintu at gmail dot com
2020-05-26  7:06 ` [Bug middle-end/95326] " pinskia at gcc dot gnu.org
2020-05-26 12:41 ` haoxintu at gmail dot com
2020-05-26 15:24 ` pinskia at gcc dot gnu.org
2024-03-10  3:35 ` 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).