Bug 111653 - make bootstrap4 fails for -fchecking=2 code generation changes
Summary: make bootstrap4 fails for -fchecking=2 code generation changes
Alias: None
Product: gcc
Classification: Unclassified
Component: bootstrap (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2023-10-01 13:01 UTC by Sergei Trofimovich
Modified: 2023-11-01 21:12 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2023-10-01 13:01:15 UTC
Reproducer on current gcc master from r14-4353-gf416a3fdbee32a:

    $ ~/dev/git/gcc/configure --disable-multilib --enable-languages=c,c++ CC='gcc -O2' CXX='g++ -O2'
    $ make bootstrap4
    Comparing stages 3 and 4
    Bootstrap comparison failure!
    x86_64-pc-linux-gnu/libstdc++-v3/src/filesystem/dir.o differs
    x86_64-pc-linux-gnu/libstdc++-v3/src/filesystem/cow-dir.o differs
    x86_64-pc-linux-gnu/libstdc++-v3/src/c++20/tzdb.o differs
    x86_64-pc-linux-gnu/libstdc++-v3/src/c++17/cow-fs_path.o differs
    x86_64-pc-linux-gnu/libstdc++-v3/src/c++17/fs_path.o differs
    x86_64-pc-linux-gnu/libstdc++-v3/src/c++17/cow-fs_dir.o differs
    x86_64-pc-linux-gnu/libstdc++-v3/src/c++17/fs_dir.o differs

The failure happens due to the difference between stage3 and stage4 flags:
- stage3: -fchecking=1
- stage4: no flag (debug version implies -fchecking=2 due to `ac_checking_flags=yes,extra` non-release defaults)

Som thoughts:
1. gcc manual says it's fine to see minor code geneation changes on -fchecking=2.
2. there are only 7 files with code generation difference
3. -fchecking=2 detects real bugs like PR111647

It feels like depending on [1.] being a bug or a feature there are a few possible solutions:
a) fix -fchecking=2 instability and change manual to always guarantee that -fchecking=2 does not change code
b) if a) is infeasible then stop using -fchecking=2 for stage compares, say to disable do-compare3 entirely
c) declate 4-stage bootstrap incompatible with `extra` checking flags
d) something else?


Minimal example with -fchecking= instability:

$ cat fs_dir.cc.cc
namespace std {

struct type_info {
  void operator==(const type_info &) const;
struct _Sp_counted_base {
  virtual void _M_get_deleter(const type_info &);
struct _Sp_make_shared_tag {};
template <typename> struct _Sp_counted_ptr_inplace : _Sp_counted_base {
  struct _Impl {
  _Sp_counted_ptr_inplace(int __a) : _M_impl(__a) {}
  void _M_get_deleter(const type_info &__ti) {
    __ti == typeid(_Sp_make_shared_tag);
  _Impl _M_impl;
struct __shared_count {
  __shared_count() { _Sp_counted_ptr_inplace<int>(0); }
} _M_refcount;
} // namespace std

$ g++ -frandom-seed=fs_dir.lo -c fs_dir.cc.cc -fchecking=2 -o bug.o
$ sha1sum bug.o
92d676d60ee6e26e9b242fb64bffe9e47a92052a  bug.o

$ /g++ -frandom-seed=fs_dir.lo -c fs_dir.cc.cc -fchecking=2 -o bug.o -fchecking=1
$ sha1sum bug.o
748b578657a335c212872b012b2afaf0be3ecbc4  bug.o

Note: hashes are different.

$ stage4-gcc/xgcc -Bstage4-gcc -v
Reading specs from stage4-gcc/specs
Target: x86_64-pc-linux-gnu
Configured with: /home/slyfox/dev/git/gcc/configure --disable-multilib --enable-languages=c,c++ CC='gcc -O2' CXX='g++ -O2'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230929 (experimental) (GCC)
Comment 1 Richard Biener 2023-10-04 09:27:23 UTC
IMHO we should try harder to make -fchecking=2 _not_ generate different code.
Comment 2 Sergei Trofimovich 2023-11-01 21:12:50 UTC
The difference on the minimized example from #comment1 disappeared with r14-4793-gdad311874ac3b3 "c++: remove NON_DEPENDENT_EXPR, part 1".

On r14-5058-g25f92179dea308 I don't get comparison failures on 'make bootstrap4' anymore. Let's close it as FIXED.