HomePhabricator

[ADT] add iterator_range::empty()

Description

[ADT] add iterator_range::empty()

Event Timeline

I'd like to try adding this back. Do you remember what the failure was? Maybe we can try calling begin() and end() instead of using the fields directly?

I'd like to try adding this back. Do you remember what the failure was? Maybe we can try calling begin() and end() instead of using the fields directly?

No sorry I don't remember. But if you don't have access to a windows build machine to test it yourself I'll try it tomorrow.

I don't. I know Swift's (hopefully superfluous) version of the same code works fine on the MSVC's we support, though: https://github.com/apple/swift/blob/da1002025323cc4199439b10d4c7bac11322d22c/include/swift/Basic/STLExtras.h#L267

Its still broken on VS2017 builds:

E:\llvm\llvm-project\llvm\lib\CodeGen\MachineModuleInfo.cpp(364): error C2668: 'llvm::empty': ambiguous call to overloaded function
E:\llvm\llvm-project\llvm\include\llvm/ADT/STLExtras.h(197): note: could be 'bool llvm::empty<llvm::iterator_range<llvm::Module::debug_compile_units_iterator>>(const T &)'
        with
        [
            T=llvm::iterator_range<llvm::Module::debug_compile_units_iterator>
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\xutility(1650): note: or       'bool std::empty<llvm::iterator_range<llvm::Module::debug_compile_units_iterator>>(const _Container &)' [found using argument-dependent lookup]
        with
        [
            _Container=llvm::iterator_range<llvm::Module::debug_compile_units_iterator>
        ]

The actual issue is that we have a lot of ambiguous empty() calls that VS2017 fails to resolve correctly:

bool MachineModuleInfoWrapperPass::doInitialization(Module &M) {
  MMI.initialize();
  MMI.TheModule = &M;
  MMI.DbgInfoAvailable = !empty(M.debug_compile_units());
  return false;
}

So it might be that making these explicit std::empty or llvm::empty would fix this? If you create a patch someone with a windows machine can test it for you.

It also trips over on VS2019.