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