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 @@ -16,6 +16,7 @@ LLVM_ENABLE_PER_TARGET_RUNTIME_DIR LLVM_ENABLE_THREADS LLVM_WITH_Z3 + LLVM_TOOL_LLVM_DRIVER_BUILD ) configure_lit_site_cfg( @@ -73,7 +74,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 @@ -40,6 +40,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)) Index: llvm/include/llvm/Support/LLVMDriver.h =================================================================== --- /dev/null +++ llvm/include/llvm/Support/LLVMDriver.h @@ -0,0 +1,28 @@ +//===- 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 file defines just a single function, llvm::IsLLVMDriver(), +// This can be useful for tools which need to behave slightly differently under +// that environment. +// +//===----------------------------------------------------------------------===// + +namespace llvm { + +namespace impl { + +extern bool IsLLVMDriver; + +} + +static inline bool IsLLVMDriver() { + return impl::IsLLVMDriver; +} + +} Index: llvm/lib/Support/CMakeLists.txt =================================================================== --- llvm/lib/Support/CMakeLists.txt +++ llvm/lib/Support/CMakeLists.txt @@ -186,6 +186,7 @@ KnownBits.cpp LEB128.cpp LineIterator.cpp + LLVMDriver.cpp Locale.cpp LockFileManager.cpp LowLevelType.cpp Index: llvm/lib/Support/LLVMDriver.cpp =================================================================== --- /dev/null +++ llvm/lib/Support/LLVMDriver.cpp @@ -0,0 +1,13 @@ +//===- LLVMDriver.cpp ------------------------------------------*- 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 +// +//===---------------------------------------------------------------------===// + +namespace llvm::impl { + +bool IsLLVMDriver = false; + +} 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,6 +11,7 @@ #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" @@ -66,9 +67,7 @@ return 1; } -extern bool IsLLVMDriver; - int main(int Argc, char **Argv) { - IsLLVMDriver = true; + llvm::impl::IsLLVMDriver = true; return findTool(Argc, Argv); } Index: llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn +++ llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn @@ -98,6 +98,7 @@ "KnownBits.cpp", "LEB128.cpp", "LineIterator.cpp", + "LLVMDriver.cpp", "Locale.cpp", "LockFileManager.cpp", "LowLevelType.cpp",