Skip to content

Commit 75a546d

Browse files
committed
[Lint] Add check to prevent usage of #include <regex>
Currently, the pytorch wheels available through `pip install` use the pre-C++11 ABI by setting `-DUSE_CXX11_ABI=0` [0]. If TVM were to user the pre-C++11 ABI, this would cause breakages with dynamically-linked LLVM environments. This commit adds a lint check to search for use of `#include <regex>` in any C++ files. Use of this header should be avoided, as its implementation is not supported by gcc's dual ABI. This ABI incompatibility results in runtime errors either when `std::regex` is called from TVM, or when `std::regex` is called from pytorch, depending on which library was loaded first. This restriction can be removed when a version of pytorch compiled using `-DUSE_CXX11_ABI=1` is available from PyPI. [0] pytorch/pytorch#51039
1 parent 268d15c commit 75a546d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/lint/cpplint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,13 @@ python3 3rdparty/dmlc-core/scripts/lint.py --quiet tvm cpp \
2828
"src/runtime/hexagon/rpc/hexagon_rpc_skel.c" \
2929
"src/runtime/hexagon/rpc/hexagon_rpc_stub.c" \
3030
"src/relay/backend/contrib/libtorch/libtorch_codegen.cc"
31+
32+
33+
if find src -name "*.cc" -exec grep -Hn '^#include <regex>$' {} +; then
34+
echo "The <regex> header file may not be used in TVM," 1>&2
35+
echo "because it causes ABI incompatibility with most pytorch installations." 1>&2
36+
echo "Pytorch packages on PyPI currently set `-DUSE_CXX11_ABI=0`," 1>&2
37+
echo "which causes ABI compatibility when calling <regex> functions." 1>&2
38+
echo "See https://github.com/pytorch/pytorch/issues/51039 for more details." 1>&2
39+
exit 1
40+
fi

0 commit comments

Comments
 (0)