Bug 96901 - [11 Regression] Many libstdc++ tests FAIL on i686-linux due to a PCH FE bug
Summary: [11 Regression] Many libstdc++ tests FAIL on i686-linux due to a PCH FE bug
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.0
: P1 normal
Target Milestone: 11.0
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-02 16:51 UTC by Jakub Jelinek
Modified: 2020-10-16 12:07 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-09-02 00:00:00


Attachments
gcc11-pr96901.patch (699 bytes, patch)
2020-09-02 16:57 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2020-09-02 16:51:59 UTC
I'm seeing following regressions between Monday and Tuesday evening CET trunk bootstraps:
 Running target unix
+FAIL: 20_util/bind/42593.cc (test for excess errors)
+FAIL: 20_util/bind/48698.cc (test for excess errors)
+FAIL: 20_util/is_compound/value.cc (test for excess errors)
+FAIL: 20_util/is_fundamental/value.cc (test for excess errors)
+FAIL: 20_util/is_signed/value.cc (test for excess errors)
+FAIL: 20_util/is_unsigned/value.cc (test for excess errors)
+FAIL: 20_util/unique_ptr/assign/nullptr.cc (test for excess errors)
+UNRESOLVED: 20_util/unique_ptr/assign/nullptr.cc compilation failed to produce executable
+FAIL: 20_util/unique_ptr/cons/convertible_neg.cc (test for excess errors)
+FAIL: 20_util/unique_ptr/cons/incomplete.cc (test for excess errors)
+FAIL: 20_util/unique_ptr/cons/nullptr.cc (test for excess errors)
+UNRESOLVED: 20_util/unique_ptr/cons/nullptr.cc compilation failed to produce executable
+FAIL: 20_util/unique_ptr/requirements/explicit_instantiation/explicit_instantiation.cc (test for excess errors)
+FAIL: 21_strings/basic_string/allocator/wchar_t/noexcept.cc (test for excess errors)
+FAIL: 22_locale/conversions/string/requirements/typedefs-2.cc (test for excess errors)
+FAIL: 23_containers/list/allocator/noexcept.cc (test for excess errors)
+FAIL: 23_containers/map/modifiers/insert/2.cc (test for excess errors)
+UNRESOLVED: 23_containers/map/modifiers/insert/2.cc compilation failed to produce executable
+FAIL: 23_containers/map/modifiers/insert/5.cc (test for excess errors)
+UNRESOLVED: 23_containers/map/modifiers/insert/5.cc compilation failed to produce executable
+FAIL: 23_containers/multimap/modifiers/insert/2.cc (test for excess errors)
+UNRESOLVED: 23_containers/multimap/modifiers/insert/2.cc compilation failed to produce executable
+FAIL: 23_containers/multimap/modifiers/insert/22102.cc (test for excess errors)
+UNRESOLVED: 23_containers/multimap/modifiers/insert/22102.cc compilation failed to produce executable
+FAIL: 23_containers/multimap/modifiers/insert/4.cc (test for excess errors)
+UNRESOLVED: 23_containers/multimap/modifiers/insert/4.cc compilation failed to produce executable
+FAIL: 23_containers/multiset/allocator/swap.cc (test for excess errors)
+UNRESOLVED: 23_containers/multiset/allocator/swap.cc compilation failed to produce executable
+FAIL: 23_containers/set/allocator/swap.cc (test for excess errors)
+UNRESOLVED: 23_containers/set/allocator/swap.cc compilation failed to produce executable
+FAIL: 23_containers/unordered_map/insert/map_single_move-2.cc (test for excess errors)
+UNRESOLVED: 23_containers/unordered_map/insert/map_single_move-2.cc compilation failed to produce executable
+FAIL: 23_containers/unordered_map/modifiers/reserve.cc (test for excess errors)
+UNRESOLVED: 23_containers/unordered_map/modifiers/reserve.cc compilation failed to produce executable
+FAIL: 23_containers/vector/allocator/noexcept.cc (test for excess errors)
+FAIL: 23_containers/vector/bool/allocator/noexcept.cc (test for excess errors)
+FAIL: 25_algorithms/max/constexpr.cc (test for excess errors)
+FAIL: 25_algorithms/min/constexpr.cc (test for excess errors)
+FAIL: 26_numerics/random/cauchy_distribution/cons/default.cc (test for excess errors)
+UNRESOLVED: 26_numerics/random/cauchy_distribution/cons/default.cc compilation failed to produce executable
+FAIL: 26_numerics/random/extreme_value_distribution/cons/default.cc (test for excess errors)
+UNRESOLVED: 26_numerics/random/extreme_value_distribution/cons/default.cc compilation failed to produce executable
+FAIL: 26_numerics/random/normal_distribution/cons/default.cc (test for excess errors)
+UNRESOLVED: 26_numerics/random/normal_distribution/cons/default.cc compilation failed to produce executable
+FAIL: 26_numerics/random/student_t_distribution/cons/default.cc (test for excess errors)
+UNRESOLVED: 26_numerics/random/student_t_distribution/cons/default.cc compilation failed to produce executable
+FAIL: 28_regex/match_results/ctors/wchar_t/default.cc (test for excess errors)
+UNRESOLVED: 28_regex/match_results/ctors/wchar_t/default.cc compilation failed to produce executable
 FAIL: 29_atomics/atomic_float/1.cc execution test
