LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 24115 - llvm-nm fails to build with gcc 5.1's libstdc++
Summary: llvm-nm fails to build with gcc 5.1's libstdc++
Status: RESOLVED FIXED
Alias: None
Product: tools
Classification: Unclassified
Component: llvm-nm (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-14 04:54 PDT by Bernhard Rosenkraenzer
Modified: 2019-08-15 14:07 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments
Patch (1.03 KB, patch)
2015-07-14 04:54 PDT, Bernhard Rosenkraenzer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bernhard Rosenkraenzer 2015-07-14 04:54:59 PDT
Created attachment 14586 [details]
Patch

Current (svn rev. 242129) llvm-nm fails to build with gcc 5.1's STL -- looks like gcc 5.1's std::sort is too picky about its arguments:


cd /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/build/tools/llvm-nm && /usr/bin/clang++   -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Oz -gdwarf-4 -Wstrict-aliasing=2 -pipe -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4  -fPIC -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -std=c++1y -ffunction-sections -fdata-sections -Oz -gdwarf-4 -Wstrict-aliasing=2 -pipe -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4  -fPIC -I/home/bero/abf/llvm/BUILD/llvm-3.7.0.src/build/tools/llvm-nm -I/home/bero/abf/llvm/BUILD/llvm-3.7.0.src/tools/llvm-nm -I/home/bero/abf/llvm/BUILD/llvm-3.7.0.src/build/include -I/home/bero/abf/llvm/BUILD/llvm-3.7.0.src/include    -o CMakeFiles/llvm-nm.dir/llvm-nm.cpp.o -c /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/tools/llvm-nm/llvm-nm.cpp
In file included from /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/tools/llvm-nm/llvm-nm.cpp:19:
In file included from /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/include/llvm/IR/Function.h:23:
In file included from /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/include/llvm/IR/Argument.h:17:
In file included from /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/include/llvm/ADT/Twine.h:13:
In file included from /home/bero/abf/llvm/BUILD/llvm-3.7.0.src/include/llvm/ADT/SmallVector.h:22:
In file included from /usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/algorithm:61:
In file included from /usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/bits/stl_algobase.h:71:
/usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/bits/predefined_ops.h:123:31: error: indirection requires pointer operand ('(anonymous namespace)::NMSymbol' invalid)
        { return bool(_M_comp(*__it1, *__it2)); }
                              ^~~~~~
/usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/functional:1981:27: note: in instantiation of function template specialization '__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (const (anonymous namespace)::NMSymbol &, const (anonymous namespace)::NMSymbol &)> >::operator()<(anonymous namespace)::NMSymbol, (anonymous namespace)::NMSymbol>' requested here
        using _Invoke = decltype(__callable_functor(std::declval<_Functor&>())
                                 ^
/usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/functional:1990:2: note: in instantiation of template type alias '_Invoke' requested here
        using _Callable
        ^
/usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/functional:2057:30: note: in instantiation of template type alias '_Callable' requested here
               typename = _Requires<_Callable<_Functor>, void>>
                                    ^
/usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/functional:2058:2: note: in instantiation of default argument for 'function<__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (const (anonymous namespace)::NMSymbol &, const (anonymous namespace)::NMSymbol &)> > >' required here
        function(_Functor);
        ^~~~~~~~
/usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/bits/predefined_ops.h:130:14: note: while substituting deduced template arguments into function template 'function' [with _Functor = __gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (const (anonymous namespace)::NMSymbol &, const (anonymous namespace)::NMSymbol &)> >, $1 = (no value)]
    { return _Iter_comp_iter<_Compare>(__comp); }
             ^
/usr/bin/../lib64/gcc/x86_64-mandriva-linux-gnu/5.1.1/../../../../include/c++/5.1.1/bits/stl_algo.h:4729:54: note: in instantiation of function template specialization '__gnu_cxx::__ops::__iter_comp_iter<std::function<bool (const (anonymous namespace)::NMSymbol &, const (anonymous namespace)::NMSymbol &)> >' requested here
      std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp));
                                                     ^
/home/bero/abf/llvm/BUILD/llvm-3.7.0.src/tools/llvm-nm/llvm-nm.cpp:499:10: note: in instantiation of function template specialization 'std::sort<__gnu_cxx::__normal_iterator<(anonymous namespace)::NMSymbol *, std::vector<(anonymous namespace)::NMSymbol, std::allocator<(anonymous namespace)::NMSymbol> > >, std::function<bool (const (anonymous namespace)::NMSymbol &, const (anonymous namespace)::NMSymbol &)> >' requested here
    std::sort(SymbolList.begin(), SymbolList.end(), Cmp);
         ^
1 error generated.
tools/llvm-nm/CMakeFiles/llvm-nm.dir/build.make:65: recipe for target 'tools/llvm-nm/CMakeFiles/llvm-nm.dir/llvm-nm.cpp.o' failed


The patch I'm attaching solves the problem for me, at the cost of making the code somewhat ugly.
Comment 1 Rafael Ávila de Espíndola 2015-07-14 12:09:09 PDT
Please send patches to llvm-commit.
Comment 2 Stephan Bergmann 2015-09-29 16:04:02 PDT
The same error related to combining std::sort and std::function hits when compiling LibreOffice with -std=c++14 against GCC 5.1 libstdc++.  It is unclear to me whether this is an issue with Clang or with libstdc++.  I was able to essentially reduce the issue to the following reproducer (where I hope it really still captures the same problem as the original code), reproducible with all versions of Clang from current trunk all the way back to at least Clang 3.2:

> $ cat test.cc
> template<typename T> T v();
> struct Func { template<typename T, typename = decltype(v<T>()(0))> Func(T); };
> template<typename F> struct Inst {
>     F fn;
>     Inst(F);
>     template<typename T> constexpr int operator ()(T x) const { return fn(*x); }
> };
> Inst<Func> f(Func fn) { return Inst<Func>(fn); }
> 
> $ clang++ -fsyntax-only -std=c++11 test.cc
> test.cc:6:75: error: indirection requires pointer operand ('int' invalid)
>     template<typename T> constexpr int operator ()(T x) const { return fn(*x); }
>                                                                           ^~
> test.cc:2:56: note: in instantiation of function template specialization 'Inst<Func>::operator()<int>' requested here
> struct Func { template<typename T, typename = decltype(v<T>()(0))> Func(T); };
>                                                        ^
> test.cc:2:68: note: in instantiation of default argument for 'Func<Inst<Func> >' required here
> struct Func { template<typename T, typename = decltype(v<T>()(0))> Func(T); };
>                                                                    ^~~~~~~
> test.cc:8:32: note: while substituting deduced template arguments into function template 'Func'
>       [with T = Inst<Func>, $1 = (no value)]
> Inst<Func> f(Func fn) { return Inst<Func>(fn); }
>                                ^
> 1 error generated.

It is unclear to me why Clang would want to instantiate Func<Inst<Func>> at all.

The problem goes away when removing the "constexpr" in line 6 (which appears to be the reason why the original problem only occurs with -std=c++14, as the corresponding "constexpr" in the original libstdc++ code is conditionally enabled only for -std=c++14).
Comment 3 JF Bastien 2019-08-15 14:07:57 PDT
Jordan Rupprecht pointed me at this bug, looks like I fixed it in https://reviews.llvm.org/D66310