Gcc O3 compile optimization

Hi All. I’m trying to compile Geant4 with -O3 optimization flags on x86_64-v3, but I get the following warnings when I am compiling:

  [4%] Building CXX object source/CMakeFiles/G4intercoms.dir/intercoms/src/G4VGlobalFastSimulationManager.cc.o
/home/filippo/aur/geant4-full/src/geant4-v11.1.1/source/intercoms/src/G4UImanager.cc: In member function ‘void G4UImanager::SetAlias(const char*)’:
/home/filippo/aur/geant4-full/src/geant4-v11.1.1/source/intercoms/src/G4UImanager.cc:760:20: warning: ‘*(__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type*)((char*)&aliasValue + offsetof(G4String, G4String::<unnamed>.std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::<unnamed>))’ may be used uninitialized [-Wmaybe-uninitialized]
  760 |   if(aliasValue[0] == '"')
/home/filippo/aur/geant4-full/src/geant4-v11.1.1/source/intercoms/src/G4UImanager.cc:759:12: note: ‘aliasValue’ declared here
  759 |   G4String aliasValue = aLine.substr(i + 1, aLine.length() - (i + 1));
      |            ^~~~~~~~~~

and also

[  6%] Building CXX object source/CMakeFiles/G4analysis.dir/analysis/csv/src/G4CsvAnalysisManager.cc.o
In file included from /usr/include/c++/12.2.1/ios:40,
                 from /usr/include/c++/12.2.1/istream:38,
                 from /usr/include/c++/12.2.1/sstream:38,
                 from /usr/include/c++/12.2.1/complex:45,
                 from /home/filippo/aur/geant4-full/src/geant4-v11.1.1/source/global/management/include/G4Types.hh:74,
                 from /home/filippo/aur/geant4-full/src/geant4-v11.1.1/source/global/management/include/G4ios.hh:35,
                 from /home/filippo/aur/geant4-full/src/geant4-v11.1.1/source/global/management/include/globals.hh:35,
                 from /home/filippo/aur/geant4-full/src/geant4-v11.1.1/source/graphics_reps/include/G4AttCheck.hh:46,
                 from /home/filippo/aur/geant4-full/src/geant4-v11.1.1/source/graphics_reps/src/G4AttCheck.cc:28:
In static member function ‘static std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’,
    inlined from ‘static void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12.2.1/bits/basic_string.h:423:21,
    inlined from ‘std::__cxx11::basic_string<_CharT, _Traits, _Allocator>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_replace(size_type, size_type, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12.2.1/bits/basic_string.tcc:532:22,
    inlined from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::assign(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12.2.1/bits/basic_string.h:1647:19,
    inlined from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12.2.1/bits/basic_string.h:815:28,
    inlined from ‘G4AttCheck::G4AttCheck(const std::vector<G4AttValue>*, const std::map<G4String, G4AttDef>*)’ at /home/filippo/aur/geant4-full/src/geant4-v11.1.1/source/graphics_reps/src/G4AttCheck.cc:69:35:
/usr/include/c++/12.2.1/bits/char_traits.h:431:56: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 9223372036854775810 or more bytes at offsets -4611686018427387902 and [-4611686018427387903, 4611686018427387904] may overlap up to 9223372036854775813 bytes at offset -3 [-Wrestrict]
  431 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
      |                                        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

The second warning looks quite important, and it occurs multiple times.
Would it be possible to start looking into using -O3 instead of O2 when compiling, as this would eventually reduce run times?

Cheers

We’re only testing GCC 12.1 at the moment, so as these look like warnings we probably should fix would you mind posting a full report to Bugzilla please: https://bugzilla-geant4.kek.jp

Due to some issues we’ve seen in other builds at O3 level, release build flags are being reviewed for the next release. This may be a drop to O2, or O2 with addition specific options. Part of this work will also be the impact of performance of these combinations in typical Geant4 applications.

1 Like