Skip to content

Build failure when targeting LLVM 11.0 #87

Open
@kcgen

Description

@kcgen

MacOS has moved to Clang 11, and for create_llvm_prof to target it we need to build autofdo --with-llvm=$(which llvm-config-11). The configuration phase passes, but building the create_llvm_prof binary fail both with gcc-9.x and clang-11 due to a missing operator[] in llvm_profile_writer.cc.

When building with GCC-9:

g++-9 -DHAVE_CONFIG_H -I. -I./glog/src  -I. -I./glog/src -I./third_party/perf_data_converter/src/quipper -I./third_party/protobuf/src  -I/usr/lib/llvm-11/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DCREATE_LLVM_PROF -g -O2 -MT create_llvm_prof-llvm_profile_writer.o -MD -MP -MF .deps/create_llvm_prof-llvm_profile_writer.Tpo -c -o create_llvm_prof-llvm_profile_writer.o `test -f 'llvm_profile_writer.cc' || echo './'`llvm_profile_writer.cc
llvm_profile_writer.cc: In member function ‘virtual void autofdo::LLVMProfileBuilder::VisitCallsite(const Callsite&)’:
llvm_profile_writer.cc:100:32: error: no match for ‘operator[]’ (operand types are ‘llvm::sampleprof::FunctionSamplesMap’ {aka ‘std::map<std::__cxx11::basic_string<char>, llvm::sampleprof::FunctionSamples, std::less<void> >’} and ‘llvm::StringRef’)
  100 |           line, discriminator))[CalleeName];
      |                                ^
In file included from /usr/include/c++/9/map:61,
                 from llvm_profile_writer.cc:22:
/usr/include/c++/9/bits/stl_map.h:490:7: note: candidate: ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::__cxx11::basic_string<char>; _Tp = llvm::sampleprof::FunctionSamples; _Compare = std::less<void>; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, llvm::sampleprof::FunctionSamples> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = llvm::sampleprof::FunctionSamples; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::__cxx11::basic_string<char>]’
  490 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_map.h:490:34: note:   no known conversion for argument 1 from ‘llvm::StringRef’ to ‘const key_type&’ {aka ‘const std::__cxx11::basic_string<char>&’}
  490 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_map.h:510:7: note: candidate: ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = std::__cxx11::basic_string<char>; _Tp = llvm::sampleprof::FunctionSamples; _Compare = std::less<void>; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, llvm::sampleprof::FunctionSamples> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = llvm::sampleprof::FunctionSamples; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::__cxx11::basic_string<char>]’
  510 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_map.h:510:29: note:   no known conversion for argument 1 from ‘llvm::StringRef’ to ‘std::map<std::__cxx11::basic_string<char>, llvm::sampleprof::FunctionSamples, std::less<void> >::key_type&&’ {aka ‘std::__cxx11::basic_string<char>&&’}
  510 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
make[1]: *** [Makefile:1234: create_llvm_prof-llvm_profile_writer.o] Error 1

When building with Clang-11:

clang++-11 -DHAVE_CONFIG_H -I. -I./glog/src  -I. -I./glog/src -I./third_party/perf_data_converter/src/quipper -I./third_party/protobuf/src  -I/usr/lib/llvm-11/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DCREATE_LLVM_PROF -g -O2 -MT create_llvm_prof-llvm_profile_writer.o -MD -MP -MF .deps/create_llvm_prof-llvm_profile_writer.Tpo -c -o create_llvm_prof-llvm_profile_writer.o `test -f 'llvm_profile_writer.cc' || echo './'`llvm_profile_writer.cc
In file included from llvm_profile_writer.cc:30:
In file included from ./llvm_profile_writer.h:7:
./profile_writer.h:186:8: warning: 'VisitCallsite' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  void VisitCallsite(const Callsite &callsite) {
       ^
./profile_writer.h:152:16: note: overridden virtual function is here
  virtual void VisitCallsite(const Callsite &offset) {}
               ^
llvm_profile_writer.cc:100:32: error: no viable overloaded operator[] for type 'llvm::sampleprof::FunctionSamplesMap' (aka 'map<basic_string<char>, llvm::sampleprof::FunctionSamples, less<> >')
          line, discriminator))[CalleeName];
          ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_map.h:490:7: note: candidate function not viable: no known conversion from 'llvm::StringRef' to 'const std::map<std::__cxx11::basic_string<char>, llvm::sampleprof::FunctionSamples, std::less<void>, std::allocator<std::pair<const std::__cxx11::basic_string<char>, llvm::sampleprof::FunctionSamples> > >::key_type' (aka 'const std::__cxx11::basic_string<char>') for 1st argument
      operator[](const key_type& __k)
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_map.h:510:7: note: candidate function not viable: no known conversion from 'llvm::StringRef' to 'std::map<std::__cxx11::basic_string<char>, llvm::sampleprof::FunctionSamples, std::less<void>, std::allocator<std::pair<const std::__cxx11::basic_string<char>, llvm::sampleprof::FunctionSamples> > >::key_type' (aka 'std::__cxx11::basic_string<char>') for 1st argument
      operator[](key_type&& __k)
      ^
1 warning and 1 error generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions