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

Haoxin Tu <haoxintu at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|11.0                        |10.0

--- Comment #1 from Haoxin Tu <haoxintu at gmail dot com> ---
I also found another case example.cpp

#include <iostream>

unsigned short g_var_ushort = 52781U;
const unsigned int g_const_uint = 2331271054U;

int main () {
    //test_function();
    short l_var_short = -14674;
    volatile unsigned char l_volatile_uchar = 151U;
    long l_var_long = 572469544701421587L;

    g_var_ushort = l_volatile_uchar - l_var_short % g_const_uint * l_var_long;
    std::cout << "hello" << std::endl;
    return 0;
}

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

$clang++ -fsanitize=signed-integer-overflow example.cpp ; ./a.out
example.cpp:12:66: runtime error: signed integer overflow: 1963681568 *
572469544701421587 cannot be represented in type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior example.cpp:12:66 in 
hello

My g++ version is
$g++ --version
g++ (GCC) 10.0.1 20200420 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I have tested all GCC versions including GCC-8, GCC-9, GCC-10, and GCC-Trunk in
Godbolt, they can not detect this UB as well.

Reply via email to