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: Tue, 7 Jun 2022 03:04:07 +0200

On Mon, 6 Jun 2022 23:46:41 +0000 Greg Chicares <gchicares@sbcglobal.net> wrote:

[...compilation error with -O3...]
GC> I have no idea at all. In the stack traces, I see nothing that
GC> pertains to lmi except for the inclusion of standard headers
GC> and this one line:
GC> 
GC> inlined from ‘std::vector<double> {anonymous}::table_256(int, int)’ at 
actuarial_table_test.cpp:188:13:
GC> 
GC> where line 188 is:
GC>       v.insert(v.end(), qult + age - 10, qult + nult);
GC> 
GC> In table_256(), 'qsel' indeed has 213 = 71 * 3 elements. Similarly,
GC> 121 - 13 + 1 equals 109, and 'qult' does have 109 elements. These
GC> arrays can't be overflowing any reasonable implementation limits.

 But apparently the compiler manages to somehow optimize it in such a way
that they do.

GC> The test passes with the 'safestdlib' build type, which uses
GC>   -O0 -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
GC> so the "debug" version of libstdc++ considers this code valid.
GC> It still passes if I change -O0 to -O2, and even if I change
GC> it to -O3.
GC> 
GC> Dare we consider the possibility that UBSan is malfunctioning?

 I think it's a compiler bug, not UBSAN's, but somehow it's only triggered
by the latter. FWIW it still compiles with ASAN and it also compiles with
UBSAN when using clang. Unfortunately it still doesn't compile with the
latest g++ 12.1.0, although the error is different with it: it's not
-Warray-bounds rather than -Wstringop-overflow, which makes slightly more
sense (as we're definitely not operating on strings here), but still not
that much.

 I'll try to see if I can make a relatively minimal reproducer for this and
report it to gcc bug tracker later, but, from past experiences, it might
take quite a long time, so I'm not going to do it before finishing with the
other tasks in progress.

 BTW, compiling this single source file with -O3 takes 15 seconds on my
machine with g++-12, which is even slower than the already not great 14s
with g++-11. -O2 is slightly faster, but -O0 is much faster at 3s and -O1
is at 9s with g++-11 and, amazingly, fails to compile with yet another
warning (-Wmaybe-uninitialized this time) with g++-12.

 Regards,
VZ

Attachment: pgp2mBYXodY55.pgp
Description: PGP signature


reply via email to

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