+FAIL: 30_threads/thread/adl.cc (test for excess errors)
+FAIL: experimental/net/buffer/traits.cc (test for excess errors)
+FAIL: experimental/net/execution_context/make_service.cc (test for excess errors)
 FAIL: experimental/net/internet/resolver/ops/lookup.cc execution test
+FAIL: experimental/optional/relops/2.cc (test for excess errors)
+UNRESOLVED: experimental/optional/relops/2.cc compilation failed to produce executable
+FAIL: experimental/optional/relops/3.cc (test for excess errors)
+UNRESOLVED: experimental/optional/relops/3.cc compilation failed to produce executable
+FAIL: ext/random/normal_mv_distribution/cons/default.cc (test for excess errors)
+UNRESOLVED: ext/random/normal_mv_distribution/cons/default.cc compilation failed to produce executable
 
 		=== libstdc++ Summary ===
 
-# of expected passes		15192
-# of unexpected failures	2
+# of expected passes		15136
+# of unexpected failures	40
 # of expected failures		98
+# of unresolved testcases	19
 # of unsupported tests		334
 
-Compiler version: 11.0.0 20200831 (experimental) (GCC) 
+Compiler version: 11.0.0 20200901 (experimental) (GCC) 
 Platform: i686-pc-linux-gnu

The regressions ICEs are all PCH related, with ICEs like:
FAIL: 20_util/bind/42593.cc (test for excess errors)
Excess errors:
/home/jakub/src/gcc/obj71/i686-pc-linux-gnu/libstdc++-v3/include/chrono:441:   in 'constexpr' expansion of 'std::chrono::duration<long long int, std::ratio<1, 1000000000> >::_S_gcd(((intmax_t)std::ratio<1>::den), ((intmax_t)std::ratio<1, 1000000000>::den))'
/home/jakub/src/gcc/obj71/i686-pc-linux-gnu/libstdc++-v3/include/chrono:442: internal compiler error: Segmentation fault
0x8dd035a crash_signal
        ../../gcc/toplev.c:327
0x86877b6 cxx_eval_call_expression
        ../../gcc/cp/constexpr.c:2622
0x8688782 cxx_eval_constant_expression
        ../../gcc/cp/constexpr.c:5765
0x868bcab cxx_eval_outermost_constant_expr
        ../../gcc/cp/constexpr.c:6772
0x86901c0 maybe_constant_value(tree_node*, tree_node*, bool)
        ../../gcc/cp/constexpr.c:7045
0x87195dc fold_for_warn(tree_node*)
        ../../gcc/cp/expr.c:418

It is PCH related and very hard to reproduce, after all, the same cc1plus doesn't crash always, but only sometimes.
I've tracked it to what seems to be another occurrence of PR92458, this time on fundef_copies_table.  This is a non-deletable non-cache hash_map<tree, tree> preserved across PCH, which means it is hashed when compiling the PCH header using pointer hashing of the decls, then PCH reassigns addresses to GC registered objects.  When PCH is read, the hash_map will usually contain keys with different hash values compared to what it hashed originally, so there are chances that some fundef->decl isn't found.  The ICE is because we don't find an entry for _S_gcd, so add a for now NULL value to that function, but the addition  to the hash table results in later call not finding that NULL entry, but some other one from before PCH was saved, which results in very bad things for recursive constexpr calls.
Comment 1 Jakub Jelinek 2020-09-02 16:57:22 UTC
Created attachment 49176 [details]
gcc11-pr96901.patch

