lmi
[Top][All Lists]
Advanced

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

Re: [lmi] How to suppress this gcc-9 diagnostic?


From: Vadim Zeitlin
Subject: Re: [lmi] How to suppress this gcc-9 diagnostic?
Date: Wed, 29 Apr 2020 15:06:36 +0200

On Wed, 29 Apr 2020 12:44:59 +0000 Greg Chicares <address@hidden> wrote:

GC> A unit test (which has always worked) now fails to compile with
GC> MinGW-w64 gcc-9.3 due to -Werror and -Wnull-dereference. I don't
GC> see how this code can possibly dereference a null pointer. Vadim,
GC> do you know a way to rewrite it so that it doesn't trigger this
GC> warning?
GC> 
GC> Observed diagnostic, including full compiler command:
GC> 
GC> i686-w64-mingw32-g++ -MMD -MP -MT financial_test.o -MF financial_test.d  -c 
-I /opt/lmi/src/lmi -I /opt/lmi/src/lmi/tools/pete-2.1.1 -I 
/opt/lmi/local/gcc_i686-w64-mingw32/lib/wx/include/i686-w64-mingw32-msw-unicode-3.1
 -I /opt/lmi/local/include/wx-3.1 -I /opt/lmi/third_party/include -I 
/opt/lmi/third_party/src -I /opt/lmi/local/include -I 
/opt/lmi/local/include/libxml2 -DLMI_WX_NEW_USE_SO  -DLIBXML_USE_DLL -DSTRICT   
 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__ -D_FILE_OFFSET_BITS=64 
-DBOOST_NO_AUTO_PTR -DBOOST_STRICT_CONFIG -DBOOST_STATIC_ASSERT_HPP   
-fno-ms-extensions -frounding-math -std=c++17 -pedantic-errors -Werror -Wall 
-Walloc-zero -Walloca -Wcast-align -Wconversion -Wdangling-else 
-Wdeprecated-declarations -Wdisabled-optimization -Wdouble-promotion 
-Wduplicated-branches -Wduplicated-cond -Wextra -Wformat-nonliteral 
-Wformat-security -Wformat-signedness -Wformat-y2k -Wimport -Winit-self 
-Winvalid-pch -Wlogical-op -Wmissing-include-dirs -Wmultichar 
-Wnull-dereference -Wpacked -Wpointer-arith -Wredundant-decls -Wrestrict 
-Wshadow -Wsign-compare -Wstack-protector -Wswitch-enum -Wtrampolines -Wundef 
-Wunreachable-code -Wunused-macros -Wvector-operation-performance 
-Wwrite-strings -Wno-parentheses  -Wc++11-compat -Wc++14-compat -Wc++1z-compat 
-Wconditionally-supported -Wctor-dtor-privacy -Wdelete-non-virtual-dtor 
-Wdeprecated -Wnoexcept -Wnoexcept-type -Wnon-template-friend 
-Wnon-virtual-dtor -Woverloaded-virtual -Wpmf-conversions -Wregister -Wreorder 
-Wstrict-null-sentinel -Wsynth -Wuseless-cast  -Wcast-qual    
-D'BOOST_STATIC_ASSERT(A)=static_assert((A))'   -ggdb -O2 
-fno-omit-frame-pointer    /opt/lmi/src/lmi/financial_test.cpp 
-ofinancial_test.o
GC> /opt/lmi/src/lmi/financial_test.cpp: In function ‘int test_main(int, 
char**)’:
GC> /opt/lmi/src/lmi/financial_test.cpp:194:16: error: potential null pointer 
dereference [-Werror=null-dereference]
GC>   194 |     accum_p[0] = p[0] * one_plus_i;
GC> cc1plus: all warnings being treated as errors
GC> make[2]: *** [/opt/lmi/src/lmi/workhorse.make:958: financial_test.o] Error 1
GC> 
GC> The code is:
GC> 
GC>     std::vector<double> p0(7);       // Payments.
GC> [...]
GC>     static double const one_plus_i = 1.0 + i;
GC>     std::vector<double> accum_p(p.size());
GC>     accum_p[0] = p[0] * one_plus_i;
GC> 
GC> AFAICT, if line 194 is reached, then both 'p0' and 'accum_p'
GC> must be vectors with seven elements, so dereferencing their
GC> first elements is valid.

 I didn't have time to test this myself yet, but this definitely looks like
an optimizer bug, i.e. I'm pretty sure that the warning wouldn't happen
when compiling without -O2. I couldn't find anything relevant in gcc bug
tracker, but I'll try to search more thoroughly a bit later.

 Of course, even if I do find a bug, it won't really help much. Disabling
the warning explicitly using pragmas diagnostic push/pop should work, but
the real question is whether the generated code is actually correct.

 Another potential workaround could be to use "optimise" pragma to turn off
optimization for this function (as it's just a test, it might not be a
problem to compile it without optimizations).

 Regards,
VZ

Attachment: pgpvx3ItrbBs7.pgp
Description: PGP signature


reply via email to

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