Can't compile MLIR with clang on windows


I’m trying to compile MLIR on Windows on Arm with a clang-cl.exe that I compiled at commit 945df8bc4cf.

I’m running into an issue in mlir-tblgen\RewriterGen.cpp [1]. I’m attaching the whole error dump, but here’s the TL;DR version:

error: implicit instantiation of undefined template ‘llvm::detail::missing_format_adapter<llvm::SmallVector<std::basic_string, 8> &>’
llvm-project\mlir\tools\mlir-tblgen\RewriterGen.cpp(303,37): note: in instantiation of template class ‘mlir::tblgen::FmtObject<std::tuple<llvm::detail::missing_format_adapter<llvm::SmallVector<std::basic_string, 8> &>>>’ requested here
auto nativeCodeCall = std::string(tgfmt(

I’m not sure I understand the issue correctly, but in any case here’s my interpretation:
There are 2 versions of tgfmt, a templated one with a parameter pack [2], and a non-templated one that takes an ArrayRefstd::string as a parameter. I would expect a call with SmallVector<std::string, 8> to just use the non-templated overload, but we never get to that part because we’re erroring out while trying to find a format adapter. I think SFINAE doesn’t kick in in this case, because the error is not in “an immediate context of the function type”. However, removing the build_format_adapter definition that uses the missing_format_adapter [3] makes it work, because I guess in that case the error is pushed into the immediate context (i.e. we error out because we don’t have a suitable build_format_adapter, not later on because we don’t have a missing_format_adapter).

Am I understanding this right? Is it reasonable to remove missing_format_adapter in order to make build_format_adapter more SFINAE-friendly? Or is there a more principled fix?



build-format-adapter-error.txt (10.2 KB)

+Mehdi AMINI in case he’s got any ideas

I'd take the easy route and change the call site to cast the
SmallVector to ArrayRef so that it selects the overload, or I'd add an
overload for SmallVector as well :slight_smile:

+River Riddle for a more principled fix in how we declare the `tgfmt` functions.