Untested fix.
Comment 2 CVS Commits 2020-09-03 19:54:28 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:ba6730bd18371a3dff1e37d2c2ee27233285b597

commit r11-3001-gba6730bd18371a3dff1e37d2c2ee27233285b597
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Sep 3 21:53:40 2020 +0200

    c++: Fix another PCH hash_map issue [PR96901]
    
    The recent libstdc++ changes caused lots of libstdc++-v3 tests FAILs
    on i686-linux, all of them in the same spot during constexpr evaluation
    of a recursive _S_gcd call.
    The problem is yet another hash_map that used the default hasing of
    tree keys through pointer hashing which is preserved across PCH write/read.
    During PCH handling, the addresses of GC objects are changed, which means
    that the hash values of the keys in such hash tables change without those
    hash tables being rehashed.  Which in the fundef_copies_table case usually
    means we just don't find a copy of a FUNCTION_DECL body for recursive uses
    and start from scratch.  But when the hash table keeps growing, the "dead"
    elements in the hash table can sometimes reappear and break things.
    In particular what I saw under the debugger is when the fundef_copies_table
    hash map has been used on the outer _S_gcd call, it didn't find an entry for
    it, so returned a slot with *slot == NULL, which is treated as that the
    function itself is used directly (i.e. no recursion), but that addition of
    a hash table slot caused the recursive _S_gcd call to actually find
    something in the hash table, unfortunately not the new *slot == NULL spot,
    but a different one from the pre-PCH streaming which contained the returned
    toplevel (non-recursive) call entry for it, which means that for the
    recursive _S_gcd call we actually used the same trees as for the outer ones
    rather than a copy of those, which breaks constexpr evaluation.
    
    2020-09-03  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/96901
            * tree.h (struct decl_tree_traits): New type.
            (decl_tree_map): New typedef.
    
            * constexpr.c (fundef_copies_table): Change type from
            hash_map<tree, tree> * to decl_tree_map *.
Comment 3 CVS Commits 2020-09-11 07:47:50 UTC
The releases/gcc-10 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:3dfe983656318c1aaa33c7f9a5a341c5904aa5b6

commit r10-8732-g3dfe983656318c1aaa33c7f9a5a341c5904aa5b6
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Sep 3 21:53:40 2020 +0200

    c++: Fix another PCH hash_map issue [PR96901]
    
    The recent libstdc++ changes caused lots of libstdc++-v3 tests FAILs
    on i686-linux, all of them in the same spot during constexpr evaluation
    of a recursive _S_gcd call.
    The problem is yet another hash_map that used the default hasing of
    tree keys through pointer hashing which is preserved across PCH write/read.
    During PCH handling, the addresses of GC objects are changed, which means
    that the hash values of the keys in such hash tables change without those
    hash tables being rehashed.  Which in the fundef_copies_table case usually
    means we just don't find a copy of a FUNCTION_DECL body for recursive uses
    and start from scratch.  But when the hash table keeps growing, the "dead"
    elements in the hash table can sometimes reappear and break things.
    In particular what I saw under the debugger is when the fundef_copies_table
    hash map has been used on the outer _S_gcd call, it didn't find an entry for
    it, so returned a slot with *slot == NULL, which is treated as that the
    function itself is used directly (i.e. no recursion), but that addition of
    a hash table slot caused the recursive _S_gcd call to actually find
    something in the hash table, unfortunately not the new *slot == NULL spot,
    but a different one from the pre-PCH streaming which contained the returned
    toplevel (non-recursive) call entry for it, which means that for the
    recursive _S_gcd call we actually used the same trees as for the outer ones
    rather than a copy of those, which breaks constexpr evaluation.
    
    2020-09-03  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/96901
            * tree.h (struct decl_tree_traits): New type.
            (decl_tree_map): New typedef.
    
            * constexpr.c (fundef_copies_table): Change type from
            hash_map<tree, tree> * to decl_tree_map *.
    
    (cherry picked from commit ba6730bd18371a3dff1e37d2c2ee27233285b597)
Comment 4 Richard Biener 2020-10-16 12:07:13 UTC
Fixed.