mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-17 09:48:10 +00:00
Sadly, the Clang driver unconditionally injects the `-disable-free` flag to CC1 invocations. =/ This ends up with us leaking memory when invoking Clang programmatically, for example in unit tests. I've fixed this by post-processing the flags. The alternatives I see all involve duplicating even more code from within Clang's internals into our runner, and we already have a lot of that. I have left a TODO to try and follow up with upstream about fixing this in a more sustainable way, but wanted to get the testing in place anyways. I've also threaded a flag through the various layers so that when we're on the command line we can actually skip this and get the same compile time benefits that Clang itself gets from disabling freeing all of the internal data structures. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include "common/bazel_working_dir.h"
|
|
#include "common/error.h"
|
|
#include "common/exe_path.h"
|
|
#include "common/init_llvm.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/Support/LLVMDriver.h"
|
|
#include "toolchain/driver/driver.h"
|
|
#include "toolchain/install/busybox_info.h"
|
|
#include "toolchain/install/install_paths.h"
|
|
|
|
namespace Carbon {
|
|
|
|
// The actual `main` implementation. Can return an exit code or an `Error`
|
|
// (which causes EXIT_FAILRUE).
|
|
static auto Main(int argc, char** argv) -> ErrorOr<int> {
|
|
InitLLVM init_llvm(argc, argv);
|
|
|
|
// Start by resolving any symlinks.
|
|
CARBON_ASSIGN_OR_RETURN(auto busybox_info, GetBusyboxInfo(argv[0]));
|
|
|
|
auto fs = llvm::vfs::getRealFileSystem();
|
|
|
|
// Resolve paths before calling SetWorkingDirForBazel.
|
|
std::string exe_path = FindExecutablePath(busybox_info.bin_path.string());
|
|
const auto install_paths = InstallPaths::MakeExeRelative(exe_path);
|
|
if (install_paths.error()) {
|
|
return Error(*install_paths.error());
|
|
}
|
|
|
|
SetWorkingDirForBazel();
|
|
|
|
llvm::SmallVector<llvm::StringRef> args;
|
|
args.reserve(argc + 1);
|
|
if (busybox_info.mode) {
|
|
args.append({*busybox_info.mode, "--"});
|
|
}
|
|
args.append(argv + 1, argv + argc);
|
|
|
|
Driver driver(fs, &install_paths, stdin, &llvm::outs(), &llvm::errs(),
|
|
/*fuzzing=*/false, /*enable_leaking=*/true);
|
|
bool success = driver.RunCommand(args).success;
|
|
return success ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
}
|
|
|
|
} // namespace Carbon
|
|
|
|
auto main(int argc, char** argv) -> int {
|
|
auto result = Carbon::Main(argc, argv);
|
|
if (result.ok()) {
|
|
return *result;
|
|
} else {
|
|
llvm::errs() << "error: " << result.error() << "\n";
|
|
return EXIT_FAILURE;
|
|
}
|
|
}
|