Index: clang/test/Analysis/scan-build/lit.local.cfg =================================================================== --- clang/test/Analysis/scan-build/lit.local.cfg +++ clang/test/Analysis/scan-build/lit.local.cfg @@ -4,6 +4,11 @@ import lit.formats import os +# The os.path.realpath(config.clang) further down finds the +# llvm executable and not clang. +if config.is_llvm_driver: + config.unsupported = True + use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL") config.test_format = lit.formats.ShTest(use_lit_shell == "0") Index: clang/test/CMakeLists.txt =================================================================== --- clang/test/CMakeLists.txt +++ clang/test/CMakeLists.txt @@ -15,6 +15,7 @@ LLVM_ENABLE_PER_TARGET_RUNTIME_DIR LLVM_ENABLE_THREADS LLVM_WITH_Z3 + LLVM_TOOL_LLVM_DRIVER_BUILD ) configure_lit_site_cfg( @@ -72,7 +73,7 @@ diagtool hmaptool ) - + if(CLANG_ENABLE_STATIC_ANALYZER) list(APPEND CLANG_TEST_DEPS clang-check Index: clang/test/lit.site.cfg.py.in =================================================================== --- clang/test/lit.site.cfg.py.in +++ clang/test/lit.site.cfg.py.in @@ -39,6 +39,7 @@ config.clang_vendor_uti = "@CLANG_VENDOR_UTI@" config.llvm_external_lit = path(r"@LLVM_EXTERNAL_LIT@") config.standalone_build = @CLANG_BUILT_STANDALONE@ +config.is_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@ import lit.llvm lit.llvm.initialize(lit_config, config) Index: clang/tools/driver/driver.cpp =================================================================== --- clang/tools/driver/driver.cpp +++ clang/tools/driver/driver.cpp @@ -37,6 +37,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" #include "llvm/Support/InitLLVM.h" +#include "llvm/Support/LLVMDriver.h" #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Process.h" @@ -55,7 +56,7 @@ using namespace llvm::opt; std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) { - if (!CanonicalPrefixes) { + if (!CanonicalPrefixes || llvm::IsLLVMDriver) { SmallString<128> ExecutablePath(Argv0); // Do a PATH lookup if Argv0 isn't a valid path. if (!llvm::sys::fs::exists(ExecutablePath)) @@ -269,12 +270,14 @@ } static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient, - const std::string &Path) { + const std::string &Path, llvm::StringRef Argv0) { // If the clang binary happens to be named cl.exe for compatibility reasons, // use clang-cl.exe as the prefix to avoid confusion between clang and MSVC. StringRef ExeBasename(llvm::sys::path::stem(Path)); if (ExeBasename.equals_insensitive("cl")) ExeBasename = "clang-cl"; + if (llvm::IsLLVMDriver) + ExeBasename = llvm::sys::path::stem(Argv0); DiagClient->setPrefix(std::string(ExeBasename)); } @@ -450,7 +453,7 @@ TextDiagnosticPrinter *DiagClient = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); - FixupDiagPrefixExeName(DiagClient, Path); + FixupDiagPrefixExeName(DiagClient, Path, Args[0]); IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); Index: llvm/cmake/modules/llvm-driver-template.cpp.in =================================================================== --- llvm/cmake/modules/llvm-driver-template.cpp.in +++ llvm/cmake/modules/llvm-driver-template.cpp.in @@ -6,6 +6,12 @@ // //===----------------------------------------------------------------------===// +namespace llvm { + +extern const bool IsLLVMDriver = false; + +} // namespace llvm + int @TOOL_NAME@_main(int argc, char **argv); int main(int argc, char **argv) { return @TOOL_NAME@_main(argc, argv); } Index: llvm/include/llvm/Support/LLVMDriver.h =================================================================== --- /dev/null +++ llvm/include/llvm/Support/LLVMDriver.h @@ -0,0 +1,17 @@ +//===- LLVMDriver.h ---------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// The llvm-driver is an executable which statically links in many llvm tools +// into one. This can be useful for tools which need to behave slightly +// differently under that environment. +// +//===----------------------------------------------------------------------===// + +namespace llvm { +extern const bool IsLLVMDriver; +} // namespace llvm Index: llvm/lib/Support/Path.cpp =================================================================== --- llvm/lib/Support/Path.cpp +++ llvm/lib/Support/Path.cpp @@ -1202,18 +1202,10 @@ #include "Windows/Path.inc" #endif -bool IsLLVMDriver = false; - namespace llvm { namespace sys { namespace fs { -std::string getMainExecutable(const char *Argv0, void *MainAddr) { - if (IsLLVMDriver) - return sys::path::stem(Argv0).str(); - return getMainExecutableImpl(Argv0, MainAddr); -} - TempFile::TempFile(StringRef Name, int FD) : TmpName(std::string(Name)), FD(FD) {} TempFile::TempFile(TempFile &&Other) { *this = std::move(Other); } Index: llvm/lib/Support/Unix/Path.inc =================================================================== --- llvm/lib/Support/Unix/Path.inc +++ llvm/lib/Support/Unix/Path.inc @@ -194,7 +194,7 @@ /// GetMainExecutable - Return the path to the main executable, given the /// value of argv[0] from program startup. -std::string getMainExecutableImpl(const char *argv0, void *MainAddr) { +std::string getMainExecutable(const char *argv0, void *MainAddr) { #if defined(__APPLE__) // On OS X the executable path is saved to the stack by dyld. Reading it // from there is much faster than calling dladdr, especially for large Index: llvm/lib/Support/Windows/Path.inc =================================================================== --- llvm/lib/Support/Windows/Path.inc +++ llvm/lib/Support/Windows/Path.inc @@ -130,7 +130,7 @@ const file_t kInvalidFile = INVALID_HANDLE_VALUE; -std::string getMainExecutableImpl(const char *argv0, void *MainExecAddr) { +std::string getMainExecutable(const char *argv0, void *MainExecAddr) { SmallVector PathName; PathName.resize_for_overwrite(PathName.capacity()); DWORD Size = ::GetModuleFileNameW(NULL, PathName.data(), PathName.size()); Index: llvm/tools/llvm-driver/llvm-driver.cpp =================================================================== --- llvm/tools/llvm-driver/llvm-driver.cpp +++ llvm/tools/llvm-driver/llvm-driver.cpp @@ -11,9 +11,16 @@ #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/LLVMDriver.h" #include "llvm/Support/Path.h" #include "llvm/Support/WithColor.h" +namespace llvm { + +const bool IsLLVMDriver = true; + +} + using namespace llvm; #define LLVM_DRIVER_TOOL(tool, entry) int entry##_main(int argc, char **argv); @@ -66,9 +73,4 @@ return 1; } -extern bool IsLLVMDriver; - -int main(int Argc, char **Argv) { - IsLLVMDriver = true; - return findTool(Argc, Argv); -} +int main(int Argc, char **Argv) { return findTool(Argc, Argv); }