lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] UBSAN flags


From: Vadim Zeitlin
Subject: Re: [lmi] UBSAN flags
Date: Mon, 6 Jun 2022 23:57:43 +0200

On Mon, 6 Jun 2022 18:59:13 +0000 Greg Chicares <gchicares@sbcglobal.net> wrote:

[...]
GC> Key:
GC>   no VTA = -fno-var-tracking-assignments
GC>   no VT  = -fno-var-tracking
GC> 
GC> This is the command I used for all:
GC> 
GC> $make build_type=ubsan clean; time UBSAN_OPTIONS=print_stacktrace=1 make 
$coefficiency unit_tests build_type=ubsan >../log 2>&1
GC> 
GC> Each datum begins with a left-aligned clock time.
GC> 
GC> 5:22.66 -O1 only found two errors:
GC>   input_test.cpp:165:5: runtime error: load of value 25000
GC>   fdlibm_expm1.c:243:13: runtime error: left shift of negative value -2
GC> 2:10.97 -O1 no VTA: same two errors
GC> 
GC> * -O1 is inadequate. It caught only two of three instances of UB.
GC> 
GC> 5:07.56 -O2 three errors:
GC>   any_member.hpp:177:33: runtime error: load of value 80
GC>   input_test.cpp:165:5: runtime error: load of value 25000
GC>   fdlibm_expm1.c:243:13: runtime error: left shift of negative value -2
GC>   -ftime-report: VT + VTA = up to 78% of total, apparently for zero_test
GC> 3:25.79 -O2 no VTA: same three errors
GC> 
GC> * -O2 is the lmi default. It catches all three errors. Oddly,
GC> it's faster than -O1 with VTA,

 This is a surprising result. IME -O2 builds are much slower than -O0 ones
and while I don't use -O1 much, it would be logical to expect them to be in
the middle.

GC> but slower with "no VTA".
GC> 
GC> 4:58.01 -Og same three errors
GC> 
GC> * -Og is hardly faster than -O2.

 This is another unexpected result, but here it's just the magnitude of the
difference which is surprising, not the sign.

GC> 5:30.70 -O3 same three errors, as well as a fourth:
GC>   actuarial_table_test.cpp:24: [illegal memory operations] fails to compile
[...]
GC> Can you reproduce the 'actuarial_table_test' problem?

 I can't compile this file with -O3 because I get this error:

In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/string:40,
                 from actuarial_table.hpp:28,
                 from actuarial_table_test.cpp:24:
In static member function ‘static constexpr _Tp* std::__copy_move<_IsMove, 
true, std::random_access_iterator_tag>::__copy_m(const _Tp*, const _Tp*, _Tp*) 
[with _Tp = double; bool _IsMove = false]’,
    inlined from ‘constexpr _OI std::__copy_move_a2(_II, _II, _OI) [with bool 
_IsMove = false; _II = const double*; _OI = double*]’ at 
/usr/include/c++/11/bits/stl_algobase.h:495:30,
    inlined from ‘constexpr _OI std::__copy_move_a1(_II, _II, _OI) [with bool 
_IsMove = false; _II = const double*; _OI = double*]’ at 
/usr/include/c++/11/bits/stl_algobase.h:522:42,
    inlined from ‘constexpr _OI std::__copy_move_a(_II, _II, _OI) [with bool 
_IsMove = false; _II = const double*; _OI = double*]’ at 
/usr/include/c++/11/bits/stl_algobase.h:529:31,
    inlined from ‘constexpr _OI std::copy(_II, _II, _OI) [with _II = const 
double*; _OI = double*]’ at /usr/include/c++/11/bits/stl_algobase.h:620:7,
    inlined from ‘static _ForwardIterator 
std::__uninitialized_copy<true>::__uninit_copy(_InputIterator, _InputIterator, 
_ForwardIterator) [with _InputIterator = const double*; _ForwardIterator = 
double*]’ at /usr/include/c++/11/bits/stl_uninitialized.h:110:27,
    inlined from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, 
_InputIterator, _ForwardIterator) [with _InputIterator = const double*; 
_ForwardIterator = double*]’ at 
/usr/include/c++/11/bits/stl_uninitialized.h:151:15,
    inlined from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, 
_InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = 
const double*; _ForwardIterator = double*; _Tp = double]’ at 
/usr/include/c++/11/bits/stl_uninitialized.h:333:37,
    inlined from ‘void std::vector<_Tp, 
_Alloc>::_M_range_insert(std::vector<_Tp, _Alloc>::iterator, _ForwardIterator, 
_ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator = const 
double*; _Tp = double; _Alloc = std::allocator<double>]’ at 
/usr/include/c++/11/bits/vector.tcc:751:34,
    inlined from ‘void std::vector<_Tp, 
_Alloc>::_M_insert_dispatch(std::vector<_Tp, _Alloc>::iterator, _InputIterator, 
_InputIterator, std::__false_type) [with _InputIterator = const double*; _Tp = 
double; _Alloc = std::allocator<double> ’ at 
/usr/include/c++/11/bits/stl_vector.h:1665:19,
    inlined from ‘std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, 
_Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, _InputIterator, 
_InputIterator) [with _InputIterator = const double*; <template-parameter-2-2> 
= void; _Tp = double; _Alloc = std::allocator<double>]’ at 
/usr/include/c++/11/bits/stl_vector.h:1383:22,
    inlined from ‘std::vector<double> {anonymous}::table_256(int, int)’ at 
actuarial_table_test.cpp:188:13:
/usr/include/c++/11/bits/stl_algobase.h:431:30: error: ‘void* 
__builtin_memmove(void*, const void*, long unsigned int)’ writing 1 or more 
bytes into a region of size 0 overflows the destination 
[-Werror=stringop-overflow=]
  431 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from 
/usr/include/x86_64-linux-gnu/c++/11/bits/c++allocator.h:33,
                 from /usr/include/c++/11/bits/allocator.h:46,
                 from /usr/include/c++/11/string:41,
                 from actuarial_table.hpp:28,
                 from actuarial_table_test.cpp:24:
/usr/include/c++/11/ext/new_allocator.h: In function ‘std::vector<double> 
{anonymous}::table_256(int, int)’:
/usr/include/c++/11/ext/new_allocator.h:127:48: note: at offset 24 into 
destination object of size 24 allocated by ‘operator new’
  127 |         return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
      |                                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~

 I'm not sure what's going on here and I'm not sure if this is the
same as the "illegal memory operation" mentioned above or not. FWIW, if I
change -O3 to -O2 for this file compilation, then it compiles fine and the
resulting test runs without any errors. But this error definitely looks
worrisome, so I'll look into it unless you already understand what is it
about -- if so, please let me know.

 Thanks in advance,
VZ

Attachment: pgpolY3_F8m5n.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]