diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" #include "llvm/IR/LLVMContext.h" @@ -1179,16 +1180,20 @@ llvm::InitializeAllAsmParsers(); Stem = sys::path::stem(ToolName); - if (Stem.contains_lower("dlltool")) + auto Is = [](StringRef Tool) { + auto I = Stem.rfind(Tool); + return I != StringRef::npos && + (I + Tool.size() == Stem.size() || !isAlnum(Stem[I + Tool.size()])); + }; + + if (Is("dlltool")) return dlltoolDriverMain(makeArrayRef(argv, argc)); - - if (Stem.contains_lower("ranlib")) + if (Is("ranlib")) return ranlib_main(argc, argv); - - if (Stem.contains_lower("lib")) + if (Is("lib")) return libDriverMain(makeArrayRef(argv, argc)); - - if (Stem.contains_lower("ar")) + if (Is("ar")) return ar_main(argc, argv); + fail("not ranlib, ar, lib or dlltool"); }