Bug 86739 - [9 Regression] Bootstrap broken with host GCC 4.1.2
Summary: [9 Regression] Bootstrap broken with host GCC 4.1.2
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: bootstrap (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: 9.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-30 14:04 UTC by Richard Biener
Modified: 2018-11-20 08:39 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-09-04 00:00:00


Attachments
preprocessed source (85.17 KB, application/octet-stream)
2018-07-30 14:18 UTC, Richard Biener
Details
gcc9-pr86739.patch (543 bytes, patch)
2018-11-13 19:55 UTC, Jakub Jelinek
Details | Diff
gcc9-pr86739-2.patch (1001 bytes, patch)
2018-11-13 19:56 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2018-07-30 14:04:32 UTC
Seen on x86_64-linux and ia64-linux.

g++ -std=gnu++98 -c   -g -DIN_GCC    -fno-strict-aliasing -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wwrite-strings -Wcast-qual -Wno-format -Wmissing-format-attribute -Woverloaded-virtual   -DHAVE_CONFIG_H -DGENERATOR_FILE -fno-PIE -I. -Ibuild -I/gcc/spec/sb-vangelis-head-64/gcc/gcc -I/gcc/spec/sb-vangelis-head-64/gcc/gcc/build -I/gcc/spec/sb-vangelis-head-64/gcc/gcc/../include  -I/gcc/spec/sb-vangelis-head-64/gcc/gcc/../libcpp/include  \
                -o build/vec.o /gcc/spec/sb-vangelis-head-64/gcc/gcc/vec.c
/usr/include/c++/4.1.2/bits/stl_pair.h: In instantiation of 'std::pair<mem_location* const&, vec_usage*&>':
/gcc/spec/sb-vangelis-head-64/gcc/gcc/mem-stats.h:597:   instantiated from 'typename mem_alloc_description<T>::mem_list_t* mem_alloc_description<T>::get_list(mem_alloc_origin, unsigned int*, int (*)(const void*, const void*)) [with T = vec_usage]'
/gcc/spec/sb-vangelis-head-64/gcc/gcc/mem-stats.h:637:   instantiated from 'void mem_alloc_description<T>::dump(mem_alloc_origin, int (*)(const void*, const void*)) [with T = vec_usage]'
/gcc/spec/sb-vangelis-head-64/gcc/gcc/vec.c:175:   instantiated from here
/usr/include/c++/4.1.2/bits/stl_pair.h:84: error: forming reference to reference type 'vec_usage*&'
/gcc/spec/sb-vangelis-head-64/gcc/gcc/hash-map.h: In member function 'std::pair<const typename Traits::key_type&, Value&> hash_map< <template-parameter-1-1>, <template-parameter-1-2>, <template-parameter-1-3> >::iterator::operator*() [with KeyId = mem_alloc_description<vec_usage>::mem_location_hash, Value = vec_usage*, Traits = simple_hashmap_traits<default_hash_traits<mem_alloc_description<vec_usage>::mem_location_hash>, vec_usage*>]':
/gcc/spec/sb-vangelis-head-64/gcc/gcc/mem-stats.h:597:   instantiated from 'typename mem_alloc_description<T>::mem_list_t* mem_alloc_description<T>::get_list(mem_alloc_origin, unsigned int*, int (*)(const void*, const void*)) [with T = vec_usage]'
/gcc/spec/sb-vangelis-head-64/gcc/gcc/mem-stats.h:637:   instantiated from 'void mem_alloc_description<T>::dump(mem_alloc_origin, int (*)(const void*, const void*)) [with T = vec_usage]'
/gcc/spec/sb-vangelis-head-64/gcc/gcc/vec.c:175:   instantiated from here
/gcc/spec/sb-vangelis-head-64/gcc/gcc/hash-map.h:229: error: no matching function for call to 'std::pair<mem_location* const&, vec_usage*&>::pair(mem_location*&, vec_usage*&)'
/usr/include/c++/4.1.2/bits/stl_pair.h:80: note: candidates are: std::pair<_T1, _T2>::pair() [with _T1 = mem_location* const&, _T2 = vec_usage*&]
/usr/include/c++/4.1.2/bits/stl_pair.h:69: note:                 std::pair<mem_location* const&, vec_usage*&>::pair(const std::pair<mem_location* const&, vec_usage*&>&)
make[3]: *** [build/vec.o] Error 1
Comment 1 Richard Biener 2018-07-30 14:14:12 UTC
Regressed between r262525 (good) and r262545 (bad).  Thus probably caused by
r262539.

/usr/include/c++/4.1.2/bits/stl_pair.h:84 is

      /** Two objects may be passed to a @c pair constructor to be copied.  */
      pair(const _T1& __a, const _T2& __b)
      : first(__a), second(__b) { }

so it somehow doesn't like _T1 == vec_usage*& here I added with

    std::pair<const Key&, Value&> operator* ()
    {
      hash_entry &e = *m_iter;
      return std::pair<const Key&, Value&> (e.m_key, e.m_value);
    }

C++ folks?
Comment 2 Richard Biener 2018-07-30 14:18:00 UTC
Created attachment 44466 [details]
preprocessed source

For reference, here's preprocessed source.
Comment 3 Jonathan Wakely 2018-07-30 14:43:37 UTC
The code is well-formed according to http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#106 but that doesn't seem to be implemented in GCC 4.1.2

template<typename T>
struct X {
    X(T&) { }
};

X<int&> f(int& i)
{
    return X<int&>(i);
}

<source>: In instantiation of 'X<int&>':
<source>:6:   instantiated from here
<source>:3: error: forming reference to reference type 'int&'
Comment 4 Jonathan Wakely 2018-07-30 14:47:13 UTC
See PR 7412

"Fixed on mainline for GCC 4.3.0. DR 106 is implemented for C++0x mode and for non-strict C++98 mode."
Comment 5 Richard Biener 2018-07-31 09:17:46 UTC
So somehow mem_alloc_description<vec_usage>::mem_map_t which then is

hash_map <mem_location_hash, vec_usage *> ends up with this reference type.
But I can't figure out how :/  It in the end uses pointer_hash which has
value/compare type of T * again with T == mem_location.

hash_entry of the hash-map should have Value == vec_usage *, so I'm confused
as to where the reference appears.

ISTR figuring the default hash_map<> template resolution is a bit tricky.
Comment 6 Jonathan Wakely 2018-08-01 19:45:48 UTC
(In reply to Richard Biener from comment #5)
> ISTR figuring the default hash_map<> template resolution is a bit tricky.

ISTR thinking it was rather overcomplicated.
Comment 7 Eric Gallager 2018-09-04 23:14:09 UTC
Iain confirmed this on IRC for darwin
Comment 8 Jakub Jelinek 2018-11-13 18:33:35 UTC
https://godbolt.org/z/DcywdN
Apparently std::pair with reference template arguments (either of them) just doesn't work in 4.1 at all because of that missing CWG.

So, do we require that hash_map's iterator's operator * returns std::pair, or can it return some other class that has first and second members?
Comment 9 Jakub Jelinek 2018-11-13 19:55:22 UTC
Created attachment 45000 [details]
gcc9-pr86739.patch

This works for me (well, make in gcc/ with recent gcc still builds and the preprocessed source from this PR with those tweaks compiles with GCC 4.1).
Comment 10 Jakub Jelinek 2018-11-13 19:56:18 UTC
Created attachment 45001 [details]
gcc9-pr86739-2.patch

Variant patch if the conversion operator would not be acceptable.
Comment 11 Jakub Jelinek 2018-11-14 16:44:10 UTC
Author: jakub
Date: Wed Nov 14 16:43:38 2018
New Revision: 266152

URL: https://gcc.gnu.org/viewcvs?rev=266152&root=gcc&view=rev
Log:
	PR bootstrap/86739
	* hash-map.h (hash_map::iterator::reference_pair): New class.
	(hash_map::iterator::operator*): Return it rather than std::pair.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/hash-map.h
Comment 12 Martin Liška 2018-11-20 08:35:30 UTC
Jakub: Can the bug be marked as resolved?
Comment 13 Jakub Jelinek 2018-11-20 08:39:49 UTC
I haven't tested such a bootstrap, but I hope it is ok.